Skip to content
Proyectos

Acerca de

The only cross-platform, cross-runtime, decorator-based framework for building modular applications in TypeScript.

Herramientas de desarrollo

Cómo se miden estas cifras

What you can do

  • One model for every application. Modules, controllers and providers are the same in an HTTP application, a command-line application and an application that handles the messages of a broker.
  • Dependency injection with no reflection. Dependencies are listed explicitly and checked against the constructor at compile time: no reflect-metadata, no emitted types. A provider can be asynchronous.
  • Fails before it starts. A missing provider, a circular dependency or a duplicate route is reported when the application is created, not on the first request.
  • Standard decorators. TC39 decorators, as TypeScript 5 has them. Legacy (experimentalDecorators) and Bun decorators work too.

Crecimiento de estrellas medido

in 24h
0
in 7 days
Recopilando historial
in 15 days
Recopilando historial
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

Cho Logo

The only cross-platform, cross-runtime, decorator-based framework for building modular applications in TypeScript.

Release CI License: MIT

CHO

CHO (chō) is an enterprise ready decorator-based framework for building modular applications. It uses modern JavaScript decorators to provide a clean and efficient way to define the structure of an application.

Main features

  • One model for every application. Modules, controllers and providers are the same in an HTTP application, a command-line application and an application that handles the messages of a broker.
  • Dependency injection with no reflection. Dependencies are listed explicitly and checked against the constructor at compile time: no reflect-metadata, no emitted types. A provider can be asynchronous.
  • Fails before it starts. A missing provider, a circular dependency or a duplicate route is reported when the application is created, not on the first request.
  • Standard decorators. TC39 decorators, as TypeScript 5 has them. Legacy (experimentalDecorators) and Bun decorators work too.
  • Built on web standards. A handler receives a standard Request and answers with a standard Response. A router is built in, so an HTTP application needs no HTTP library, and an adapter runs it on Hono or on Fastify.
  • Server-sent events and WebSockets, with no library: an async * method is a stream of events, and a controller handles a socket with decorators.
  • Typed, validated arguments. A handler declares what it receives, and a schema of Zod, Valibot, ArkType or any other Standard Schema checks it.
  • Middlewares and error handlers on a module, a controller or a handler, as functions or as injectable classes.
  • Message brokers. The same handlers run on Apache Kafka and on NATS, and a contract gives the two sides of a message their types.
  • OpenAPI. The document of an application, and its page, are made from its code.
  • AsyncAPI. The same for messages: the document of the consumers of an application, and a page that needs nothing but a browser.
  • Testable with no server. An application is a function that takes a Request, and a test replaces any provider with a fake.
  • A command-line tool. cho creates a workspace, adds projects to it, runs them, and generates controllers, services and modules.

Portability

CHO applications can run on multiple JavaScript runtimes, including Node.js, Deno, Bun, and Cloudflare Workers. This allows developers to write code once and deploy it anywhere, without worrying about runtime-specific issues.

Node.js Logo Deno Logo Bun Logo Cloudflare Workers Logo

A quick look

An HTTP application:

import {
    ChoWeb,
    type ChoWebContext,
    Controller,
    Get,
    Injectable,
    Module,
} from "@chojs/web";
import { serve } from "@chojs/web/serve";

@Injectable()
class UserStore {
    find(id: string) {
        return {id, name: "Ada"};
    }
}

@Controller({route: "users", dependencies: [UserStore]})
class UsersController {
    constructor(readonly store: UserStore) {
    }

    @Get(":id") // GET /users/42
    get(ctx: ChoWebContext) {
        return this.store.find(ctx.params.id!); // sent as JSON
    }
}

@Module({providers: [UserStore], controllers: [UsersController]})
class App {
}

const app = await ChoWeb.create(App);
await serve(app, {port: 3000}); // the same file runs on Deno, Node.js and Bun

A command-line application, with the same modules, controllers and providers:

import process from "node:process";
import {
    Action,
    ChoCommand,
    type ChoCommandContext,
    Controller,
    Help,
    Module,
} from "@chojs/command";

