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

composable-backend

v2.0.0

Published

Composable foundation SDK

Readme

Composable Backend

A composable backend framework for building event-driven microservices and serverless applications in Node.js.

This project is a derivative work based on Mercury Composable for Node.js, originally developed by Accenture. See NOTICE for full attribution.

The source code is provided under the Apache 2.0 license.

5-Minute Quickstart

Install

npm install composable-backend

Optional Kafka Add-On

npm install @composable-backend/kafka kafkajs

Minimal Project

your-app/
  src/
    hello-world.task.ts       ← auto-discovered by convention
    config/
      preload.ts
      application.yml

Minimal Config

Create src/config/application.yml:

application.name: 'quickstart-demo'
log.level: 'info'
rest.automation: false

Minimal Function

Create src/hello-world.task.ts:

import { defineComposable, EventEnvelope } from 'composable-backend';

export default defineComposable({
  process: 'hello.world',
  handler: async (evt: EventEnvelope) => {
    const body = (evt.getBody() ?? {}) as { name?: string };
    return {
      message: `Hello ${body.name ?? 'world'}`,
    };
  },
});

Minimal App Bootstrap

Create src/config/preload.ts:

import { fileURLToPath } from 'url';
import { AppConfig, Platform } from 'composable-backend';

function getRootFolder(): string {
  const folder = fileURLToPath(new URL('.', import.meta.url));
  return folder.includes('\\') ? folder.replaceAll('\\', '/') : folder;
}

export class ComposableLoader {
  static async initialize(): Promise<void> {
    const configDir = getRootFolder();
    AppConfig.getInstance(configDir + 'resources');

    const platform = Platform.getInstance();
    await platform.autoScan(configDir + '..');

    platform.runForever();
    await platform.getReady();
  }
}

Create src/main.ts:

import { ComposableLoader } from './config/preload.js';

ComposableLoader.initialize().catch(error => {
  console.error(error);
  process.exit(1);
});

Dev Mode

Add to package.json:

{
  "scripts": {
    "dev": "tsx watch src/main.ts",
    "build": "tsc",
    "start": "node dist/main.js"
  }
}

npm run dev runs directly from source with instant restart on file changes. No build step needed during development.

Example Request

Send an in-memory RPC request to your composable with PostOffice:

import { EventEnvelope, PostOffice, Sender } from 'composable-backend';

const po = new PostOffice(new Sender('demo.client', '1000', 'TEST /hello'));

const response = await po.request(
  new EventEnvelope()
    .setTo('hello.world')
    .setBody({ name: 'Ada' }),
  3000
);

console.log(response.getBody());
// { message: 'Hello Ada' }

Testing Example

Create tests/hello-world.test.ts:

import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { beforeAll, describe, expect, it } from 'vitest';
import { AppConfig, EventEnvelope, Platform, PostOffice, Sender } from 'composable-backend';
import helloWorld from '../src/hello-world.task.js';

function getResourcePath() {
  const here = dirname(fileURLToPath(import.meta.url));
  return join(here, '../src/config');
}

describe('hello.world', () => {
  let platform: Platform;

  beforeAll(async () => {
    AppConfig.getInstance(getResourcePath());
    platform = Platform.getInstance();
    await platform.getReady();
    platform.registerComposable(helloWorld);
  });

  it('returns a greeting', async () => {
    const po = new PostOffice(new Sender('unit.test', '1001', 'TEST /hello'));
    const response = await po.request(
      new EventEnvelope()
        .setTo('hello.world')
        .setBody({ name: 'Ada' }),
      3000
    );
    expect(response.getBody()).toStrictEqual({ message: 'Hello Ada' });
  });
});

Run it with:

npx vitest run

File Conventions

The framework uses file naming conventions to auto-discover tasks and flows:

| Convention | What it does | |---|---| | *.task.ts | Auto-registered as a composable function (must default-export a defineComposable()) | | *.flow.yml | Auto-loaded as a flow definition |

Place them anywhere inside src/. The scanner searches recursively — organize by feature, domain, or however you prefer:

src/
  leads/
    lead-score.task.ts
    lead-validate.task.ts
    process-lead.flow.yml
  orders/
    order-process.task.ts
    process-order.flow.yml
  config/
    preload.ts
    application.yml
    rest.yaml

Or flat:

src/
  lead-score.task.ts
  process-lead.flow.yml
  config/...

Both work. The scanner finds every *.task.ts and *.flow.yml under src/ regardless of folder structure.

Auto-scan from libraries

Libraries listed in web.component.scan are also scanned for *.task.js and *.flow.yml files:

# application.yml
web.component.scan: 'my-composable-library'

Manual registration

You can still register composables manually alongside auto-scan. This is needed for external packages that don't follow the naming convention:

import { KafkaAdapter, KafkaNotification } from '@composable-backend/kafka';

await platform.autoScan(srcDir);
platform.registerComposable(KafkaAdapter);
platform.registerComposable(KafkaNotification);

Two Authoring Styles

Function Style (recommended)

import { defineComposable, EventEnvelope } from 'composable-backend';

export default defineComposable({
  process: 'v1.lead.log-scored',
  instances: 10,
  handler: async (evt: EventEnvelope) => {
    return evt.getBody() ?? {};
  },
});

Class Style

import { Composable, EventEnvelope, preload } from 'composable-backend';

export class LeadLogScored implements Composable {
  @preload('v1.lead.log-scored', 10)
  initialize(): Composable {
    return this;
  }

  async handleEvent(evt: EventEnvelope) {
    return evt.getBody() ?? {};
  }
}

Class-style composables are registered manually:

platform.register('v1.lead.log-scored', new LeadLogScored(), 10);

Why Composable Backend

Composable Backend is built around a simple idea: each task should be a self-contained unit with immutable input and output, and larger use cases should be assembled by event choreography rather than tight coupling.

That gives you:

  • Small, isolated business functions
  • Clear boundaries between tasks
  • Easy unit and integration testing
  • Strong fit for event-driven systems and flow-based automation
  • A code shape that is easy for both humans and AI tools to reason about

Next Steps