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
| File | Responsibility |
|---|---|
| src/index.ts | Start the server |
| src/app.ts | Compose modules and middleware |
| src/products/module.ts | Register product routes |
| src/products/service.ts | Business logic and persistence |
| test/products.test.ts | Test app.handle through createTestClient |
Separate server startup from application creation so tests can instantiate the app without binding a port.