A clean architecture backend API built with Elysia.js, TypeScript, and Bun.
- Clean architecture pattern with separation of concerns
- Elysia.js web framework with TypeBox validation
- PostgreSQL with Drizzle ORM
- Redis for caching and rate limiting
- BullMQ for background job processing
- ClickHouse for analytics (optional)
- Comprehensive authentication and authorization (RBAC)
- API documentation with OpenAPI and Scalar
- Docker support
- Runtime: Bun
- Framework: Elysia.js
- Language: TypeScript
- Databases: PostgreSQL, Redis, ClickHouse
- ORM: Drizzle
- Queue: BullMQ
- Validation: TypeBox
- API Docs: OpenAPI + Scalar
- Bun 1.x or higher
- PostgreSQL
- Redis
- Docker (optional)
Install dependencies:
bun installCopy the example environment file and configure your environment variables:
cp .env.example .envConfigure the following environment variables:
- Database connections (PostgreSQL, Redis, ClickHouse)
- Mail settings
- JWT secrets
- Application settings
See Configuration Documentation for detailed reference.
Generate and run PostgreSQL migrations:
bun run db:generate
bun run db:migrateSeed the database with initial data:
bun run db:seedFor development, you can also use:
bun run db:push # Push schema directly without migrationsOpen Drizzle Studio to view and edit data:
bun run db:studioRun ClickHouse migrations:
bun run db:clickhouse:migrateCheck ClickHouse migration status:
bun run db:clickhouse:statusRun the API server in development mode:
bun run devThe API will be available at http://localhost:3000
Build the application:
bun run buildStart the production server:
bun run startBuild and run with Docker Compose:
docker-compose up -dsrc/
├── base.ts # Base Elysia app with core plugins
├── index.ts # Entry point
├── bull/ # Background jobs
│ ├── queue/ # Job queues
│ └── worker/ # Job workers
├── libs/ # Shared libraries
│ ├── cache/ # Cache utilities
│ ├── config/ # Configuration
│ ├── database/ # Database clients and repositories
│ ├── errors/ # Custom error classes
│ ├── guards/ # Authorization guards
│ ├── mailer/ # Email service
│ ├── plugins/ # Elysia plugins
│ ├── repositories/ # Data access layer
│ ├── types/ # TypeScript types
│ └── utils/ # Utility functions
└── modules/ # Feature modules
├── auth/ # Authentication
├── home/ # Root/health endpoints
├── profile/ # User profile
└── settings/ # Application settings
Run linting:
bun run lintFix linting issues:
bun run lint:fixFormat code:
bun run formatType checking:
bun run typecheckOnce the server is running, access the interactive API documentation at:
http://localhost:3000/docs
The API documentation is powered by OpenAPI with Scalar UI, providing:
- Browse all endpoints with request/response schemas
- Try endpoints directly from the browser
- View validation rules and examples
- Bearer token authentication support
Download the OpenAPI specification:
http://localhost:3000/docs/openapi.json
For more details, see the API Documentation Guide.
bun run dev- Run API server with hot reloadbun run build- Build the applicationbun run start- Start the production server
bun run lint- Run ESLintbun run lint:fix- Fix ESLint issuesbun run format- Format code with Prettierbun run typecheck- Run TypeScript type checking
bun run db:generate- Generate migration files from schemabun run db:migrate- Apply pending migrationsbun run db:push- Push schema to database (development only)bun run db:pull- Pull schema from databasebun run db:studio- Open Drizzle Studiobun run db:drop- Drop all tables (dangerous!)bun run db:seed- Seed database with initial data
bun run db:clickhouse:migrate- Run ClickHouse migrationsbun run db:clickhouse:status- Check migration status
You can also use make commands:
make help- Show all available commandsmake dev- Start development servermake fresh- Drop, push schema, and seed (development)make reset- Generate migrations, migrate, and seed
Comprehensive documentation is available in the docs/ directory:
- API Documentation - API consumer guide
- Configuration - Environment variables reference
- Error Handling - Error handling guide
- Plugins - Plugin system guide
- Security - Security documentation
This project follows Clean Architecture principles:
- Modules - Feature-based modules containing routes and business logic
- Repositories - Data access layer with database operations
- Services - Business logic and orchestration
- Plugins - Cross-cutting concerns (logging, error handling, security)
- Utils - Helper functions and utilities
- Repository Pattern - Factory functions returning database access methods
- Service Pattern - Object exports with business logic methods
- Plugin Pattern - Reusable Elysia plugins for middleware
- Error Handling - Custom error classes with consistent API responses
- Validation - TypeBox schemas for runtime validation
See TODO.md for a comprehensive list of planned improvements and enhancements.
Compare with clean-hono implementation: COMPARISON.md
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
Please read our Contributing Guidelines and Code of Conduct.
This project is licensed under the MIT License.