Skip to content

Introduction

A Lean Framework for Enterprise Scalability.

GamanJS is a lightweight, fast HTTP framework built on top of Bun runtime. Designed for building structured REST APIs with a clean Controller-Service-Middleware architecture that’s easy to maintain.

  • ⚑ Blazing Fast β€” Built on Bun’s native Bun.serve() for maximum performance
  • πŸ—οΈ Structured Architecture β€” Built-in Controller / Service / Middleware pattern
  • πŸ“¦ Fluent Response API β€” Clean and consistent response handling via ctx.send()
  • πŸ”€ Declarative Router β€” Clean route definition with composeRouter
  • 🧩 Type-Safe DI β€” Simple dependency injection via destructuring and TypeScript
  • πŸ›‘οΈ Exception Handling β€” Global & per-route exception handlers
  • 🎯 Middleware Priority β€” Control middleware execution order
PageDescription
Getting StartedInstallation & creating a new project
BootstrapdefineBootstrap & server configuration
RouterRoute definition, grouping, & methods
ControllerCreating controllers with composeController
ServiceBusiness logic with composeService
MiddlewareMiddleware & priority system
ResponseFluent response handling with ctx.send
ContextRequest context (ctx) in detail
Exception HandlerGlobal & per-route error handling
Terminal window
bun create gaman@latest

GamanJS embraces the Feature-Based Modularity philosophy. For better scalability, we recommend placing your routes, controllers, and services within feature modules:

src/
β”œβ”€β”€ index.ts # The Orchestrator (Entry Point)
└── modules/
└── app/ # Main Application Module
β”œβ”€β”€ controllers/
β”‚ └── AppController.ts
β”œβ”€β”€ services/
β”‚ └── AppService.ts
β”œβ”€β”€ middlewares/
β”‚ └── AppMiddleware.ts
└── AppRoutes.ts # Routes for this module

For large-scale production applications, you can add more feature modules:

src/
β”œβ”€β”€ index.ts # The Orchestrator (Entry Point)
β”œβ”€β”€ database/ # Database Configuration
└── modules/ # Powerhouse of your Application
β”œβ”€β”€ app/ # Infrastructure Module (Global/Shared)
β”‚ β”œβ”€β”€ controllers/ # Handlers for Global Requests (Health, Index)
β”‚ β”‚ └── AppController.ts
β”‚ β”œβ”€β”€ services/ # Shared Utilities & System Services
β”‚ β”‚ └── AppService.ts
β”‚ └── AppRoutes.ts # Global Middleware & Base Routing
β”‚
└── user/ # Feature Module (Example: User Management)
β”œβ”€β”€ controllers/ # Request Handlers (Login, Register, Profile)
β”‚ └── UserController.ts
β”œβ”€β”€ services/ # Business Logic (Auth Logic, User CRUD)
β”‚ └── UserService.ts
β”œβ”€β”€ models/ # Data Access Layer (Powered by @gaman/orm)
β”‚ └── UserModel.ts
└── UserRoutes.ts # Scoped Routes & Feature Middleware
import { defineBootstrap } from 'gaman';
import AppRoutes from './modules/app/AppRoutes';
defineBootstrap(async (app) => {
app.mount(AppRoutes);
app.mountServer({ http: 3431 });
});
import { composeRouter } from 'gaman/compose';
import { AppService } from './services/AppService';
import AppController from './controllers/AppController';
export default composeRouter((r) => {
// Inject services
r.mountService({
appService: AppService(),
});
r.get('/', [AppController, 'HelloWorld']);
});
import { composeController } from 'gaman/compose';
import { AppService } from '../services/AppService';
export type Deps = {
appService: AppService;
};
export default composeController(({ appService }: Deps) => ({
HelloWorld(ctx) {
return ctx.send(appService.WelcomeMessage()).ok();
},
}));
import { composeService } from 'gaman/compose';
import type { RT } from 'gaman/types';
export const AppService = composeService(() => ({
WelcomeMessage() {
return '❀️ Welcome to GamanJS';
},
}));
export type AppService = RT<typeof AppService>;
import { composeMiddleware } from 'gaman/compose';
export default composeMiddleware(async (ctx, next) => {
console.log(`[${ctx.request.method}] ${ctx.path}`);
return next();
});

MIT Β© Angga7Togk