Koa2 + Typescript + IOC = koatty. Koatty is a progressive Node.js framework for building efficient and scalable server-side applications. Perfect for crafting enterprise-level APIs, microservices, and full-stack applications with TypeScript excellence.
- 🚄 High Performance: Built on top of Koa2 with optimized architecture
- 🧩 Full-Featured: Supports gRPC, HTTP, WebSocket, Schedule tasks, and more
- 🧠 TypeScript First: Native TypeScript support with elegant OOP design
- 🌀 Spring-like IOC Container: Powerful dependency injection system with autowiring
- ✂️ AOP Support: Aspect-oriented programming with decorator-based interceptors
- 🔌 Extensible Architecture: Plugin system with dependency injection
- 📦 Modern Tooling: CLI scaffolding, testing utilities, and production-ready configs
- 🌐 Protocol Agnostic: Write once, deploy as HTTP/gRPC/WebSocket services
- Install CLI:
npm install -g koatty_cli
- Create Project:
koatty new awesome-app
- Run Development Server:
cd awesome-app
npm run dev
// config/config.ts
export default {
...
protocol: "grpc", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss'
...
}
@Service()
export class UserService {
async findUser(id: number) {
return { id, name: 'Koatty User' };
}
}
@Controller()
export class IndexController {
app: App;
ctx: KoattyContext;
...
@Autowired()
private userService: UserService;
async test(id: number) {
const info = await this.userService.findUser(id);
...
}
}
@Aspect()
export class LogAspect implements IAspect {
app: App;
run() {
console.log('LogAspect');
}
}
// Apply aspect to controller
@Controller()
@BeforeEach(LogAspect)
export class UserController {}
// plugin/logger.ts
export class LoggerPlugin implements IPlugin {
app: App;
run() {
// todo something or hook on app.event
Logger.Debug("LoggerPlugin");
return Promise.resolve();
}
}
- HTTP、HTTPS、HTTP2、gRPC、WebSocket server.✔️
- Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env).✔️
@ExceptionHandler()
Register global exception handling.✔️- graceful shutdown and pre-exit event.✔️
- custom decorator based on app events.✔️
- GraphQL supporting. 💪
- OpenTelemetry . 💪
Framework | Requests/sec | Latency | Memory Usage |
---|---|---|---|
Koatty | 13,321 | 1.43ms | 54MB |
Express | 12,456 | 1.45ms | 52MB |
NestJS | 11,892 | 1.51ms | 63MB |
Tested on AWS t3.micro with 100 concurrent connections
Thanks to these amazing developers:
BSD-3 © Koatty Team