A professional, scalable, and modular SaaS API boilerplate built with Bun.js, ElysiaJS, and Mongoose.
- Runtime: Bun.js (Latest)
- Framework: ElysiaJS
- ORM: Mongoose (MongoDB)
- Auth: BetterAuth with JWT
- Documentation: Swagger
- Validation: Zod (via Elysia TypeBox/t)
- Payments: Stripe
- Email: Nodemailer
- Architecture: Clean Architecture, SOLID, Repository Pattern
src/
├── application/ # Use Cases & DTOs (Business Logic)
├── core/ # Global Config, Errors, Logger
├── domain/ # Entities & Repository Interfaces (Enterprise Rules)
├── infrastructure/ # DB, Repositories Impl, External Services (Stripe, Email)
├── presentation/ # Controllers, Routes, Middlewares
├── shared/ # Utils & Constants
└── tests/ # Automated Tests
-
Install Bun:
curl -fsSL https://bun.sh/install | bash -
Install Dependencies:
bun install
-
Environment Variables: Fill in your credentials in the
.envfile. -
Run Development Server:
bun run src/index.ts
-
Run Tests:
bun test
Once the server is running, access the Swagger documentation at:
http://localhost:3000/doc
- Multi-tenancy: Built-in structure for tenant isolation.
- Clean Architecture: Decoupled layers for easy maintenance and database swapping.
- Error Handling: Global middleware with custom API error classes.
- Logging: Native Bun logging to files in
/logs. - SaaS Workflow: User registration -> Email verification -> Subscription -> Admin privileges.
- Roles:
ADMIN,OWNER,MANAGER,USER. - Registration: Users start as
inactivewithUSERrole. - Verification: Account activation via email code.
- Upgrading: Upon subscription, users are promoted to
ADMIN(Tenant Owner) to manage their own users.