Skip to main content

Document Service — Deployment Topology

Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template · 17 technology-stack


1. Runtime​

PropertyValue
RuntimeNode.js 22 LTS
FrameworkNestJS 11
LanguageTypeScript 5.x
Package@ghasi/service-document
Port3020
Container basenode:22-alpine

2. Replicas and Scaling​

EnvironmentMin replicasMax replicasScaling trigger
Production (API + render workers)2 API + 2 workers8 API + 10 workersCPU > 60 % or render job queue > 100
Staging1 API + 1 worker3 API + 3 workers—
Dev/local1 combined1—

API instances (request handling) and render workers (async PDF generation) are separate deployment units that share the same codebase but start with different profiles.


3. Infrastructure Dependencies​

DependencyTypeNotes
PostgreSQL 16Primary storeSchema document_svc; RLS enforced
Object Storage (S3 / MinIO)Binary storageTenant-scoped paths; AES-256 at rest
ClamAVVirus scannerSidecar container or dedicated service
NATS JetStreamMessage busStreams: doc-template-events, doc-render-events, doc-artifact-events, doc-security-events
interop-service / FHIR gatewayHTTPFHIR binding resolution + DocumentReference creation
config-serviceHTTPTenant branding tokens for PDF rendering
KongAPI GatewayRoutes /v1/document* with JWT auth
KeycloakIdentityJWT issuer
OpenTelemetry CollectorTelemetryOTLP → Grafana / Tempo

4. Object Storage Configuration​

Deployment typeObject storageEncryption
Cloud (AWS)Amazon S3SSE-KMS per-tenant key
On-premisesMinIOSSE with platform-managed key
DevelopmentMinIO (docker compose)Default MinIO encryption

Bucket naming: ghasi-documents-{region}-{env} (cloud) or documents (on-prem MinIO).


5. ClamAV Integration​

ClamAV runs as a sidecar container (clamav:latest) or as a dedicated service. The document-service calls ClamAV via the clamd TCP protocol (port 3310). Virus definition updates are scheduled daily.


6. Regions​

RegionRoleNotes
Primary (Afghanistan MoPH)ActiveAll write traffic; primary DB; primary object storage
Secondary (DR)StandbyDB read replica; object storage replication; NATS replication

Clinical documents are subject to Afghanistan MoPH data residency requirements. No document data leaves the designated region without explicit tenant policy.


7. Health Checks​

EndpointChecks
GET /health/liveProcess alive
GET /health/readyPostgreSQL OK; object storage reachable; ClamAV connected; NATS connected

8. Resource Limits (Production)​

PodCPU RequestCPU LimitMemory RequestMemory Limit
API pod250 m1000 m256 Mi512 Mi
Render worker500 m2000 m512 Mi1 Gi

Render workers are memory-intensive due to PDF generation (Puppeteer/PDFLib). Workers auto-scale independently of API pods.


9. Deployment Diagram​