A clean architecture implementation using Bun, Elysia, and Postgres.js for building a robust and scalable API.
This project demonstrates a clean architecture approach to building a web API using modern JavaScript technologies. It leverages Bun as the runtime environment, Elysia as the web framework, and Postgres.js for database interactions. The application follows clean architecture principles, ensuring a clear separation of concerns and maintainability.
Key highlights:
While Elysia doesn't provide a scalable structure out of the box, this boilerplate shows how to achieve clean architecture with some additional effort, making it an excellent starting point for serious application development.
The project follows a clean architecture pattern with the following structure:
src/
├── auth/
│ ├── application/
│ ├── domain/
│ └── infrastructure/
├── notes/
│ ├── application/
│ ├── domain/
│ └── infrastructure/
├── shared/
│ └── infrastructure/
└── users/
├── domain/
└── infrastructure/
auth/
: Authentication-related modulesnotes/
: Note management modulesusers/
: User management modulesshared/
: Shared utilities and configurationsEach module is divided into:
application/
: Use cases and business logicdomain/
: Domain entities and typesinfrastructure/
: External interfaces (controllers, repositories)bun run start
The project uses Elysia, a modern and performant web framework for Bun. It provides a clean and intuitive API for building web applications.
Fastest full-featured node & deno client, Postgres.js is used for database operations, offering a simple and efficient way to interact with PostgreSQL databases.
The project follows clean architecture principles, separating concerns into distinct layers: Application, Domain, and Infrastructure.
Code quality and consistency are maintained using ESLint and Prettier with a standardized configuration.
Imports are automatically organized using the eslint-plugin-simple-import-sort
plugin.
Environment variables are managed securely using a combination of .env
files and the zod
library for validation.
A simple database migration system is implemented using raw SQL scripts.
API documentation is automatically generated using Swagger, making it easy for developers to understand and interact with the API.
The project includes integration (E2E) tests to ensure the correct functionality of the API endpoints. Run the tests using:
bun test
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。