Skip to main content

Core Package

Monolithic development experience for serverless applications

The @serverless-monolith/core package is the foundation of Serverless Monolith. It enables you to develop serverless applications with the same experience as a traditional monolith, offering easy debugging, local AWS service emulation, and complete TypeScript support.

Installation

pnpm add @serverless-monolith/core

Features

Automatic Discovery

  • ✅ Automatic module discovery via functions.yml
  • ✅ Support for multiple organization strategies
  • ✅ Security validation and path traversal prevention
  • ✅ Robust fallback for restrictive cases

HTTP Server

  • ✅ Express server with universal dynamic import
  • ✅ Full compatibility with ES Modules and CommonJS
  • ✅ Log capture per execution with executionId
  • ✅ Configurable CORS
  • ✅ API routes for execution logs

SQS Emulator

  • ✅ Event Emitter for message processing
  • ✅ REST API for sending messages
  • ✅ Specific log capture per execution
  • ✅ Configurable retry system
  • ✅ Execution logs via API

Configuration System

  • ✅ Flexible configuration via file or object
  • ✅ Configuration validation
  • ✅ Overrides via environment variables
  • ✅ Minimal configuration for quick use

Logging System

  • ✅ Logs per execution (HTTP and SQS)
  • ✅ Capture of debug package logs
  • ✅ Automatic log formatting
  • ✅ API for log queries
  • ✅ Support for external adapters (MongoDB, PostgreSQL, etc.)

Quick Start

Minimal Configuration

// monolith.config.js
module.exports = {
discovery: {
modulesDir: 'src/modules'
}
}

Programmatic Usage

import { MonolithServer } from '@serverless-monolith/core';
import path from 'path';

const server = MonolithServer.create(
path.resolve(__dirname, './monolith.config.ts'),
{
port: 4005,
cors: true
}
);

await server.start();

Configuration Object

import { MonolithServer } from '@serverless-monolith/core';

const server = MonolithServer.create({
discovery: {
modulesDir: 'src/modules',
functionsFile: 'functions.yml'
},
logging: {
enabledCategories: ['adapterStartupInfo'],
showRoutesTable: true
}
}, {
port: 4005,
cors: true
});

await server.start();

Project Structure

your-project/
├── monolith.config.js # Configuration (optional)
├── src/modules/ # Serverless modules
│ ├── user/
│ │ ├── functions.yml # Function definitions
│ │ └── handlers/ # Implementation
│ │ ├── create/
│ │ │ └── index.ts
│ │ └── list/
│ │ └── index.ts
│ └── order/
│ ├── functions.yml
│ └── handlers/
└── .env # Environment variables

Next Steps