# d-exponent/guard architecture

> Architecture diagram of the GitHub repository d-exponent/guard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/d-exponent/guard
- Repository: https://github.com/d-exponent/guard

## Overview

NCA is a Go modular-monolith backend for location-aware community alerts. The main user flow is a client calling the versioned REST API: identity authenticates the request, then group coverage and alert workflows support creating alerts and escalating them through background jobs; authenticated members receive realtime delivery. Billing and operational metrics are distinct capabilities. The graph follows documented process wiring and sampled handler calls; unsampled service internals are represented at their listed paths, without asserting unverified calls between them.

Main entry points: [`cmd/api/app/app.go`](https://github.com/d-exponent/guard/blob/main/cmd/api/app/app.go) (API Composition), [`internal/modules/billing/handler.go`](https://github.com/d-exponent/guard/blob/main/internal/modules/billing/handler.go) (Billing Endpoints), [`cmd/realtime/app/app.go`](https://github.com/d-exponent/guard/blob/main/cmd/realtime/app/app.go) (Realtime Composition), [`internal/modules/alerts`](https://github.com/d-exponent/guard/tree/main/internal/modules/alerts) (Alert Workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["REST API"]
  node_api_app["API Composition<br/>[app.go]"]
  node_api_routes["Versioned Routes<br/>[v1.go]"]
end

subgraph group_domain["Community Domains"]
  node_identity["Identity and Sessions"]
  node_identity_auth["Auth Endpoints<br/>[handler_auth.go]"]
  node_groups["Groups and Coverage"]
  node_groups_handler["Group Endpoints<br/>[handler.go]"]
  node_alerts["Alert Workflows"]
  node_alerts_handler["Alert Endpoints<br/>[handler.go]"]
  node_billing["Plans and Purchases"]
  node_billing_handler["Billing Endpoints<br/>[handler.go]"]
  node_domain_models["Domain Types<br/>[enums.go]"]
end

subgraph group_async["Async Delivery"]
  node_worker_bootstrap["Worker Bootstrap<br/>[app.go]"]
  node_alert_worker["Escalation Worker<br/>[jobs.go]"]
  node_jobs["River Job Queue<br/>[client.go]"]
end

subgraph group_realtime["Realtime Service"]
  node_realtime_app["Realtime Composition<br/>[app.go]"]
  node_realtime_service["Realtime Access<br/>[svc.go]"]
  node_realtime_platform["WebSocket Node<br/>[node.go]"]
end

subgraph group_platform["Platform Infrastructure"]
  node_postgres[("PostgreSQL and PostGIS<br/>[pool.go]")]
  node_redis[("Redis Client<br/>[client.go]")]
  node_sms["SMS Delivery<br/>[sms.go]"]
  node_metrics["Prometheus Metrics<br/>[metrics.go]"]
end

node_client(("API Client"))
node_paystack["Paystack"]
node_member(("Community Member"))

node_client -->|"sends requests"| node_api_app
node_api_app -->|"mounts routes"| node_api_routes
node_api_app -->|"wires handler"| node_identity_auth
node_api_app -->|"wires handler"| node_groups_handler
node_api_app -->|"wires handler"| node_alerts_handler
node_api_app -->|"wires handler"| node_billing_handler
node_identity_auth -->|"calls service"| node_identity
node_groups_handler -.->|"serves requests"| node_groups
node_alerts_handler -->|"serves requests"| node_alerts
node_billing_handler -->|"calls service"| node_billing
node_billing_handler -->|"accepts webhooks"| node_paystack
node_alerts -->|"queues escalation"| node_jobs
node_worker_bootstrap -->|"registers worker"| node_alert_worker
node_worker_bootstrap -->|"creates client"| node_jobs
node_member -->|"opens socket"| node_realtime_app
node_realtime_app -->|"configures access"| node_realtime_service
node_realtime_app -->|"starts node"| node_realtime_platform
node_api_app -->|"builds repositories"| node_postgres
node_api_app -->|"builds cache"| node_redis
node_api_app -->|"builds sender"| node_sms
node_api_app -->|"instruments routes"| node_metrics
node_api_app -->|"creates broker node"| node_realtime_platform
node_domain_models -.->|"models domain"| node_alerts

click node_api_app "https://github.com/d-exponent/guard/blob/main/cmd/api/app/app.go"
click node_api_routes "https://github.com/d-exponent/guard/blob/main/cmd/api/routes/v1.go"
click node_identity "https://github.com/d-exponent/guard/tree/main/internal/modules/identity"
click node_identity_auth "https://github.com/d-exponent/guard/blob/main/internal/modules/identity/handler_auth.go"
click node_groups "https://github.com/d-exponent/guard/tree/main/internal/modules/groups"
click node_groups_handler "https://github.com/d-exponent/guard/blob/main/internal/modules/groups/handler.go"
click node_alerts "https://github.com/d-exponent/guard/tree/main/internal/modules/alerts"
click node_alerts_handler "https://github.com/d-exponent/guard/blob/main/internal/modules/alerts/handler.go"
click node_billing "https://github.com/d-exponent/guard/tree/main/internal/modules/billing"
click node_billing_handler "https://github.com/d-exponent/guard/blob/main/internal/modules/billing/handler.go"
click node_domain_models "https://github.com/d-exponent/guard/blob/main/internal/kernel/models/enums.go"
click node_worker_bootstrap "https://github.com/d-exponent/guard/blob/main/cmd/workers/bootstrap/app.go"
click node_alert_worker "https://github.com/d-exponent/guard/blob/main/internal/modules/alerts/jobs.go"
click node_jobs "https://github.com/d-exponent/guard/blob/main/internal/platform/jobs/client.go"
click node_realtime_app "https://github.com/d-exponent/guard/blob/main/cmd/realtime/app/app.go"
click node_realtime_service "https://github.com/d-exponent/guard/blob/main/internal/modules/realtime/svc.go"
click node_realtime_platform "https://github.com/d-exponent/guard/blob/main/internal/platform/realtime/node.go"
click node_postgres "https://github.com/d-exponent/guard/blob/main/internal/platform/postgres/pool.go"
click node_redis "https://github.com/d-exponent/guard/blob/main/internal/platform/redis/client.go"
click node_sms "https://github.com/d-exponent/guard/blob/main/internal/platform/messaging/sms.go"
click node_metrics "https://github.com/d-exponent/guard/blob/main/internal/platform/metrics/metrics.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_app,node_api_routes,node_client toneBlue
class node_identity,node_identity_auth,node_groups,node_groups_handler,node_alerts,node_alerts_handler,node_billing,node_billing_handler,node_domain_models toneAmber
class node_worker_bootstrap,node_alert_worker,node_jobs toneMint
class node_realtime_app,node_realtime_service,node_realtime_platform toneRose
class node_postgres,node_redis,node_sms,node_metrics,node_paystack,node_member toneIndigo
```

## Components

### REST API

- [API Composition](https://github.com/d-exponent/guard/blob/main/cmd/api/app/app.go): `cmd/api/app/app.go`
- [Versioned Routes](https://github.com/d-exponent/guard/blob/main/cmd/api/routes/v1.go): `cmd/api/routes/v1.go`

### Community Domains

- [Identity and Sessions](https://github.com/d-exponent/guard/tree/main/internal/modules/identity): `internal/modules/identity`
- [Auth Endpoints](https://github.com/d-exponent/guard/blob/main/internal/modules/identity/handler_auth.go): `internal/modules/identity/handler_auth.go`
- [Groups and Coverage](https://github.com/d-exponent/guard/tree/main/internal/modules/groups): `internal/modules/groups`
- [Group Endpoints](https://github.com/d-exponent/guard/blob/main/internal/modules/groups/handler.go): `internal/modules/groups/handler.go`
- [Alert Workflows](https://github.com/d-exponent/guard/tree/main/internal/modules/alerts): `internal/modules/alerts`
- [Alert Endpoints](https://github.com/d-exponent/guard/blob/main/internal/modules/alerts/handler.go): `internal/modules/alerts/handler.go`
- [Plans and Purchases](https://github.com/d-exponent/guard/tree/main/internal/modules/billing): `internal/modules/billing`
- [Billing Endpoints](https://github.com/d-exponent/guard/blob/main/internal/modules/billing/handler.go): `internal/modules/billing/handler.go`
- [Domain Types](https://github.com/d-exponent/guard/blob/main/internal/kernel/models/enums.go): `internal/kernel/models/enums.go`

### Async Delivery

- [Worker Bootstrap](https://github.com/d-exponent/guard/blob/main/cmd/workers/bootstrap/app.go): `cmd/workers/bootstrap/app.go`
- [Escalation Worker](https://github.com/d-exponent/guard/blob/main/internal/modules/alerts/jobs.go): `internal/modules/alerts/jobs.go`
- [River Job Queue](https://github.com/d-exponent/guard/blob/main/internal/platform/jobs/client.go): `internal/platform/jobs/client.go`

### Realtime Service

- [Realtime Composition](https://github.com/d-exponent/guard/blob/main/cmd/realtime/app/app.go): `cmd/realtime/app/app.go`
- [Realtime Access](https://github.com/d-exponent/guard/blob/main/internal/modules/realtime/svc.go): `internal/modules/realtime/svc.go`
- [WebSocket Node](https://github.com/d-exponent/guard/blob/main/internal/platform/realtime/node.go): `internal/platform/realtime/node.go`

### Platform Infrastructure

- [PostgreSQL and PostGIS](https://github.com/d-exponent/guard/blob/main/internal/platform/postgres/pool.go): `internal/platform/postgres/pool.go`
- [Redis Client](https://github.com/d-exponent/guard/blob/main/internal/platform/redis/client.go): `internal/platform/redis/client.go`
- [SMS Delivery](https://github.com/d-exponent/guard/blob/main/internal/platform/messaging/sms.go): `internal/platform/messaging/sms.go`
- [Prometheus Metrics](https://github.com/d-exponent/guard/blob/main/internal/platform/metrics/metrics.go): `internal/platform/metrics/metrics.go`

### Other components

- **API Client**
- **Paystack**
- **Community Member**

## Connections

- API Client → API Composition: sends requests
- API Composition → Versioned Routes: mounts routes (evidence: `cmd/api/app/app.go`)
- API Composition → Auth Endpoints: wires handler (evidence: `cmd/api/app/app.go`)
- API Composition → Group Endpoints: wires handler (evidence: `cmd/api/app/app.go`)
- API Composition → Alert Endpoints: wires handler (evidence: `cmd/api/app/app.go`)
- API Composition → Billing Endpoints: wires handler (evidence: `cmd/api/app/app.go`)
- Auth Endpoints → Identity and Sessions: calls service (evidence: `internal/modules/identity/handler_auth.go`)
- Group Endpoints → Groups and Coverage: serves requests
- Alert Endpoints → Alert Workflows: serves requests
- Billing Endpoints → Plans and Purchases: calls service (evidence: `internal/modules/billing/handler.go`)
- Billing Endpoints → Paystack: accepts webhooks (evidence: `internal/modules/billing/handler.go`)
- Alert Workflows → River Job Queue: queues escalation
- Worker Bootstrap → Escalation Worker: registers worker (evidence: `cmd/workers/bootstrap/app.go`)
- Worker Bootstrap → River Job Queue: creates client (evidence: `cmd/workers/bootstrap/app.go`)
- Community Member → Realtime Composition: opens socket
- Realtime Composition → Realtime Access: configures access (evidence: `cmd/realtime/app/app.go`)
- Realtime Composition → WebSocket Node: starts node (evidence: `cmd/realtime/app/app.go`)
- API Composition → PostgreSQL and PostGIS: builds repositories (evidence: `cmd/api/app/app.go`)
- API Composition → Redis Client: builds cache (evidence: `cmd/api/app/app.go`)
- API Composition → SMS Delivery: builds sender (evidence: `cmd/api/app/app.go`)
- API Composition → Prometheus Metrics: instruments routes (evidence: `cmd/api/app/app.go`)
- API Composition → WebSocket Node: creates broker node (evidence: `cmd/api/app/app.go`)
- Domain Types → Alert Workflows: models domain
