TsdkArc LogoTsdkArc

Type-safe module composable.

Compose modules like building blocks, nest them, and share them across projects. Clean, simple, type safe and scalable.

Read Documentation

Quick Start

import { defineModule, type ContextOf } from "tsdkarc";

// 1. Define Config (Returns namespace: ctx.config)
const configModule = defineModule({ name: "config" }).init(() => ({
  port: 3000,
}));

// 2. Define Server (Depends on Config)
const serverModule = defineModule({
  name: "server",
  modules: [configModule],
}).init((ctx) => ({
  listen: () => console.log(`šŸš€ Server running on port ${ctx.config.port}`),
}));

// Export inferred types for use elsewhere in your app
export type AppCtx = ContextOf<typeof serverModule>;

// 3. Compose and Launch
async function bootstrap() {
  try {
    // Wrap top-level modules in an anonymous root module
    const appModule = defineModule({ modules: [serverModule] }).init(
      () => ({})
    );

    // Display the generated dependency graph
    console.log("\nDependency Tree:\n" + appModule.graph().formatted);
    const app = await appModule.start({
      afterBoot: () => console.log("āœ… All modules booted successfully!"),
    });
    // Run the app! (Fully type-safe)
    app.ctx.server.listen();
  } catch (error) {
    // tsdkarc automatically rolls back already-booted modules if a failure occurs here
    console.error("āŒ Failed to boot application:", error);
    process.exit(1);
  }
}

bootstrap();

Why TsdkArc?

Fully Type-Safe Context

The merged union of all slices is fully typed at each module's boundary. Autocomplete works exactly as you'd expect, everywhere.

Auto Resolution

Declare your dependencies. start() resolves the graph.

Composable

Build small modules. Complex wiring becomes just a simple chain.

Robust Lifecycle

Granular control over setup and teardown. From beforeBoot to afterShutdown.

Other Awesome Projects