C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Aspect-Oriented (AOP)
  • CQRS Architecture
  • GraphQL API
  • Tracing
  • Health Checks
Architecture

CQRS

Command Query Responsibility Segregation (CQRS) separates read and write operations for better scalability and performance.

Command Bus

Decouple write operations.

Query Bus

Segregate read operations.

Event Bus

Async event processing.

Sagas

Manage long-running processes.

Commands

commands.ts
1import { ICommand, CommandHandler, ICommandHandler, CommandBus } from "canxjs";
2
3export class CreateUserCommand implements ICommand {
4 type = 'CreateUser';
5 constructor(public readonly name: string) {}
6}
7
8@CommandHandler('CreateUser')
9export class CreateUserHandler implements ICommandHandler<CreateUserCommand> {
10 async execute(command: CreateUserCommand): Promise<void> {
11 console.log("Creating user:", command.name);
12 }
13}
14
15// In your controller:
16await commandBus.execute(new CreateUserCommand("Alice"));

Queries

queries.ts
1import { IQuery, QueryHandler, IQueryHandler } from "canxjs";
2
3export class GetUserQuery implements IQuery {
4 type = 'GetUser';
5 constructor(public readonly id: string) {}
6}
7
8@QueryHandler('GetUser')
9export class GetUserHandler implements IQueryHandler<GetUserQuery> {
10 async execute(query: GetUserQuery) {
11 return { id: query.id, name: "Alice" };
12 }
13}

Sagas

Sagas orchestrate complex workflows by listening to events and dispatching commands.

sagas.ts
1import { EventHandler, IEvent, ISaga, ICommand } from "canxjs";
2
3@EventHandler('UserCreated')
4export class UserSagas implements ISaga {
5
6 // React to events and dispatch commands
7 async *handle(event: IEvent): AsyncGenerator<ICommand> {
8 if (event.type === 'UserCreated') {
9 yield new SendWelcomeEmailCommand(event.userId);
10 }
11 }
12}