@Controller()
class Greeter {
    @Help("Say hello")
    @Action("hello", {string: ["name"]})
    hello(ctx: ChoCommandContext) {
        console.log(`Hello, ${ctx.args.name ?? "world"}!`);
    }
}

@Module({controllers: [Greeter]})
class App {
}

const app = ChoCommand.create(App, {name: "greet"});
const code = await app.run(process.argv.slice(2)); // greet hello --name you
await app.close();
process.exit(code);

An application that handles the messages of a broker is made the same way: see @chojs/message.

Getting started

With cho

cho is the command-line tool of the framework. Install it once, for the whole machine:

npm install --global @chojs/cli   # Node.js
bun add --global @chojs/cli       # Bun

# Deno
deno install --global --allow-env --allow-read --allow-write --allow-run --name cho jsr:@chojs/cli

Create a workspace, and run its application:

cho new shop   # asks what you are building, and writes the workspace
cd shop
cho serve      # runs the application, and again when a file changes

cho new writes a web application, a command-line tool or a message consumer, with its tests, and it runs as it is. The workspace is the same on Deno, on Node.js and on Bun: the runtime you choose is the one cho installs and runs with, and another one can take over later.

Then, in the workspace:

cho generate controller users   # users.ts and its test, for the application
cho add                         # another application, or a library

@chojs/cli has every command, and its options.

In a project of your own

Pick the package for what you are building, and add it to the project; it brings everything an application needs:

# an HTTP application
deno add jsr:@chojs/web
npx jsr add @chojs/web
bunx jsr add @chojs/web

# a command-line application
deno add jsr:@chojs/command
npx jsr add @chojs/command
bunx jsr add @chojs/command

# an application that handles the messages of a broker
deno add jsr:@chojs/message
npx jsr add @chojs/message
bunx jsr add @chojs/message

Deno and Bun run TypeScript decorators directly. On Node.js, compile the application with TypeScript 5 or run it with a tool such as tsx.

@chojs/web has a router built in, on the standard URL Pattern API, so an HTTP application needs nothing else. To match requests with another HTTP library, give ChoWeb.create the linker of an adapter:

Router Runs on
Built in Deno, Node.js 24, Bun 1.3.4 and Cloudflare Workers: tested on the four
@chojs/vendor-hono Deno, Node.js, Bun and edge runtimes
@chojs/vendor-fastify Node.js only

@chojs/message is connected to its broker by an adapter, a package of its own:

Broker Adapter Runs on
Apache Kafka @chojs/vendor-kafka Node.js; tested on Deno and Bun
NATS @chojs/vendor-nats Deno, Node.js and Bun

Packages

The name of a package links to its guide, and the specification is its full description.

Package Version For Specification
@chojs/web JSR HTTP applications specs
@chojs/command JSR Command-line applications specs
@chojs/message JSR Applications that handle the messages of a broker, such as Kafka specs
@chojs/vendor-cho JSR Middlewares for the built-in router of @chojs/web, such as CORS specs
@chojs/vendor-hono JSR Running @chojs/web on Hono specs
@chojs/vendor-fastify JSR Running @chojs/web on Fastify (Node.js only) specs
@chojs/vendor-kafka JSR Running @chojs/message on Apache Kafka (tested on Deno and Bun too) specs
@chojs/vendor-nats JSR Running @chojs/message on NATS, with replies specs
@chojs/openapi JSR The OpenAPI document of a @chojs/web application, and its page specs
@chojs/asyncapi JSR The AsyncAPI document of a @chojs/message application, and its page specs
@chojs/dev JSR Development tools: the endpoints of an application, and its graph specs
@chojs/prompt JSR Questions in a terminal: a text, a yes or no, a choice of a list specs
@chojs/cli JSR cho, the command-line tool of the framework specs
@chojs/core JSR The dependency injection engine underneath specs

Runnable examples are in examples/.

Contributing

Contributions are welcome: see CONTRIBUTING.md and the code of conduct.

License

MIT


This project uses the TC39 stage 3 decorators proposal (JavaScript decorators).

蝶

Explorar proyectos relacionados

Cargando…