Analytics Service — Local Dev Setup
Status: populated Owner: Platform Engineering Last updated: 2026-04-18
1. docker-compose
From repo root: docker compose -f docker-compose.dev.yml up -d postgres redis nats.
Relevant services:
postgres:16withanlytschema auto-created.nats:2.10-alpineJetStream enabled.- ClickHouse optional:
docker compose --profile analytics-full up -d clickhouse.
2. Environment
Copy .env.example → .env:
PORT=3030
DATABASE_URL=postgresql://anlyt:anlyt@localhost:5432/ghasi_sms?schema=anlyt
DATABASE_READ_URL=postgresql://anlyt:anlyt@localhost:5432/ghasi_sms?schema=anlyt
NATS_URL=nats://localhost:4222
CLICKHOUSE_URL=http://localhost:8123 # optional
CLICKHOUSE_ENABLED=false
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
LOG_LEVEL=debug
3. Install + Migrate
pnpm install
pnpm --filter @ghasi/service-analytics prisma migrate dev
pnpm --filter @ghasi/service-analytics prisma db seed
pnpm --filter @ghasi/service-analytics dev
4. Seed Data
prisma/seed.ts creates:
- 7 days of synthetic
metrics_hourlyrows (3 operators, 5 accounts). - Corresponding
metrics_dailyroll-ups. operator_performancehourly rows.- NATS streams:
BILLING_EVENTS,SMS_DLRwith durable consumers.
5. Smoke Tests
# Platform summary
curl http://localhost:3030/v1/internal/analytics/summary
# Operator performance
curl "http://localhost:3030/v1/internal/analytics/operators/op-dev-001/performance?from=2026-04-11T00:00:00Z&to=2026-04-18T23:59:59Z"
# Publish synthetic billing event
nats pub billing.events '{"schemaVersion":"1","eventId":"test-001","messageId":"msg-001","accountId":"acct-001","tenantId":"t-001","operatorId":"op-dev-001","segmentCount":1,"costPerSegment":"0.006500","totalCost":"0.006500","currency":"USD","status":"BILLED","billedAt":"2026-04-18T10:00:00Z"}'
6. Common Commands
pnpm lint
pnpm typecheck
pnpm test # unit
pnpm test:int # testcontainers
pnpm --filter @ghasi/service-analytics run rollup:daily # trigger rollup manually