Why Silgi?
The Challenges
Building modern, type-safe backends and microservices often requires repetitive code, manual type definitions, and complex tool setups. Developers frequently face these issues:
- Ensuring consistent type safety across services
- Managing service discovery and naming in microservices
- Implementing proper error handling and data validation
- Configuring deployment environments
- Creating reusable components across services
- Working with nested schemas and complex data structures
These challenges reduce productivity, lead to inconsistent implementations, and cause runtime errors.
The Solution with Silgi
Silgi eliminates these problems with a comprehensive, TypeScript-first framework designed specifically for service-oriented architectures:
End-to-End Type Safety
- Define your schemas once and get automatic type generation.
- Catch type errors during development.
- IDE autocompletion for all services, inputs, and outputs.
- Inputs/outputs are automatically validated.
Modular and Sustainable Architecture
typescript
import { createSchema, createService, ErrorFactory } from 'silgi'
import { z } from 'zod'
const BookSchema = z.object({
id: z.string(),
title: z.string(),
author: z.string(),
})
const GetBookInput = z.object({
bookId: z.string(),
})
export const bookSchema = createSchema({
book: {
book: {
get: {
bookById: {
input: GetBookInput,
output: BookSchema,
},
},
post: {
createBook: {
input: BookSchema.omit({ id: true }),
output: BookSchema,
}
}
},
},
})
export const bookService = createService({
book: {
book: {
get: {
bookById: {
handler: async (input, shared) => {
const book = await shared.storage('db').getItem(`book:${input.bookId}`)
if (!book) {
throw ErrorFactory.notFound('Book not found')
}
return book
},
},
},
post: {
createBook: {
handler: async (input, shared) => {
const newBook = { id: `book-${Date.now()}`, ...input }
await shared.storage('db').setItem(`book:${newBook.id}`, newBook)
return newBook
}
}
}
},
},
})
Powerful Shared Helpers
Define reusable logic once and use it in all your services:
typescript
import { createShared } from 'silgi'
import type { ExtendShared } from 'silgi/types'
import { useDatabase } from '../utils/db'
export interface SharedDatabase extends ExtendShared {
database: ReturnType<typeof useDatabase>
}
export const db = createShared({
database: useDatabase,
})
Extensible Module System
- Add custom functionality with a consistent module interface.
- Configure modules with type-safe options.
- Share and reuse modules across projects.
typescript
import { defineSilgiModule, addNPMPackage } from 'silgi/kit';
export interface ModuleOptions {
authModule: {
jwtSecret: string;
tokenExpiry?: string;
}
}
export default defineSilgiModule<ModuleOptions['authModule']>({
meta: {
name: 'auth-module',
configKey: 'authModule',
},
defaults: {
tokenExpiry: '1h',
},
async setup(options, silgi) {
if (silgi.options.isPreparingModules) {
return
}
const { resolve } = createResolver(import.meta.url)
const runtimeDir = resolve('./runtime')
silgi.options.plugins ||= []
silgi.options.plugins.push({
path: resolve(runtimeDir, './plugin.ts'),
})
silgi.hook('reload:scan', async () => {
/// await graphqlLoadSync(silgi)
})
addNPMPackage([
{
name: 'graphql',
},
])
},
});
Framework Independence with Presets
- Compatible with Nitro, H3, Nuxt, Express, Fastify, Next.js, and more.
- Package as a standalone NPM package.
- Consistent API regardless of deployment target.
Streamlined Development Experience
- Automatic type and code generation
- Fast development with built-in CLI
- Hot module replacement
- Structured error management with
ErrorFactory
- Comprehensive test helpers
Silgi Compared to Alternatives
- Express/Fastify/Koa: Silgi offers superior TypeScript integration, automatic type generation, and a more structured service definition.
- tRPC: Both focus on type safety, but Silgi provides a more comprehensive ecosystem with modules, shared helpers, and deployment presets.
- NestJS: Silgi is lighter and more flexible, preferring functional composition over decorators.
- GraphQL Frameworks: Silgi offers similar type safety and schema benefits without GraphQL's complexity, using standard HTTP methods and JSON. Silgi also supports REST and GraphQL automatically.
Quick Start with Silgi
Build type-safe services in minutes:
bash
pnpm create silgi@latest my-service
cd my-service
pnpm install
pnpm silgi prepare
pnpm dev
Discover all features and examples in the Getting Started Guide and examples.