Skip to main content

Notification Service — Local Dev Setup

Status: populated Owner: Platform Engineering Last updated: 2026-04-18

1. docker-compose

docker compose -f docker-compose.dev.yml up -d postgres redis nats

Relevant services:

  • postgres:16 with notif schema auto-created.
  • redis:7-alpine.
  • nats:2.10-alpine JetStream enabled.

Note: No Kong needed (this service has no Kong-routed endpoints).

2. Environment

Copy .env.example.env:

PORT=3030
DATABASE_URL=postgresql://notif:notif@localhost:5432/ghasi_sms?schema=notif
REDIS_URL=redis://localhost:6379/3
NATS_URL=nats://localhost:4222
AUTH_SERVICE_URL=http://localhost:3001
SMS_ORCHESTRATOR_URL=http://localhost:3010
SMS_API_KEY=dev-sms-key
SENDGRID_API_KEY=SG.dev-key-replace-for-real-sends
SENDGRID_FROM_EMAIL=noreply@dev.ghasi.io
INTERNAL_TOKEN=dev-internal-token
PLATFORM_ADMIN_CACHE_TTL_SECONDS=300
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
LOG_LEVEL=debug

For local email testing, use SENDGRID_API_KEY=SG.disabled and set NOTIF_EMAIL_DRY_RUN=true to log emails instead of sending.

3. Install + migrate

pnpm install
pnpm --filter @ghasi/service-notification prisma migrate dev
pnpm --filter @ghasi/service-notification prisma db seed
pnpm --filter @ghasi/service-notification dev

4. Smoke test — Publish test event

# Simulate a billing.invoice.generated event
nats pub billing.events '{
"schemaVersion":"1",
"invoiceId":"inv-test-001",
"accountId":"660e8400-e29b-41d4-a716-446655440001",
"tenantId":"550e8400-e29b-41d4-a716-446655440000",
"periodStart":"2026-03-01",
"periodEnd":"2026-03-31",
"totalMessages":50000,
"subtotalAmount":"1000.00",
"currency":"USD",
"s3Key":"invoices/660e.../2026/03/inv-test-001.pdf",
"generatedAt":"2026-04-01T00:10:00Z"
}'

Check notif.notification_log for SENT/FAILED row. Check NOTIF_EMAIL_DRY_RUN log for rendered email.

5. Smoke test — Template admin

# List active templates
curl -H "X-Internal-Token: dev-internal-token" http://localhost:3030/internal/templates

# Preview a template
curl -X POST -H "X-Internal-Token: dev-internal-token" \
-H "Content-Type: application/json" \
http://localhost:3030/internal/templates/{id}/preview \
-d '{ "variables": { "invoiceId": "inv-001", "periodStart": "2026-03-01", "periodEnd": "2026-03-31", "subtotalAmount": "1000.00", "currency": "USD", "downloadUrl": "https://example.com" } }'

6. Seed Data

prisma/seed.ts creates:

  • 1 tenant, 1 account, 2 users (account.admin + platform.admin).
  • Default templates for all 6 notification types (USER_REGISTERED, INVOICE_GENERATED, OPERATOR_DOWN, OPERATOR_RECOVERED, SYSTEM_SECURITY_ALERT, SYSTEM_INFO_ALERT).
  • NATS streams: AUTH_EVENTS, BILLING_EVENTS (shared with billing-service in dev), OPERATOR_HEALTH, SYSTEM_ALERTS.

7. Common Commands

pnpm lint
pnpm typecheck
pnpm test # unit
pnpm test:int # testcontainers
pnpm test:e2e # requires all deps up
pnpm prisma studio