Database overview
Baseleg uses Cloudflare D1 as the initial relational database, with Drizzle as the query/migration toolkit.
This document describes how the repo is structured so the data owner can expand it safely without breaking architecture boundaries.
Key rules
- UI routes/pages must not import Drizzle schema or repository implementations.
- Application packages must not depend on infrastructure implementations directly.
- Infrastructure owns D1/Drizzle wiring and repository implementations.
- Schema changes must ship with migrations.
Repo structure
db/schema/— canonical schema “source of truth” (placeholders today)db/migrations/— SQL migration files (generated/maintained as the schema evolves)db/seeds/— seed scripts/data for local/dev environmentspackages/infrastructure/db/— Drizzle + D1 wiring (implementation detail)packages/infrastructure/repositories/— repository implementations (DB-backed)
Suggested conventions (starting point)
These are conventions to adopt as we add real schema:
- One schema entrypoint per bounded context, e.g.:
db/schema/people.tsdb/schema/aircraft.tsdb/schema/scheduling.ts
- Migrations are append-only and ordered.
- Prefer explicit foreign keys for cross-table relationships.
- Keep “reporting” queries out of domain/application; implement in infrastructure behind ports.
Expansion roadmap (data owner)
- Define first tables for the v1 spine:
- People
- Aircraft
- Scheduling (bookings)
- Add minimal indexes for core queries (list + overlap checks).
- Add seed data that supports UI demos and test fixtures.
- Add a
drizzle.config.tsand a migration flow (when we’re ready to wire D1 locally/CI).