Architecture
Counslr SOS is an emergency PSAP routing platform that enables telehealth counselors to dispatch 911 to a patient’s location during a crisis. The system prioritizes low-latency response, HIPAA compliance through minimal data persistence, and multi-tenant isolation.
System Overview
┌────────────────────────────┐
│ AWS VPC │
┌─────────────┐ ┌──────────────┐ │ ┌──────────────────────┐ │
│ Patient SDK │────▶│ │ │ │ Lambda (Go) │ │
│ (Browser) │◀────│ API Gateway │────▶│ │ - Session mgmt │ │
└─────────────┘ │ (REST + │ │ │ - SOS handling │ │
│ WebSocket) │ │ │ - PSAP lookup │ │
┌─────────────┐ │ │ │ └───────────┬──────────┘ │
│ Counselor │────▶│ │ │ │ │
│ SDK │◀────└──────────────┘ │ ┌───────────▼──────────┐ │
│ (Browser) │ │ │ Aurora Serverless │ │
└─────────────┘ │ │ v2 + PostGIS │ │
│ └───────────┬──────────┘ │
└──────────────┼─────────────┘
│
┌──────────────▼─────────────┐
│ TrueVault (HIPAA) │
│ Crisis event logs │
└────────────────────────────┘
Clean Architecture
The codebase follows Clean Architecture with four layers. Dependencies point inward — the domain layer has zero external imports.
┌─────────────────────────────────────────────────┐
│ cmd/api, cmd/ws, cmd/migrate, cmd/import │ Entrypoints
├─────────────────────────────────────────────────┤
│ internal/api (HTTP handlers) │ Adapters (outer)
│ internal/storage (Postgres, DynamoDB, │
│ API Gateway, TrueVault) │
├─────────────────────────────────────────────────┤
│ internal/service (Use cases, interfaces) │ Application
├─────────────────────────────────────────────────┤
│ internal/domain (Entities, value objects) │ Domain (inner)
└─────────────────────────────────────────────────┘
Repository interfaces are defined in internal/service/ (consumer side) and implemented in internal/storage/ (provider side).
SOS Data Flow
- Counselor triggers SOS →
POST /v1/platforms/{platformId}/sessions/{sessionId}/sos(counselor JWT required) - Session transitions to
sosstate → Aurora (session state update) - SOS event created → TrueVault (HIPAA-compliant)
- Audit entry recorded → Aurora (tamper-evident hash chain)
- Location request pushed → WebSocket
location_requestto patient - Patient submits location →
POST /v1/platforms/{platformId}/sessions/{sessionId}/sos/location(patient JWT required) - PSAP lookup → PostGIS nearest-neighbor query (location in-memory only)
- PSAP contacts returned → REST response + WebSocket push to counselor
- Location discarded → Never written to any database
Key Components
| Component | Technology | Purpose |
|---|---|---|
| Backend | Go on AWS Lambda (ARM64) | Sub-100ms cold starts for life-safety SOS, provisioned concurrency on WebSocket Lambda (staging/prod) |
| Database | Aurora Serverless v2 + PostGIS | Spatial queries for PSAP lookup |
| Crisis logs | TrueVault | HIPAA-compliant storage with BAA |
| Real-time | WebSocket API Gateway | Push-based location request during SOS |
| Multi-tenancy | Stripe-like API key model | Publishable/secret + live/test keys |
| Patient SDK | TypeScript, zero-dependency | Geolocation, WebSocket, location submission |
| Counselor SDK | TypeScript, zero-dependency | Session management, SOS triggering |
| Audit trail | HMAC-SHA256 hash chain | Tamper-evident crisis event logging |
| Infrastructure | AWS CDK (Go) | Type-safe IaC in the same language as backend |
HIPAA Compliance
Patient location is the most sensitive data in the system. The on-demand capture model ensures location is never at rest:
- Patient grants geolocation permission at session start
- SDK holds permission but does not transmit until SOS
- During SOS, coordinates are held in Lambda process memory only
- After PSAP lookup, location goes out of scope
- Crisis logs record the event (who, when, which PSAP) but never the coordinates
See Security & HIPAA for the complete data classification and compliance model.