AsterFlow is a modular, strongly typed framework for building HTTP APIs in TypeScript.
AsterFlow is a clean rewrite of base-fastify, a project I originally created to improve my own workflow. It evolved substantially as I developed it. The name combines my nickname "Ashu" + "Router" + "Flow" (inspired by TensorFlow). I built it out of frustration with the unnecessary complexity of other frameworks—often you end up writing dozens of type definition files instead of focusing on the routes themselves, with needless modularization that only adds cognitive overhead. AsterFlow simplifies that process, and I hope it makes your life easier too!
I also toyed with a pseudo-framework called Kython, which I developed alongside Drylian as an experiment to see who could go further without using AI.
- Dynamic, Contextual Typing: Every route added to the router automatically enriches its type context—no external file generation required.
- Parameter Validation: Natively support Zod or @caeljs/config for per-route schema validation.
- Multi-Server Compatibility: Abstractions for Node.js, Bun, Express, and Fastify.
- tRPC-Inspired API: Consume routes in a fully type-safe manner without auxiliary files.
- Standardized Response Handling: Type-safe response system with status helpers and unified format handling.
- Package-Based Architecture: Core, Driver, and Router modules are decoupled for maximum scalability.
| Package | Description |
|---|---|
asterflow |
The heart of the framework, providing server initialization and configuration with strong typing |
@asterflow/adapter |
HTTP adapters for different runtimes (Node.js, Bun, Express, Fastify) |
@asterflow/request |
Unified HTTP request adapter system |
@asterflow/response |
Type-safe HTTP response system with status helpers and runtime compatibility |
@asterflow/router |
Type-safe routing system with middleware and validation support |
# You can use any package manager - npm, pnpm, bun, etc.
npm install asterflow- HTTP Adapters: Native support for Node.js, Bun, Express and Fastify through the adapter system
- High-Performance Routing: Optimized routing system using prefix tree
- Parameter Validation: Native support for Zod and @caeljs/config
- Advanced URL Analysis: URL parser with AST support and automatic typing
- Middleware System: Full middleware support with typed context
- Standardized Responses: Type-safe response system with status helpers and runtime compatibility
- Modular Architecture: Decoupled packages for maximum scalability
- Dynamic Typing: Automatic type inference without external files
- tRPC-Inspired API: Fully type-safe route consumption
import { AsterFlow } from 'asterflow'
import { adapters } from '@asterflow/adapter'
import fastify from 'fastify'
const server = fastify()
const aster = new AsterFlow({
driver: adapters.fastify
})
aster.listen(server, { port: 3000 })Simple Method
import { Method } from '@asterflow/router'
export default new Method({
path: '/users/:id=number', // Support for typed parameters
method: 'get',
handler: ({ response, url }) => {
const { id } = url.getParams() // id is automatically typed as number
return response.success({ id })
}
})Router with Middleware
import { Router, Middleware } from '@asterflow/router'
const authMiddleware = new Middleware({
name: 'auth',
onRun({ next }) {
return next({
user: { id: 1, name: 'John' }
})
}
})
export default new Router({
path: '/protected',
use: [authMiddleware],
methods: {
get({ response, middleware }) {
return response.success({ user: middleware.user })
}
}
})Validation with Zod
import { Method } from '@asterflow/router'
import { z } from 'zod'
export default new Method({
path: '/users',
method: 'post',
schema: z.object({
name: z.string(),
email: z.string().email(),
age: z.number().min(18)
}),
handler: ({ response, schema }) => {
return response.created({ user: schema }) // Automatically typed
}
})Validation with CaelJS
import { Method } from '@asterflow/router'
import { c } from '@caeljs/config'
export default new Method({
path: '/users',
method: 'post',
schema: c.object({
name: c.string(),
email: c.string(),
age: c.number().min(18)
}),
handler: ({ response, schema }) => {
return response.created({ user: schema })
}
})Express Example
import { AsterFlow } from 'asterflow'
import { adapters } from '@asterflow/adapter'
import express from 'express'
const app = express()
const aster = new AsterFlow({
driver: adapters.express
})
// Express middleware
app.use(express.json())
// AsterFlow routes
aster.router({
basePath: '/api',
controllers: [/* your routes */]
})
aster.listen(app, 3000)Node.js HTTP Example
import { AsterFlow } from 'asterflow'
import { adapters } from '@asterflow/adapter'
import { createServer } from 'http'
const server = createServer()
const aster = new AsterFlow({
driver: adapters.node
})
// AsterFlow routes
aster.router({
basePath: '/api',
controllers: [/* your routes */]
})
aster.listen(server, { port: 3000 })Bun Example
import { AsterFlow } from 'asterflow'
import { adapters } from '@asterflow/adapter'
const aster = new AsterFlow({
driver: adapters.bun
})
// AsterFlow routes
aster.router({
basePath: '/api',
controllers: [/* your routes */]
})
aster.listen(null, { port: 3000 })If you're exploring alternatives, you might also like:
- ElysiaJS - Minimal web framework for Bun
- tRPC - Type-safe RPC framework
- Fastify - Fast and low overhead web framework
- Express - Minimal web framework for Node.js
MIT - See LICENSE for more details.