This is the backend for Hagakure, a project in development.
Click to expand
Runtime and dependencies
This project currently runs on the Bun 1.0.29 runtime. If you don't have it installed, I advise you just install the latest version and it should work.
With Bun installed, run the following command to install the project's dependencies:
bun install
Database
This project requires a Postgres database. If you have Docker installed, you can use the provided docker-compose.yml
file to start and stop a DB container by running these commands:
bun run db:up
bun run db:stop
To completely remove the container, you can run the following command:
bun run db:down
Environment variables
With a Postgres database running, copy the contents of .env.template
to a new file called .env
and fill in the environment variables with your database connection string and the desired port you want to run the application on.
Then run the Drizzle commands to initialize the database schema.
bun run db:generate
bun run db:migrate
Remember to run migrations after making changes to the database schema:
bun run db:migrate
Always commit the new migration files generated in ./drizzle
!
Setup complete and additional scripts
With these steps done, you're ready to start the development server:
bun run dev
Happy coding!
Additional scripts you should be aware of (WIP):
# lint and format the project with Biome
bun run lint:fix
...
Click to expand
This project implements a few concepts from Clean Architecture (or at least attempts to), represented through this image:
The core of the application are it's domain entities, use cases and business logic. They must not have have any external dependencies. The Domain layer is where application entities and data structures are contained and can be found at src/core/domain
. The Application layer has business logic that implements the use cases of the system - located in src/core/application
.
Outside of this core, the application has an Infrastructure layer, where external dependencies like databases and HTTP servers can be interacted with, and a Presentation layer, where the application can be interacted with - in this case, defining controller classes that handle HTTP requests and responses and invoke the correct use cases.
As a rule, each layer cannot have dependencies from an outermost layer - instead relying on interfaces and the Dependency Inversion principle.
Click to expand
This application is built using:
- Bun (runtime)
- ElysiaJS (API framework)
- Drizzle (ORM)
- TypeScript (type-checking)
- Docker (database containers in development environment)