# esca6585dev/habarchy architecture

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

- Interactive diagram: https://gitdiagram.com/esca6585dev/habarchy
- Repository: https://github.com/esca6585dev/habarchy

## Overview

Habarchy is a self-hosted, multi-tenant notification gateway. Clients submit messages through public APIs; the backend validates and queues them, workers deliver through configured providers with retries and fallback, and status/webhook events report outcomes. The repository also includes tenant administration, contact and group management, imports, OTP, team chat, a web admin panel, and an Android SIM gateway. The graph combines sampled wiring with README-documented capabilities; unsampled details are represented only where documentation supports them.

Main entry points: [`backend/cmd/api/main.go`](https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/api/main.go) (HTTP API), [`backend/internal/app/delivery/service.go`](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/delivery/service.go) (Delivery and fallback), [`gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt`](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt) (Gateway service), [`backend/internal/app/messages/service.go`](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/messages/service.go) (Message intake)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API"]
  node_api["HTTP API<br/>[main.go]"]
  node_message_service["Message intake<br/>[service.go]"]
  node_postgres[("PostgreSQL<br/>[postgres.go]")]
  node_scheduler["Maintenance scheduler<br/>[main.go]"]
end

subgraph group_delivery["Delivery Runtime"]
  node_provider_service["Provider setup<br/>[service.go]"]
  node_queue["Job queue<br/>[client.go]"]
  node_worker["Delivery worker<br/>[main.go]"]
  node_delivery_service["Delivery and fallback<br/>[service.go]"]
  node_provider_adapters["Channel adapters"]
  node_webhooks["Webhooks<br/>[service.go]"]
  node_redis[("Redis<br/>[redis.go]")]
end

subgraph group_admin["Administration"]
  node_project_service["Projects and keys<br/>[service.go]"]
  node_auth_service["Admin auth<br/>[service.go]"]
  node_contacts_service["Contacts and groups<br/>[service.go]"]
  node_chat_service["Team chat<br/>[service.go]"]
end

subgraph group_gateway["SIM Gateway"]
  node_gateway_api["Gateway API client<br/>[Api.kt]"]
  node_gateway_service["Gateway service<br/>[GatewayService.kt]"]
  node_gateway_store[("Gateway state<br/>[GatewayStore.kt]")]
  node_inbound_control["Inbound SMS control<br/>[InboundControl.kt]"]
  node_sms_sender["SIM SMS sender<br/>[SmsSender.kt]"]
  node_gateway_reporter["Gateway reports<br/>[Reporter.kt]"]
end

subgraph group_clients["Client Interfaces"]
  node_web_admin["Web admin<br/>[page.tsx]"]
  node_php_sdk["PHP SDK<br/>[Client.php]"]
end

node_api_client(("API clients"))
node_mobile_phone(("Android phone and SIM"))
node_notification_providers(("External channels"))
node_message_recipients(("Message recipients"))

node_api_client -->|"sends requests"| node_api
node_php_sdk -->|"calls public API"| node_api
node_web_admin -->|"uses backend"| node_api
node_api -->|"routes sends"| node_message_service
node_api -->|"registers handlers"| node_project_service
node_api -->|"registers handlers"| node_auth_service
node_api -->|"registers handlers"| node_contacts_service
node_message_service -->|"resolves recipients"| node_contacts_service
node_message_service -->|"persists messages"| node_postgres
node_message_service -.->|"enqueues sends"| node_queue
node_worker -->|"handles tasks"| node_delivery_service
node_worker -->|"consumes jobs"| node_queue
node_delivery_service -->|"selects adapters"| node_provider_service
node_delivery_service -->|"uses contacts"| node_contacts_service
node_delivery_service -->|"records outcomes"| node_postgres
node_delivery_service -->|"publishes events"| node_redis
node_delivery_service -->|"emits callbacks"| node_webhooks
node_delivery_service -->|"sends messages"| node_provider_adapters
node_provider_adapters -->|"delivers externally"| node_notification_providers
node_message_recipients -.->|"receive notifications"| node_notification_providers
node_scheduler -->|"runs maintenance"| node_postgres
node_gateway_service -->|"polls and reports"| node_gateway_api
node_gateway_service -->|"reads state"| node_gateway_store
node_gateway_service -->|"sends SMS"| node_sms_sender
node_gateway_service -->|"checks forwarding"| node_inbound_control
node_inbound_control -->|"reads settings"| node_gateway_store
node_inbound_control -->|"forwards inbound"| node_gateway_reporter
node_sms_sender -->|"uses SIM radio"| node_mobile_phone
node_gateway_reporter -->|"posts reports"| node_gateway_api
node_gateway_api -->|"calls gateway endpoints"| node_api
node_api -.->|"queues SIM delivery"| node_gateway_service
node_api -->|"registers chat handlers"| node_chat_service
node_provider_service -->|"stores configuration"| node_postgres

