@teliagen/server
v0.4.2
Published
HTTP server and application runtime for Teliagen
Readme
@teliagen/server
The core HTTP runtime and application orchestrator for Teliagen.
@teliagen/server provides the backbone for building scalable, type-safe, and federated Node.js applications. It replaces traditional controllers with a robust Action-based architecture and manages the entire application lifecycle.
Features
- TeliagenApp: A unified application class handling configuration, plugins, and server lifecycle.
- Action System: Route requests directly to typed Action Providers (no manual router configuration needed).
- Federation Ready: Built-in
TeliagenHostfor orchestrating microservices and gateway patterns. - Plugin Architecture: Deep integration points for authentication, database adapters, and custom logic.
- Performance: Lightweight HTTP transport layer optimized for high throughput.
Installation
npm install @teliagen/server @teliagen/commonsNote: This package requires
reflect-metadatato function correctly with decorators.
Quick Start
Create a simple API with a single action:
import 'reflect-metadata';
import { TeliagenApp } from '@teliagen/server';
### 1. Define Input Schema (`src/modules/hello/schemas/hello.schema.ts`)
It is recommended to define schemas in separate files using the `@Schema` decorator for better organization and automatic client generation.
```typescript
import { Schema } from '@teliagen/commons/schemas';
import { String } from '@teliagen/commons/validation';
@Schema()
export class HelloInput {
@String()
name!: string;
}2. Define Action Provider (src/modules/hello/actions/hello.actions.ts)
import { Action, ActionProvider, Input } from '@teliagen/commons/actions/decorators';
import { HelloInput } from '../schemas/hello.schema.js';
@ActionProvider({
module: 'hello',
name: 'HelloActions'
})
export class HelloActions {
@Action('world')
async world(@Input(HelloInput) input: HelloInput) {
return { message: `Hello ${input.name} from Teliagen!` };
}
}3. Start Server (src/server.ts)
import 'reflect-metadata';
import { TeliagenApp } from '@teliagen/server/app';
import { HelloActions } from './modules/hello/actions/hello.actions.js';
const app = new TeliagenApp({
server: { port: 3000 }
});
// Register module containing actions (optional)
app.registerModule({
actions: [HelloActions]
});
await app.start();
console.log('Server running on http://localhost:3000');Core Concepts
TeliagenApp
The TeliagenApp class is your entry point. It can be configured via code or primarily through teliagen.config.ts.
const app = new TeliagenApp();
await app.initialize(); // Auto-loads teliagen.config.ts
await app.start();Routing & Actions
Unlike Express or Fastify, you don't define routes manually. Teliagen routes are derived from the Action Provider metadata.
- Module: The namespace of the provider (e.g.,
auth,users). - Provider: The class name (e.g.,
UserActions). - Action: The method name (e.g.,
create).
This structure allows the Client Generator (@teliagen/vite-plugin) to create fully typed SDKs for your frontend automatically.
Federation (TeliagenHost)
For microservices, use TeliagenHost to act as a gateway that stitches multiple remote or local Services into a single Unified Graph.
import { TeliagenHost } from '@teliagen/server';
const host = TeliagenHost.getInstance();
await host.setup(); // Loads services from config
await host.start(8080);Documentation
For comprehensive guides, API references, and advanced usage (Middlewares, Guards, Interceptors), please visit:
License
Apache-2.0
