npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lafken/main

v0.9.0

Published

Lafken core engine - orchestrate AWS serverless infrastructure using decorators with automatic CDKTN code generation

Downloads

347

Readme

@lafken/main

Core entry point for a Lafken serverless application. @lafken/main initializes the AWS provider, orchestrates resolvers and modules, and synthesizes the resulting Terraform configuration through CDKTN. It provides createApp to bootstrap the application and createModule to organize resources into logical groups.

Installation

npm install @lafken/main

Getting Started

Create an application with resolvers and modules, then let Lafken generate all the infrastructure:

import { createApp, createModule } from '@lafken/main';
import { ApiResolver } from '@lafken/api/resolver';
import { QueueResolver } from '@lafken/queue/resolver';

// 1. Define modules that group related resources
const userModule = createModule({
  name: 'users',
  resources: [UserApi, UserQueue],
});

const billingModule = createModule({
  name: 'billing',
  resources: [InvoiceSchedule],
});

// 2. Create the application
await createApp({
  name: 'my-app',
  modules: [userModule, billingModule],
  resolvers: [
    new ApiResolver({ restApi: { name: 'my-api' } }),
    new QueueResolver(),
  ],
});

Features

createApp

createApp is the main entry point. It initializes the AWS stack, runs all resolver lifecycle hooks (beforeCreatecreateafterCreate), and synthesizes the Terraform output:

await createApp({
  name: 'my-app',
  modules: [userModule, billingModule],
  resolvers: [new ApiResolver(), new QueueResolver()],
  globalConfig: {
    lambda: {
      memory: 512,
      timeout: 30,
      runtime: 22,
      services: ['dynamodb', 's3', 'sqs'],
    },
    tags: {
      environment: 'production',
      team: 'platform',
    },
  },
  awsProviderConfig: {
    region: 'us-east-1',
    profile: 'my-aws-profile',
  },
  s3Backend: {
    bucket: 'my-terraform-state',
    key: 'app/terraform.tfstate',
    region: 'us-east-1',
  },
  extend: async (scope) => {
    // Add custom CDKTN constructs after all resolvers finish
  },
});

Application Options

| Option | Type | Required | Description | | ------------------- | ------------------- | -------- | --------------------------------------------------------- | | name | string | Yes | Application name, used as the stack identifier | | modules | StackModule[] | Yes | Modules created with createModule | | resolvers | ResolverType[] | Yes | Resolvers that process decorated resources | | globalConfig | GlobalConfig | No | Shared Lambda and tag settings for all resources | | awsProviderConfig | AwsProviderConfig | No | AWS provider settings (region, profile, etc.) | | s3Backend | S3BackendConfig | No | Remote S3 backend for Terraform state | | extend | (scope) => void | No | Callback invoked after all resolvers finish |

createModule

createModule groups related resources into a logical unit with its own scope, IAM role, and configuration. Each resource inside the module is processed by the matching resolver based on its decorator type:

const orderModule = createModule({
  name: 'orders',
  resources: [OrderApi, OrderQueue, OrderSchedule],
  globalConfig: {
    lambda: {
      memory: 256,
      timeout: 15,
      services: ['dynamodb', 'sqs'],
    },
    tags: {
      domain: 'orders',
    },
  },
});

Module Options

| Option | Type | Required | Description | | -------------- | ----------------- | -------- | ----------------------------------------------------- | | name | string | Yes | Module name, used as scope and tag identifier | | resources | ClassResource[] | Yes | Decorated classes to be processed by resolvers | | globalConfig | GlobalConfig | No | Lambda and tag settings scoped to this module |

Global Configuration

Global configuration applies default settings to all Lambda functions and resources. Values cascade from application to module to individual resource, with more specific settings taking precedence:

App globalConfig → Module globalConfig → Resource-level config

Lambda Configuration

| Option | Type | Description | | ------------- | ---------------- | --------------------------------------------------------- | | memory | number | Memory allocation in MB | | timeout | number | Execution timeout in seconds | | runtime | 20 \| 22 \| 24 | Node.js runtime version | | services | Services[] | AWS services the Lambda can access (creates IAM role) | | enableTrace | boolean | Enable AWS X-Ray tracing | | env | EnvironmentValue | Environment variables for Lambda functions |

Available Services

Services define which AWS resources the Lambda IAM role can access:

| Service | Description | | --------------- | -------------------------------- | | dynamodb | Amazon DynamoDB | | s3 | Amazon S3 | | lambda | AWS Lambda | | cloudwatch | Amazon CloudWatch Logs | | sqs | Amazon SQS | | state_machine | AWS Step Functions | | kms | AWS KMS | | ssm | AWS Systems Manager Parameter Store | | event | Amazon EventBridge |

For fine-grained control, specify individual permissions:

services: [
  'cloudwatch',
  { type: 'dynamodb', permissions: ['Query', 'GetItem'] },
  { type: 's3', permissions: ['GetObject'], resources: ['arn:aws:s3:::my-bucket/*'] },
  { type: 'custom', serviceName: 'ses', permissions: ['SendEmail'] },
]

Tags

Tags are applied automatically to all taggable resources. Module-level tags merge with app-level tags, and resource-specific tags take highest precedence:

// App-level tags
globalConfig: {
  tags: {
    environment: 'production',
    project: 'my-app',
  },
}

// Module-level tags (merged with app tags)
globalConfig: {
  tags: {
    domain: 'orders',
  },
}

Lafken also adds automatic tags: lafken:app with the app name and lafken:module with the module name.

S3 Backend

Store Terraform state remotely in an S3 bucket for team collaboration and state locking:

await createApp({
  name: 'my-app',
  s3Backend: {
    bucket: 'terraform-state-bucket',
    key: 'apps/my-app/terraform.tfstate',
    region: 'us-east-1',
    dynamodbTable: 'terraform-locks',
  },
});

Extending the Application

The extend callback runs after all resolvers have finished processing. Use it to add custom infrastructure that is not covered by the standard resolvers:

await createApp({
  name: 'my-app',
  modules: [userModule],
  resolvers: [new ApiResolver()],
  extend: async (scope) => {
    // Add any CDKTN construct directly to the stack
  },
});