Lewati ke konten

Introduction

A Lean Framework for Enterprise Scalability.

GamanJS adalah framework HTTP ringan dan cepat yang dibangun di atas Bun runtime. Dirancang untuk membangun REST API yang terstruktur dengan arsitektur Controller-Service-Middleware yang bersih dan mudah di-maintain.

  • ⚑ Blazing Fast β€” Dibangun di atas Bun Bun.serve() untuk performa maksimal
  • πŸ—οΈ Arsitektur Terstruktur β€” Pola Controller / Service / Middleware bawaan
  • πŸ“¦ API Response Fluent β€” Penanganan response yang bersih dan konsisten via ctx.send()
  • πŸ”€ Router Deklaratif β€” Definisi route yang bersih dengan composeRouter
  • 🧩 Type-Safe DI β€” Dependency injection sederhana via destrukturisasi dan TypeScript
  • πŸ›‘οΈ Exception Handling β€” Global & per-route exception handler
  • 🎯 Middleware Priority β€” Kontrol urutan middleware eksekusi
HalamanDeskripsi
MemulaiInstalasi & membuat project baru
BootstrapdefineBootstrap & konfigurasi server
RouterDefinisi route, grouping, & method
ControllerMembuat controller dengan composeController
ServiceBusiness logic dengan composeService
MiddlewareMiddleware & priority system
ResponsePenanganan response fluent dengan ctx.send
ContextRequest context (ctx) secara detail
Exception HandlerError handling global & per-route
Terminal window
bun create gaman@latest

GamanJS mengadopsi filosofi Feature-Based Modularity. Untuk skalabilitas yang lebih baik, kami merekomendasikan penempatan route, controller, dan service di dalam modul fitur:

src/
β”œβ”€β”€ index.ts # The Orchestrator (Entry Point)
└── modules/
└── app/ # Modul Utama Aplikasi
β”œβ”€β”€ controllers/
β”‚ └── AppController.ts
β”œβ”€β”€ services/
β”‚ └── AppService.ts
β”œβ”€β”€ middlewares/
β”‚ └── AppMiddleware.ts
└── AppRoutes.ts # Route untuk modul ini

Untuk aplikasi skala produksi yang besar, kamu bisa menambahkan lebih banyak modul fitur:

src/
β”œβ”€β”€ index.ts # The Orchestrator (Entry Point)
β”œβ”€β”€ database/ # Konfigurasi Database
└── modules/ # Pusat Logika Aplikasi
β”œβ”€β”€ app/ # Modul Infrastruktur (Global/Shared)
β”‚ β”œβ”€β”€ controllers/ # Handler untuk Request Global (Health, Index)
β”‚ β”‚ └── AppController.ts
β”‚ β”œβ”€β”€ services/ # Utility Shared & System Services
β”‚ β”‚ └── AppService.ts
β”‚ └── AppRoutes.ts # Middleware Global & Base Routing
β”‚
└── user/ # Modul Fitur (Contoh: User Management)
β”œβ”€β”€ controllers/ # Request Handlers (Login, Register, Profile)
β”‚ └── UserController.ts
β”œβ”€β”€ services/ # Business Logic (Auth Logic, User CRUD)
β”‚ └── UserService.ts
β”œβ”€β”€ models/ # Data Access Layer (Didukung @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 service
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