8000 GitHub - Koatty/koatty: Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Koatty/koatty

Repository files navigation

Koatty πŸš€

npm version License

Koa2 + TypeScript + IOC = Koatty. Koatty is a progressive Node.js framework for building efficient and scalable server-side applications. It's perfect for crafting enterprise-level APIs, microservices, and full-stack applications with TypeScript excellence.

Why Koatty? πŸ’‘

  • πŸš„ High Performance: Built on top of Koa2 with optimized architecture
  • 🧩 Full-Featured: Supports gRPC, HTTP, WebSocket, scheduled 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 configurations
  • 🌐 Protocol Agnostic: Write once, deploy as HTTP/gRPC/WebSocket services

New Features ✨

  • HTTP, HTTPS, HTTP2, gRPC, and WebSocket server support βœ”οΈ
  • Environment-based configuration loading, command-line argument parsing (process.argv), and environment variable parsing (process.env) βœ”οΈ
  • @ExceptionHandler() for global exception handling βœ”οΈ
  • Graceful shutdown and pre-exit events βœ”οΈ
  • Custom decorators bound to app events βœ”οΈ
  • GraphQL integration βœ”οΈ
  • Full-stack tracing through OpenTelemetry βœ”οΈ
  • Middleware binding to controllers and method routes βœ”οΈ
  • gRPC streaming support βœ”οΈ
  • Swagger OpenAPI 3.0 support πŸ’ͺ

Core Features ✨

πŸ“‘ Multi-Protocol Support

// config/config.ts
export default {
  ...
  protocol: "grpc", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss' | 'graphql'
  ...
}

πŸ’‰ Dependency Injection

@Service()
export class UserService {
  async findUser(id: number) {
    return { id, name: 'Koatty User' };
  }
}

@Controller()
export class IndexController {
    app: App;
    ctx: KoattyContext;
    @Config("protocol")
    conf: { protocol: string };
    ...

    @Autowired()
    private userService: UserService;

    async test(id: number) {
        const info = await this.userService.findUser(id);
        ...
    }
}

βœ‚οΈ Aspect-Oriented Programming

@Aspect()
export class LogAspect implements IAspect {
  app: App;

  run() {
    console.log('LogAspect');
  }
}

// Apply aspect to controller
@Controller()
@BeforeEach(LogAspect)
export class UserController {
  ...
  @After(LogAspect)
  test() {
    ...
  }
}

πŸ”Œ Plugin System

// plugin/logger.ts
export class LoggerPlugin implements IPlugin {
  app: App;

  run() {
    // todo something or hook on app.event
    Logger.Debug("LoggerPlugin");
    return Promise.resolve();
  }
}

Benchmarks πŸ“Š

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

Documentation πŸ“š

Quick Start ⚑

  1. Install CLI:
npm install -g koatty_cli
  1. Create Project:
koatty new awesome-app
  1. Run Development Server:
cd awesome-app
npm run dev

Community 🌍

Contributors ✨

Thanks to these amazing developers:

License πŸ“„

BSD-3 Β© Koatty Team

0