# toinbox/simplerelay architecture

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

- Interactive diagram: https://gitdiagram.com/toinbox/simplerelay
- Repository: https://github.com/toinbox/simplerelay

## Overview

SimpleRelay is a self-hosted, multi-tenant SMTP relay with a React dashboard and FastAPI control plane. Users register and verify accounts, configure upstream providers and allowed clients, then send mail through Postfix, which routes by sender to an upstream SMTP account; the dashboard exposes logs and health. Admins manage users, proxies, provider-type limits, and relay status. The graph combines sampled call/import evidence with README-documented runtime behavior; unsampled subsystem links are omitted where their callers could not be confirmed.

Main entry points: [`frontend/src/App.jsx`](https://github.com/toinbox/simplerelay/blob/main/frontend/src/App.jsx) (Dashboard app and routes), [`frontend/src/api.js`](https://github.com/toinbox/simplerelay/blob/main/frontend/src/api.js) (Authenticated API client), [`backend/database.py`](https://github.com/toinbox/simplerelay/blob/main/backend/database.py) (Database access and initialization), [`backend/routers/providers.py`](https://github.com/toinbox/simplerelay/blob/main/backend/routers/providers.py) (Provider management API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web dashboard"]
  node_app["Dashboard app and routes<br/>[App.jsx]"]
  node_api_client["Authenticated API client<br/>[api.js]"]
  node_provider_ui["Provider management<br/>[Providers.jsx]"]
  node_wizard_ui["Setup wizard<br/>[Wizard.jsx]"]
  node_dashboard_ui["User dashboard<br/>[Dashboard.jsx]"]
  node_logs_ui["Mail logs<br/>[Logs.jsx]"]
  node_clients_ui["Access control UI<br/>[Clients.jsx]"]
  node_admin_users_ui["User administration<br/>[AdminUsers.jsx]"]
  node_admin_proxies_ui["Proxy administration<br/>[AdminProxies.jsx]"]
  node_admin_limits_ui["Provider limits UI<br/>[AdminLimits.jsx]"]
  node_admin_logs_ui["Admin mail logs<br/>[AdminLogs.jsx]"]
end

subgraph group_api["API and account management"]
  node_auth_routes["Registration and authentication<br/>[auth.py]"]
  node_provider_routes["Provider management API<br/>[providers.py]"]
  node_client_routes["Allowed-client API<br/>[clients.py]"]
  node_admin_routes["Admin API<br/>[admin.py]"]
  node_dashboard_routes["Dashboard data API<br/>[dashboard.py]"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_auth_service["JWT and password auth<br/>[auth.py]"]
  node_email_service["Verification email delivery<br/>[email_sender.py]"]
  node_presets["Provider detection and presets"]
  node_dns["DNS validation<br/>[dns_checker.py]"]
  node_crypto["Credential encryption<br/>[crypto.py]"]
end

subgraph group_relay["SMTP relay"]
  node_postfix["Postfix configuration<br/>[postfix_config.py]"]
  node_access["Relay access policy<br/>[access_server.py]"]
end

subgraph group_state["Persistence and monitoring"]
  node_postgres[("PostgreSQL")]
  node_models["Relay domain models<br/>[models.py]"]
  node_database["Database access and initialization<br/>[database.py]"]
  node_mail_logs["Mail log service<br/>[mail_logger.py]"]
  node_health["Provider health checks<br/>[health_checker.py]"]
  node_expiry["Relay expiry checks<br/>[expiry_checker.py]"]
end

node_user(("Relay user"))
node_admin_actor(("Administrator"))
node_mail_client(("Sending application"))
node_upstream{{"Upstream SMTP"}}

node_user -->|"uses dashboard"| node_app
node_admin_actor -->|"uses admin panel"| node_app
node_app -->|"routes to"| node_provider_ui
node_app -->|"routes to"| node_wizard_ui
node_app -->|"routes to"| node_dashboard_ui
node_app -->|"routes to"| node_logs_ui
node_app -->|"routes to"| node_clients_ui
node_app -->|"routes to"| node_admin_users_ui
node_app -->|"routes to"| node_admin_proxies_ui
node_app -->|"routes to"| node_admin_limits_ui
node_app -->|"routes to"| node_admin_logs_ui
node_provider_ui -->|"calls"| node_api_client
node_wizard_ui -->|"calls"| node_api_client
node_dashboard_ui -->|"calls"| node_api_client
node_logs_ui -->|"calls"| node_api_client
node_clients_ui -->|"calls"| node_api_client
node_admin_users_ui -->|"calls"| node_api_client
node_admin_proxies_ui -->|"calls"| node_api_client
node_admin_limits_ui -->|"calls"| node_api_client
node_admin_logs_ui -->|"calls"| node_api_client
node_api_client -->|"sends API requests"| node_fastapi
node_fastapi -->|"initializes"| node_database
node_fastapi -->|"registers routes"| node_auth_routes
node_fastapi -->|"registers routes"| node_provider_routes
node_fastapi -->|"registers routes"| node_client_routes
node_fastapi -->|"registers routes"| node_dashboard_routes
node_fastapi -->|"registers routes"| node_admin_routes
node_auth_routes -->|"authenticates users"| node_auth_service
node_auth_routes -->|"sends verification mail"| node_email_service
node_provider_routes -->|"uses provider presets"| node_presets
node_provider_routes -->|"validates DNS"| node_dns
node_provider_routes -->|"encrypts credentials"| node_crypto
node_provider_routes -->|"updates relay config"| node_postfix
node_client_routes -->|"reloads policy config"| node_postfix
node_admin_routes -->|"tests encrypted credentials"| node_crypto
node_database -->|"creates model tables"| node_models
node_database -->|"stores records"| node_postgres
node_auth_service -->|"queries users"| node_database
node_provider_routes -->|"reads and writes providers"| node_database
node_client_routes -->|"reads and writes clients"| node_database
node_admin_routes -->|"manages admin data"| node_database
node_dashboard_routes -->|"queries dashboard data"| node_database
node_user -->|"configures relay"| node_mail_client
node_mail_client -->|"submits SMTP mail"| node_postfix
node_postfix -->|"routes by sender"| node_upstream
node_postfix -->|"checks relay access"| node_access
node_access -->|"checks allowed clients"| node_database
node_provider_routes -->|"requests health checks"| node_health

click node_app "https://github.com/toinbox/simplerelay/blob/main/frontend/src/App.jsx"
click node_api_client "https://github.com/toinbox/simplerelay/blob/main/frontend/src/api.js"
click node_provider_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Providers.jsx"
click node_wizard_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Wizard.jsx"
click node_dashboard_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Dashboard.jsx"
click node_logs_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Logs.jsx"
click node_clients_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Clients.jsx"
click node_admin_users_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminUsers.jsx"
click node_admin_proxies_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminProxies.jsx"
click node_admin_limits_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminLimits.jsx"
click node_admin_logs_ui "https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminLogs.jsx"
click node_auth_routes "https://github.com/toinbox/simplerelay/blob/main/backend/routers/auth.py"
click node_provider_routes "https://github.com/toinbox/simplerelay/blob/main/backend/routers/providers.py"
click node_client_routes "https://github.com/toinbox/simplerelay/blob/main/backend/routers/clients.py"
click node_admin_routes "https://github.com/toinbox/simplerelay/blob/main/backend/routers/admin.py"
click node_dashboard_routes "https://github.com/toinbox/simplerelay/blob/main/backend/routers/dashboard.py"
click node_fastapi "https://github.com/toinbox/simplerelay/blob/main/backend/main.py"
click node_auth_service "https://github.com/toinbox/simplerelay/blob/main/backend/services/auth.py"
click node_email_service "https://github.com/toinbox/simplerelay/blob/main/backend/services/email_sender.py"
click node_presets "https://github.com/toinbox/simplerelay/blob/main/backend/services/provider_presets.py"
click node_dns "https://github.com/toinbox/simplerelay/blob/main/backend/services/dns_checker.py"
click node_crypto "https://github.com/toinbox/simplerelay/blob/main/backend/services/crypto.py"
click node_models "https://github.com/toinbox/simplerelay/blob/main/backend/models.py"
click node_database "https://github.com/toinbox/simplerelay/blob/main/backend/database.py"
click node_mail_logs "https://github.com/toinbox/simplerelay/blob/main/backend/services/mail_logger.py"
click node_health "https://github.com/toinbox/simplerelay/blob/main/backend/services/health_checker.py"
click node_expiry "https://github.com/toinbox/simplerelay/blob/main/backend/services/expiry_checker.py"
click node_postfix "https://github.com/toinbox/simplerelay/blob/main/backend/services/postfix_config.py"
click node_access "https://github.com/toinbox/simplerelay/blob/main/backend/services/access_server.py"

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_app,node_api_client,node_provider_ui,node_wizard_ui,node_dashboard_ui,node_logs_ui,node_clients_ui,node_admin_users_ui,node_admin_proxies_ui,node_admin_limits_ui,node_admin_logs_ui,node_user toneBlue
class node_auth_routes,node_provider_routes,node_client_routes,node_admin_routes,node_dashboard_routes,node_fastapi,node_auth_service,node_email_service,node_presets,node_dns,node_crypto toneAmber
class node_postfix,node_access toneMint
class node_postgres,node_models,node_database,node_mail_logs,node_health,node_expiry toneRose
class node_admin_actor,node_mail_client,node_upstream toneIndigo
```

## Components

### Web dashboard

- [Dashboard app and routes](https://github.com/toinbox/simplerelay/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Authenticated API client](https://github.com/toinbox/simplerelay/blob/main/frontend/src/api.js): `frontend/src/api.js`
- [Provider management](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Providers.jsx): `frontend/src/pages/Providers.jsx`
- [Setup wizard](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Wizard.jsx): `frontend/src/pages/Wizard.jsx`
- [User dashboard](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Mail logs](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Logs.jsx): `frontend/src/pages/Logs.jsx`
- [Access control UI](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/Clients.jsx): `frontend/src/pages/Clients.jsx`
- [User administration](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminUsers.jsx): `frontend/src/pages/AdminUsers.jsx`
- [Proxy administration](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminProxies.jsx): `frontend/src/pages/AdminProxies.jsx`
- [Provider limits UI](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminLimits.jsx): `frontend/src/pages/AdminLimits.jsx`
- [Admin mail logs](https://github.com/toinbox/simplerelay/blob/main/frontend/src/pages/AdminLogs.jsx): `frontend/src/pages/AdminLogs.jsx`

### API and account management

- [Registration and authentication](https://github.com/toinbox/simplerelay/blob/main/backend/routers/auth.py): `backend/routers/auth.py`
- [Provider management API](https://github.com/toinbox/simplerelay/blob/main/backend/routers/providers.py): `backend/routers/providers.py`
- [Allowed-client API](https://github.com/toinbox/simplerelay/blob/main/backend/routers/clients.py): `backend/routers/clients.py`
- [Admin API](https://github.com/toinbox/simplerelay/blob/main/backend/routers/admin.py): `backend/routers/admin.py`
- [Dashboard data API](https://github.com/toinbox/simplerelay/blob/main/backend/routers/dashboard.py): `backend/routers/dashboard.py`
- [FastAPI application](https://github.com/toinbox/simplerelay/blob/main/backend/main.py): `backend/main.py`
- [JWT and password auth](https://github.com/toinbox/simplerelay/blob/main/backend/services/auth.py): `backend/services/auth.py`
- [Verification email delivery](https://github.com/toinbox/simplerelay/blob/main/backend/services/email_sender.py): `backend/services/email_sender.py`
- [Provider detection and presets](https://github.com/toinbox/simplerelay/blob/main/backend/services/provider_presets.py): `backend/services/provider_presets.py`
- [DNS validation](https://github.com/toinbox/simplerelay/blob/main/backend/services/dns_checker.py): `backend/services/dns_checker.py`
- [Credential encryption](https://github.com/toinbox/simplerelay/blob/main/backend/services/crypto.py): `backend/services/crypto.py`

### SMTP relay

- [Postfix configuration](https://github.com/toinbox/simplerelay/blob/main/backend/services/postfix_config.py): `backend/services/postfix_config.py`
- [Relay access policy](https://github.com/toinbox/simplerelay/blob/main/backend/services/access_server.py): `backend/services/access_server.py`

### Persistence and monitoring

- **PostgreSQL**
- [Relay domain models](https://github.com/toinbox/simplerelay/blob/main/backend/models.py): `backend/models.py`
- [Database access and initialization](https://github.com/toinbox/simplerelay/blob/main/backend/database.py): `backend/database.py`
- [Mail log service](https://github.com/toinbox/simplerelay/blob/main/backend/services/mail_logger.py): `backend/services/mail_logger.py`
- [Provider health checks](https://github.com/toinbox/simplerelay/blob/main/backend/services/health_checker.py): `backend/services/health_checker.py`
- [Relay expiry checks](https://github.com/toinbox/simplerelay/blob/main/backend/services/expiry_checker.py): `backend/services/expiry_checker.py`

### Other components

- **Relay user**
- **Administrator**
- **Sending application**
- **Upstream SMTP**

## Connections

- Relay user → Dashboard app and routes: uses dashboard
- Administrator → Dashboard app and routes: uses admin panel
- Dashboard app and routes → Provider management: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → Setup wizard: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → User dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → Mail logs: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → Access control UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → User administration: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → Proxy administration: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → Provider limits UI: routes to (evidence: `frontend/src/App.jsx`)
- Dashboard app and routes → Admin mail logs: routes to (evidence: `frontend/src/App.jsx`)
- Provider management → Authenticated API client: calls (evidence: `frontend/src/pages/Providers.jsx`)
- Setup wizard → Authenticated API client: calls (evidence: `frontend/src/pages/Wizard.jsx`)
- User dashboard → Authenticated API client: calls (evidence: `frontend/src/pages/Dashboard.jsx`)
- Mail logs → Authenticated API client: calls (evidence: `frontend/src/pages/Logs.jsx`)
- Access control UI → Authenticated API client: calls (evidence: `frontend/src/pages/Clients.jsx`)
- User administration → Authenticated API client: calls (evidence: `frontend/src/pages/AdminUsers.jsx`)
- Proxy administration → Authenticated API client: calls (evidence: `frontend/src/pages/AdminProxies.jsx`)
- Provider limits UI → Authenticated API client: calls (evidence: `frontend/src/pages/AdminLimits.jsx`)
- Admin mail logs → Authenticated API client: calls (evidence: `frontend/src/pages/AdminLogs.jsx`)
- Authenticated API client → FastAPI application: sends API requests
- FastAPI application → Database access and initialization: initializes (evidence: `backend/main.py`)
- FastAPI application → Registration and authentication: registers routes (evidence: `backend/main.py`)
- FastAPI application → Provider management API: registers routes (evidence: `backend/main.py`)
- FastAPI application → Allowed-client API: registers routes (evidence: `backend/main.py`)
- FastAPI application → Dashboard data API: registers routes (evidence: `backend/main.py`)
- FastAPI application → Admin API: registers routes (evidence: `backend/main.py`)
- Registration and authentication → JWT and password auth: authenticates users (evidence: `backend/routers/auth.py`)
- Registration and authentication → Verification email delivery: sends verification mail (evidence: `backend/routers/auth.py`)
- Provider management API → Provider detection and presets: uses provider presets (evidence: `backend/routers/providers.py`)
- Provider management API → DNS validation: validates DNS (evidence: `backend/routers/providers.py`)
- Provider management API → Credential encryption: encrypts credentials (evidence: `backend/routers/providers.py`)
- Provider management API → Postfix configuration: updates relay config (evidence: `backend/routers/providers.py`)
- Allowed-client API → Postfix configuration: reloads policy config (evidence: `backend/routers/clients.py`)
- Admin API → Credential encryption: tests encrypted credentials (evidence: `backend/routers/admin.py`)
- Database access and initialization → Relay domain models: creates model tables (evidence: `backend/database.py`)
- Database access and initialization → PostgreSQL: stores records (evidence: `backend/database.py`)
- JWT and password auth → Database access and initialization: queries users (evidence: `backend/services/auth.py`)
- Provider management API → Database access and initialization: reads and writes providers (evidence: `backend/routers/providers.py`)
- Allowed-client API → Database access and initialization: reads and writes clients (evidence: `backend/routers/clients.py`)
- Admin API → Database access and initialization: manages admin data (evidence: `backend/routers/admin.py`)
- Dashboard data API → Database access and initialization: queries dashboard data (evidence: `backend/routers/dashboard.py`)
- Relay user → Sending application: configures relay
- Sending application → Postfix configuration: submits SMTP mail
- Postfix configuration → Upstream SMTP: routes by sender
- Postfix configuration → Relay access policy: checks relay access
- Relay access policy → Database access and initialization: checks allowed clients (evidence: `backend/services/access_server.py`)
- Provider management API → Provider health checks: requests health checks (evidence: `backend/routers/providers.py`)