click node_api "https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/api/main.go"
click node_message_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/messages/service.go"
click node_project_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/projects/service.go"
click node_auth_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/auth/service.go"
click node_contacts_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/contacts/service.go"
click node_chat_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/chat/service.go"
click node_provider_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/providers/service.go"
click node_queue "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/queue/client.go"
click node_worker "https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/worker/main.go"
click node_delivery_service "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/delivery/service.go"
click node_provider_adapters "https://github.com/esca6585dev/habarchy/tree/main/backend/internal/adapters/providers"
click node_webhooks "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/webhooks/service.go"
click node_postgres "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/adapters/postgres/postgres.go"
click node_redis "https://github.com/esca6585dev/habarchy/blob/main/backend/internal/adapters/redis/redis.go"
click node_scheduler "https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/scheduler/main.go"
click node_web_admin "https://github.com/esca6585dev/habarchy/blob/main/web/src/app/(dashboard)/page.tsx"
click node_php_sdk "https://github.com/esca6585dev/habarchy/blob/main/sdk/php/src/Client.php"
click node_gateway_api "https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Api.kt"
click node_gateway_service "https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt"
click node_gateway_store "https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayStore.kt"
click node_inbound_control "https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/InboundControl.kt"
click node_sms_sender "https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/SmsSender.kt"
click node_gateway_reporter "https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Reporter.kt"

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,node_message_service,node_postgres,node_scheduler,node_api_client toneBlue
class node_provider_service,node_queue,node_worker,node_delivery_service,node_provider_adapters,node_webhooks,node_redis toneAmber
class node_project_service,node_auth_service,node_contacts_service,node_chat_service toneMint
class node_gateway_api,node_gateway_service,node_gateway_store,node_inbound_control,node_sms_sender,node_gateway_reporter toneRose
class node_web_admin,node_php_sdk,node_mobile_phone,node_notification_providers,node_message_recipients toneIndigo
```

## Components

### Backend API

- [HTTP API](https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/api/main.go): `backend/cmd/api/main.go`
- [Message intake](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/messages/service.go): `backend/internal/app/messages/service.go`
- [PostgreSQL](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/adapters/postgres/postgres.go): `backend/internal/adapters/postgres/postgres.go`
- [Maintenance scheduler](https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/scheduler/main.go): `backend/cmd/scheduler/main.go`

### Delivery Runtime

- [Provider setup](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/providers/service.go): `backend/internal/app/providers/service.go`
- [Job queue](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/queue/client.go): `backend/internal/queue/client.go`
- [Delivery worker](https://github.com/esca6585dev/habarchy/blob/main/backend/cmd/worker/main.go): `backend/cmd/worker/main.go`
- [Delivery and fallback](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/delivery/service.go): `backend/internal/app/delivery/service.go`
- [Channel adapters](https://github.com/esca6585dev/habarchy/tree/main/backend/internal/adapters/providers): `backend/internal/adapters/providers`
- [Webhooks](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/webhooks/service.go): `backend/internal/app/webhooks/service.go`
- [Redis](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/adapters/redis/redis.go): `backend/internal/adapters/redis/redis.go`

### Administration

- [Projects and keys](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/projects/service.go): `backend/internal/app/projects/service.go`
- [Admin auth](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/auth/service.go): `backend/internal/app/auth/service.go`
- [Contacts and groups](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/contacts/service.go): `backend/internal/app/contacts/service.go`
- [Team chat](https://github.com/esca6585dev/habarchy/blob/main/backend/internal/app/chat/service.go): `backend/internal/app/chat/service.go`

### SIM Gateway

- [Gateway API client](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Api.kt): `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Api.kt`
- [Gateway service](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt): `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt`
- [Gateway state](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayStore.kt): `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayStore.kt`
- [Inbound SMS control](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/InboundControl.kt): `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/InboundControl.kt`
- [SIM SMS sender](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/SmsSender.kt): `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/SmsSender.kt`
- [Gateway reports](https://github.com/esca6585dev/habarchy/blob/main/gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Reporter.kt): `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Reporter.kt`

### Client Interfaces

- [Web admin](https://github.com/esca6585dev/habarchy/blob/main/web/src/app/(dashboard)/page.tsx): `web/src/app/(dashboard)/page.tsx`
- [PHP SDK](https://github.com/esca6585dev/habarchy/blob/main/sdk/php/src/Client.php): `sdk/php/src/Client.php`

### Other components

- **API clients**
- **Android phone and SIM**
- **External channels**
- **Message recipients**

## Connections

- API clients → HTTP API: sends requests (evidence: `README.md`)
- PHP SDK → HTTP API: calls public API (evidence: `README.md`)
- Web admin → HTTP API: uses backend (evidence: `README.md`)
- HTTP API → Message intake: routes sends (evidence: `backend/cmd/api/main.go`)
- HTTP API → Projects and keys: registers handlers (evidence: `backend/cmd/api/main.go`)
- HTTP API → Admin auth: registers handlers (evidence: `backend/cmd/api/main.go`)
- HTTP API → Contacts and groups: registers handlers (evidence: `backend/cmd/api/main.go`)
- Message intake → Contacts and groups: resolves recipients (evidence: `backend/internal/app/messages/service.go`)
- Message intake → PostgreSQL: persists messages (evidence: `backend/internal/app/messages/service.go`)
- Message intake → Job queue: enqueues sends
- Delivery worker → Delivery and fallback: handles tasks (evidence: `backend/cmd/worker/main.go`)
- Delivery worker → Job queue: consumes jobs (evidence: `backend/cmd/worker/main.go`)
- Delivery and fallback → Provider setup: selects adapters (evidence: `backend/internal/app/delivery/service.go`)
- Delivery and fallback → Contacts and groups: uses contacts (evidence: `backend/internal/app/delivery/service.go`)
- Delivery and fallback → PostgreSQL: records outcomes (evidence: `backend/internal/app/delivery/service.go`)
- Delivery and fallback → Redis: publishes events (evidence: `backend/internal/app/delivery/service.go`)
- Delivery and fallback → Webhooks: emits callbacks (evidence: `backend/internal/app/delivery/service.go`)
- Delivery and fallback → Channel adapters: sends messages (evidence: `backend/internal/app/delivery/service.go`)
- Channel adapters → External channels: delivers externally (evidence: `README.md`)
- Message recipients → External channels: receive notifications
- Maintenance scheduler → PostgreSQL: runs maintenance (evidence: `backend/cmd/scheduler/main.go`)
- Gateway service → Gateway API client: polls and reports (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt`)
- Gateway service → Gateway state: reads state (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt`)
- Gateway service → SIM SMS sender: sends SMS (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt`)
- Gateway service → Inbound SMS control: checks forwarding (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/GatewayService.kt`)
- Inbound SMS control → Gateway state: reads settings (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/InboundControl.kt`)
- Inbound SMS control → Gateway reports: forwards inbound (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/InboundControl.kt`)
- SIM SMS sender → Android phone and SIM: uses SIM radio (evidence: `README.md`)
- Gateway reports → Gateway API client: posts reports (evidence: `gateway/android/app/src/main/kotlin/tm/habarchy/gateway/Reporter.kt`)
- Gateway API client → HTTP API: calls gateway endpoints (evidence: `README.md`)
- HTTP API → Gateway service: queues SIM delivery
- HTTP API → Team chat: registers chat handlers (evidence: `backend/cmd/api/main.go`)
- Provider setup → PostgreSQL: stores configuration (evidence: `backend/internal/app/providers/service.go`)
