Use Node.js 22 (22.15 or newer, matching CI and the node:22-alpine images), npm, and Docker Desktop with Compose v2. Copy .env.example to .env for local commands, but do not commit the copy.
This repository provides a full local Compose file at docker-compose.yml plus committed base, development, test, and production overlays. The base file defines PostgreSQL 16, Redis 7, Zookeeper, and Kafka; the overlays add application services and environment-specific ports/configuration. docker-compose.override.yml is ignored for local-only customization.
# start the committed full local stack and wait for application healthchecks
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml up -d --build --wait --wait-timeout 300
# after the stack is healthy, bootstrap through the public API and validate it
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml ps
npm run seed
npm run e2e
# start the full stack. It runs with NODE_ENV=production, so it needs its own SYSTEM_JWT_SECRET (#202):
# at least 32 characters and different from JWT_SECRET. driver-service also needs the private documents
# bucket name and the national ID HMAC key (#207, at least 32 characters, different from the JWT secrets).
SYSTEM_JWT_SECRET=$(openssl rand -hex 32) \
DRIVER_DOCUMENTS_BUCKET=delivery-plus-private-local \
NATIONAL_ID_HMAC_SECRET=$(openssl rand -hex 32) \
docker compose up -d --build
# validate the committed development graph in Linux/WSL
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml config --quiet
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml ps --all# PowerShell (WSL-hosted validation is also supported)
$env:SYSTEM_JWT_SECRET = -join ((1..64) | ForEach-Object { '{0:x}' -f (Get-Random -Maximum 16) })
$env:DRIVER_DOCUMENTS_BUCKET = 'delivery-plus-private-local'
$env:NATIONAL_ID_HMAC_SECRET = -join ((1..64) | ForEach-Object { '{0:x}' -f (Get-Random -Maximum 16) })
docker compose config --quiet
docker compose up -d --buildThe root multi-stage Dockerfile accepts SERVICE_NAME and builds the shared package followed by the selected service.
For local media uploads, start the dev overlay (docker compose -f docker-compose.base.yml -f docker-compose.dev.yml up) so the media-storage service (SeaweedFS's S3 gateway) and its bucket initializer are included. The production overlay requires AWS_S3_BUCKET, AWS_PUBLIC_BASE_URL, and CORS_ORIGINS. S3 credentials come from the AWS default credential chain: on EC2 the instance role (IMDSv2 with a hop limit of 2, so containers reach it), and no keys in any file. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are optional, for hosts without a role; if you set them, use deployment secrets, not committed credentials. Configure the bucket to expire objects with the pending/ prefix after one day so unconfirmed uploads are cleaned up.
Driver documents (#207) need a second, private bucket, named by DRIVER_DOCUMENTS_BUCKET (driver-service refuses to start in production without it, and refuses the public media bucket's name). Use separate buckets for staging and production. Set it up with:
- Block Public Access on, and no bucket policy that grants any principal access;
- default encryption SSE-S3 (S3's default for new buckets);
- a lifecycle rule expiring objects with the
pending/prefix after one day (unconfirmed uploads); - CORS allowing
POSTfrom the driver app origins only (the presigned upload goes straight from the app to the bucket); - an IAM policy for driver-service allowing
s3:PutObjectands3:GetObjectonpending/drivers/*anddrivers/*only. S3 can't scopePutObjectto one driver, so the presigned POST conditions, which fix the exact key, are the control;GetObjectcan't be limited to presigned URLs either, so theonboarding.reviewpermission check before a URL is issued is the control. driver-service needs noListBucket, andDeleteObjectwaits for account deletion (#233) and the retention job.
driver-service also needs NATIONAL_ID_HMAC_SECRET: the key of the HMAC that detects one national ID on two accounts. It has no default outside development and test, must be at least 32 characters, and must differ from the JWT secrets. Changing it later makes existing hashes stop matching, so keep it as stable as the database. AWS_REGION defaults to us-east-1; endpoint variables are only needed for S3-compatible providers or private/CDN URL layouts.
Behind a load balancer or reverse proxy, set TRUSTED_PROXY_HOPS on the gateway to the number of proxies in front of it, for example 1 for one load balancer that appends to X-Forwarded-For (#251). Left at 0, every client shares the balancer's address, so the per-client login and registration limits become one limit for everyone. Set too high, a client can choose the address it is counted as. See services/api-gateway.md.
PostgreSQL creates these logical databases: auth_service, user_service, restaurant_service, menu_service, order_service, payment_service, driver_service, delivery_service, notification_service, and audit_service (#213; on an existing volume, create it by hand, see audit-service). Compose passes each service its own database URL via DATABASE_URL.
The repository provides Compose validation commands, but this document does not claim that the full stack has been started successfully in every environment. Validate the local runtime with docker compose config --quiet, docker compose ps, and targeted service logs.
Internal containers communicate using Docker DNS names such as http://order-service:3006, redis://redis:6379, and kafka:29092. For local host access, Kafka is published as 127.0.0.1:9092 and is reachable from tools running on the machine as localhost:9092. Kafka UI remains exposed locally on 127.0.0.1:8085 and connects to the Compose network via kafka:29092.
Listener summary:
- Docker services →
kafka:29092 - Host development tools →
localhost:9092 - Kafka UI →
localhost:8085
- Topics:
order.events,payment.events,delivery.events, plus one dead-letter topic each (<topic>.dlq). Consumers create them on startup with broker defaults (1 partition locally); production should create them up front with explicit partition counts and replication. Events are keyed byorderId, so partitions can be added without breaking per-order ordering. - A handler gets
maxHandlerAttemptstries (default 3). After that the message goes to<topic>.dlqwithdlq-*headers (original topic/partition/offset, consumer group, reason, error, time) and the source offset is committed. If the dead-letter send itself fails, the offset is not committed and the message is redelivered. - Inspect:
npm run kafka:dlq -- order.events(usesKAFKA_BROKER, defaultlocalhost:9092). Replay after fixing the cause: add--replay. Replays go back to the original topic; consumer groups that already handled an event skip it via their Redis idempotency markers. - Retention: keep
.dlqtopics at least as long as the source topics (Kafka default 7 days), and longer if replays may happen later. Processed-event markers in Redis expire after 7 days, matching the default source retention; Redis must persist (Compose uses AOF on theredis_datavolume).
This repository uses a migration-first database workflow for every PostgreSQL-backed service.
Start the infrastructure first:
docker compose up -d postgres redis zookeeper kafkaCreate or update the service schema from the service folder:
npm run migration:generate --workspace=@food-delivery/order-service
npm run migration:run --workspace=@food-delivery/order-service
npm run migration:show --workspace=@food-delivery/order-serviceThe generated migration files live under each service’s src/database/migrations directory. The migration history is tracked in the service database by TypeORM.
The Postgres container creates the logical service databases through docker/postgres/init.sql. That file creates databases such as auth_service, user_service, menu_service, order_service, and payment_service.
Application tables are created by TypeORM migrations. Do not rely on runtime schema sync. The repository intentionally keeps synchronize: false and migrationsRun: false for the service TypeORM configuration.
Generated UUID primary keys use PostgreSQL gen_random_uuid() from the pgcrypto extension. The 001-initial-schema migrations define this default for fresh databases. The 002-uuid-primary-key-defaults migrations apply the same default with ALTER TABLE for databases where 001 was already applied before the UUID fix. Do not manually assign IDs in API clients or seed scripts.
The generated-ID tables are credentials, restaurants, categories, menu_items, orders, order_items, payments, deliveries, drivers, and notifications. user_profiles.id is intentionally excluded: it is a @PrimaryColumn whose value comes from auth-service.
Verify a repaired database with:
docker compose exec postgres psql -U postgres -d restaurant_service \
-c "SELECT column_name, column_default, is_nullable, data_type FROM information_schema.columns WHERE table_name = 'restaurants' AND column_name = 'id';"The expected column_default is gen_random_uuid().
The Docker image startup path runs the service migration before the Node process starts. This means the production-safe flow is:
- build the image
- start the Postgres container
- let the app container execute its migration
- start the service only after migration success
This is the intended Docker image startup path and avoids synchronize: true creating implicit schema drift. Existing databases still require care: the payment service also contains a manual SQL upgrade under services/payment-service/migrations/ that is not part of the normal TypeORM migration runner.
- migration files are expected to be forward-only once they are published
- do not edit an already-applied migration in a shared environment
- new schema changes must be created as new migration files
- rollback is limited to recovery and local cleanup; it is not the normal deployment path
- schema recovery should be performed with a new migration or a controlled maintenance window, not by re-running
synchronize
For a disposable local environment, recreate volumes to test the initial schemas from zero:
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml down -v
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml build --no-cache
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml up -dFor an existing local database, keep the volume and rebuild/recreate the affected PostgreSQL-backed service so its 002-uuid-primary-key-defaults migration runs.
CI runs npm ci, lint, tests, TypeScript builds, Compose validation, and an API Gateway image build. Trivy scans the filesystem and the built image for unfixed CRITICAL vulnerabilities and secrets. CI does not require production credentials or start the full infrastructure.