Skip to content

Why Silgi?

Challenges Encountered

Developing modern, type-safe backends and microservices often requires repetitive code, manual type definitions, and complex tool setups. Common problems include:

  • Ensuring consistent type safety across services
  • Service discovery and naming management
  • Proper error handling and data validation
  • Deployment environment configurations
  • Creating reusable helpers
  • Nested schemas and complex data structures
  • Difficulties during framework migrations

These issues reduce productivity and lead to runtime errors.

The Silgi Solution

Silgi offers a comprehensive, TypeScript-based framework for service-oriented architectures:

End-to-End Type Safety

  • Define your schemas once, get automatic type generation.
  • Catch type errors during development.
  • Autocompletion for all services, inputs, and outputs.

Clean and Modular Service Definition

typescript
import { 
createSchema
,
createService
} 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
: {
get
: {
bookById
: {
input
:
GetBookInput
,
output
:
BookSchema
,
}, },
post
: {
createBook
: {
input
:
BookSchema
.
omit
({
id
: true }),
output
:
BookSchema
,
} } }, }) export const
bookService
=
createService
(
bookSchema
, {
book
: {
get
: {
async
bookById
({
input
,
shared
}) {
const
book
= await
shared
.storage('db').getItem(`book:${
input
.bookId}`)
if (!
book
) {
throw ErrorFactory.notFound('Book not found') } return
book
}, },
post
: {
async
createBook
({
input
,
shared
}) {
const
newBook
= {
id
: `book-${
Date
.
now
()}`, ...
input
}
await
shared
.storage('db').setItem(`book:${
newBook
.id}`,
newBook
)
return
newBook
} } }, })

Middleware Support

Define global or route-specific middleware:

Route-Specific Middleware

typescript
import { 
createMiddleware
} from 'silgi'
export const
pathMiddleware
=
createMiddleware
({
path
: '/api/library/books/**',
method
: ['GET', 'POST'],
setup
: {
rules
: {
rateLimit
: {
interval
: '1m',
tokensPerInterval
: 10,
}, },
handler
: async (
event
,
silgi
) => {
console
.
log
('Middleware executed')
}, }, })

Global Middleware

typescript
import { 
createMiddleware
} from 'silgi'
export const
globalMiddleware
=
createMiddleware
({
global
: 'globalkey1',
// You can add method: ['GET', 'POST']
setup
: {
rules
: {
rateLimit
: {
interval
: '1m',
tokensPerInterval
: 10,
}, },
handler
: async (
event
,
silgi
) => {
console
.
log
('Global middleware executed')
}, }, })

Shared Helpers

Define reusable logic once, use it in all services:

typescript
import { createShared } from 'silgi'
import { useDatabase } from '../utils/db'

export const shared = createShared({
  db: useDatabase,
})

Module System

  • Add custom functionality with a consistent interface.
  • Configure with type-safe options.
  • Share across projects.
typescript
import { defineSilgiModule } from 'silgi/kit'

export default defineSilgiModule({
  meta: { name: 'auth-module', configKey: 'auth' },
  defaults: { tokenExpiry: '1h' },
  async setup(options, silgi) {
    // Module setup logic
  },
})

Framework Agnostic with Presets

  • Compatible with Nitro, H3, Nuxt, Express, Fastify, Next.js, and more.
  • Package as an independent NPM package.

Simplified Development

  • Automatic type and code generation
  • Rapid development with built-in CLI
  • Hot module replacement
  • Structured error management with ErrorFactory

Comparison with Alternatives

  • Express/Fastify/Koa: Silgi offers superior TypeScript integration and automatic type generation.
  • tRPC: Silgi provides a more comprehensive ecosystem with modules, helpers, and presets.
  • NestJS: Silgi offers a lighter and more functional architecture.
  • GraphQL Frameworks: Silgi automatically supports REST and GraphQL, using standard HTTP and JSON.

Quick Start

Create type-safe services in minutes:

bash
pnpm create silgi@latest my-service
cd my-service
pnpm install
pnpm silgi prepare
pnpm dev

For more information and examples, check out the Getting Started Guide and examples pages.

Released under the MIT License. (dev). Documentation design is a copy of vite.dev docs.