Introduction
What Suku is and how its pieces fit together.
Suku is a lightweight TypeScript backend framework built from four ideas: routes, features, middlewares and services. Routes are typed by their schemas, and services come from a dependency injection container modelled on .NET's.
import { Routes, Suku, feature, route, singleton } from '@sukujs/core';
import { nodeAdapter } from '@sukujs/platform-node';
import { z } from 'zod';
class UsersService {
find(id: number) {
return { id, name: 'Ada' };
}
}
@Routes('/users')
class UsersRoutes {
constructor(private readonly users: UsersService) {}
findOne = route.get('/:id', {
params: z.object({ id: z.coerce.number() }),
handle: ({ params }) => this.users.find(params.id), // params.id is a number
});
}
const UsersFeature = feature('users', {
routes: [UsersRoutes],
services: [singleton(UsersService)],
});
const app = await Suku.create({ features: [UsersFeature], adapter: nodeAdapter() });
await app.listen(3000);The four ideas
Routes
A route is a typed object. Its schemas validate the request and type the handler, so nothing is written twice. Group routes in a class, or use them on their own.
Features
A feature bundles the routes, services and middlewares of one part of your app.
Middlewares
One concept for everything that wraps a request: logging, authentication, caching, CORS.
Services
Declared with a class or without one. Singleton, scoped and transient lifetimes, a scope per request, and startup validation.
Packages
| Package | Purpose |
|---|---|
@sukujs/core | Routes, features, middlewares, validation, config, logger. |
@sukujs/di | The container. Usable on its own, without HTTP. |
@sukujs/crypto | JWT, passwords, signed and encrypted values. Works on its own. |
@sukujs/security | CORS, security headers, CSRF protection, rate limiting. |
@sukujs/graphql | Class-based GraphQL resolvers. Optional. |
@sukujs/platform-node | Adapter for node:http. |
@sukujs/platform-bun | Adapter for Bun.serve. |
None of them has a runtime dependency. @sukujs/core re-exports the container's decorators and
registration helpers, so application code usually imports from one place.
Status
Suku 0.1.0
All packages are on npm under @sukujs. Install with
bun add @sukujs/core (and the platform adapter you need). The API is still early: lifecycle
hooks, OpenAPI output and a typed client are planned and not documented here.