The system design is heavily inspired by Clean Architecture, DDD and Layered Architecture concepts.
- Controller - Handling requests, parsing and data validation.
- Service - Contains the business logic.
- Repository - Data layer managing communication with the database.
├── src
│ ├── app // application configuration, DI and setup
│ ├── core // holds all domain packages
│ │ ├── domain1
│ │ │ ├── http // transport/presenter layer handling data I/O, validation and routing.
│ │ │ ├── repo // data layer managing data fetching from db, cache etc.
│ │ │ ├── mocks // mocks for testing
│ │ │ ├── service // buisness logic layer
│ │ │ └── domain.ts // domain entities, interfaces and type definitions
│ │ ├── domain2
│ │ └── ...
│ ├── pkg // foundation packages for supporting core packages with db, logging, auth etc.
│ │ ├── db // db connection, migrations and helpers
│ │ ├── error // internal error definitions
│ │ ├── logger // logger setup
│ │ ├── middleware // middlewares handling permissions, logging, auth etc.
│ │ ├── web // response renderer for processing responses
│ │ └── ...
│ ├── cli.ts // cli for creating users and generating jwts for server side development
│ └── index.ts // application entrypoint
└── README.md
Database migrations is handled using dbmate and can be run using cli or docker. Migration files can be found in src/pkg/db/migrations
.
Migrate to latest database version
pnpm migrate up
Rollback one version
pnpm migrate rollback
Create new migration file
pnpm migrate new <name>
docker run --rm -it --network=host -v "$(pwd)/src/pkg/db:/db" --env-file=.env ghcr.io/amacneil/dbmate:1 --no-dump-schema <COMMAND>
Prod database can be accessed using the gcloud cli by installing the following component
gcloud components install cloud_sql_proxy
WARNING: This is the production database and should not be manipulated manually
cloud_sql_proxy -instances=<your-gcp-project-id>:<gcp-region>:prod=tcp:5432