Volt v0.1 · TypeScript APIs on Bun · Get started
Docs/Architecture & DI/Modular Architecture

Modular Architecture

Compose feature modules using the actual ModuleConfig API.

Complete module example

index.ts
import { Volt, type ModuleConfig } from 'voltts';

const productsModule: ModuleConfig = {
  name: 'products',
  setup(app) {
    app.group('/products', (products) => {
      products.get('/', () => ({ products: [{ id: 1, title: 'Coffee' }] }));
      products.get('/:id', (c) => ({ id: c.params.id }));
    });
  },
};
const app = new Volt();
app.registerModule({ name: 'app', imports: [productsModule] });
if (globalThis._importMeta_.main) app.listen(3000);
export default app;

How registration works

registerModule() recursively registers imports, then calls setup(app). ModuleConfig is an object interface, not a VoltModule class. The current implementation does not process providers or exports automatically. Use a Container explicitly for services as described in Dependency Injection.

Suggested project structure

FileResponsibility
src/index.tsStart the server
src/app.tsCompose modules and middleware
src/products/module.tsRegister product routes
src/products/service.tsBusiness logic and persistence
test/products.test.tsTest app.handle through createTestClient

Separate server startup from application creation so tests can instantiate the app without binding a port.