models object that every part of the backend uses to read and write data.
Why
Sequelize gives you a fully typed ORM over PostgreSQL with first-class migration support and soft-delete semantics built in. It’s the only database client supported by this stack, and every model, migration, and seed is colocated underapps/backend/src/tools/rds/sequelize/ for easy navigation.
Setup
- In
development.ts,production.ts, andtest.ts, settools.rds: - In
compose.yml, thedbservice provides PostgreSQL: - In
.env.development, set: - Run migrations:
make migrate. - Run
make test module=backend.
Adding a new model
- Create
apps/backend/src/tools/rds/sequelize/models/<ModelName>/index.ts(or a flat file for simple models). ExtendModelfrom Sequelize, define attributes, and callModelName.init(...)with the table name insnake_caseplural. - Register associations in the model file’s
associatestatic method, called automatically by the model loader. - Generate a migration: copy the closest existing migration in
apps/backend/src/tools/rds/sequelize/migrations/and name it<timestamp>-<describe-change>.ts. - Export the model from
apps/backend/src/tools/rds/sequelize/models/index.ts. - Run
make migrateto apply. - Run
make test module=backend.
Migrations
Migrations live inapps/backend/src/tools/rds/sequelize/migrations/ and are run in timestamp order. Run them with:
Soft deletes (paranoid models)
Models markedparanoid: true set a deleted_at timestamp on deletion instead of removing the row. Sequelize automatically excludes soft-deleted rows from all queries unless you explicitly pass paranoid: false:
Gotchas
- Always pass the active
transactionto every ORM call inside a transaction block. Omitting it causes dirty reads and partial writes. - Never run
sequelize.sync()in production — use migrations. - The
verbose: trueconfig flag logs every SQL query. Useful for debugging, but leave it off in production. PGPORTmust be a number. The config parses it withNumber(process.env.PGPORT)— ensure your.envhas no quotes around it.
What’s next?
- Configuration — environment-level database vars.
- Tooling system — how the tools object is assembled.
- Architecture overview — where this tool sits in the full system.