# rezarasoulzadeh/biztrack architecture

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

- Interactive diagram: https://gitdiagram.com/rezarasoulzadeh/biztrack
- Repository: https://github.com/rezarasoulzadeh/biztrack

## Overview

This repository is a Rust service suite for a business platform: an API gateway fronts account, tenant, and accountant workflows, with separate notification and analytics/logging services. The auth service handles registration, login, OTP and email verification, password recovery, token refresh, tenant management, and accountant assignments. Shared code supplies database initialization and security utilities. Source evidence is strongest for auth routing and OTP/token persistence, notification startup, and analytics logging; downstream gateway routing and several auth handlers were not sampled, so their connections are left unspecified.

Main entry points: [`services/auth_service/src/main.rs`](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/main.rs) (Auth Service), [`services/notifications/src/main.rs`](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/main.rs) (Notifications Service), [`services/auth_service/src/handlers/otp_handler.rs`](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/otp_handler.rs) (OTP Verification), [`services/auth_service/src/models/payloads.rs`](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/models/payloads.rs) (Auth Payloads)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["API Gateway"]
  node_gateway_app["Gateway Service<br/>[main.rs]"]
  node_gateway_proxy["Request Proxy<br/>[proxy.rs]"]
end

subgraph group_identity["Identity and Business"]
  node_auth_app["Auth Service<br/>[main.rs]"]
  node_auth_otp["OTP Verification<br/>[otp_handler.rs]"]
  node_auth_tenants["Tenant Management<br/>[tentants.rs]"]
  node_auth_accountants["Accountant Assignment<br/>[accountant.rs]"]
  node_auth_verification["Email Verification<br/>[verification.rs]"]
  node_auth_payloads["Auth Payloads<br/>[payloads.rs]"]
  node_auth_cleanup["OTP Cleanup"]
  node_auth_db[("Auth PostgreSQL")]
end

subgraph group_shared["Shared Security"]
  node_auth_db_init["Auth DB Setup<br/>[auth_db.rs]"]
  node_token_security["Token Security<br/>[tokens.rs]"]
  node_gateway_guard["Gateway Guard<br/>[enforce_gateway.rs]"]
  node_request_middleware["Auth Middleware<br/>[middleware.rs]"]
end

subgraph group_notify["Notifications"]
  node_notifications_app["Notifications Service<br/>[main.rs]"]
  node_notification_delivery["Notification Delivery<br/>[notifications.rs]"]
  node_email_routes["Verification Email Route<br/>[routes.rs]"]
  node_email_sender["SMTP Email Sender<br/>[email.rs]"]
  node_email_config["Email Configuration<br/>[config.rs]"]
  node_notification_store[("Notification MongoDB<br/>[mongo.rs]")]
  node_notification_models["Notification Models<br/>[models.rs]"]
end

subgraph group_analytics["Analytics and Logging"]
  node_analytics_app["Analytics Service<br/>[main.rs]"]
  node_log_handlers["Log Ingestion<br/>[handlers.rs]"]
  node_log_models["Log Entry Model<br/>[models.rs]"]
  node_log_storage["Log Storage Setup<br/>[storage.rs]"]
  node_log_db[("Logs MongoDB")]
end

node_client(("API Client"))

node_client -->|"sends requests"| node_gateway_app
node_gateway_app -->|"dispatches requests"| node_gateway_proxy
node_auth_app -->|"routes OTP"| node_auth_otp
node_auth_app -->|"routes tenants"| node_auth_tenants
node_auth_app -->|"routes assignments"| node_auth_accountants
node_auth_app -->|"routes verification"| node_auth_verification
node_auth_app -->|"initializes database"| node_auth_db_init
node_auth_db_init -->|"initializes"| node_auth_db
node_auth_app -->|"starts cleanup"| node_auth_cleanup
node_auth_cleanup -->|"deletes expired OTPs"| node_auth_db
node_auth_otp -->|"uses payloads"| node_auth_payloads
node_auth_tenants -->|"uses payloads"| node_auth_payloads
node_auth_accountants -->|"uses payloads"| node_auth_payloads
node_auth_verification -->|"uses payloads"| node_auth_payloads
node_auth_otp -->|"reads and writes"| node_auth_db
node_auth_otp -->|"stores tokens"| node_token_security
node_request_middleware -->|"validates tokens"| node_token_security
node_auth_app -->|"enforces gateway access"| node_gateway_guard
node_notifications_app -->|"routes delivery"| node_notification_delivery
node_notifications_app -->|"initializes MongoDB"| node_notification_store
node_notifications_app -->|"loads configuration"| node_email_config
node_notifications_app -->|"configures state"| node_notification_models
node_notification_delivery -->|"uses notifications"| node_notification_models
node_email_routes -->|"sends email"| node_email_sender
node_email_routes -->|"uses configuration"| node_email_config
node_analytics_app -->|"routes log ingestion"| node_log_handlers
node_analytics_app -->|"initializes storage"| node_log_storage
node_analytics_app -->|"configures log layer"| node_log_db
node_log_storage -->|"initializes collection"| node_log_db
node_log_handlers -->|"inserts log records"| node_log_db
node_log_handlers -->|"receives entries"| node_log_models

click node_gateway_app "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/api_gateway/src/main.rs"
click node_gateway_proxy "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/api_gateway/src/proxy.rs"
click node_auth_app "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/main.rs"
click node_auth_otp "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/otp_handler.rs"
click node_auth_tenants "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/tentants.rs"
click node_auth_accountants "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/accountant.rs"
click node_auth_verification "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/verification.rs"
click node_auth_payloads "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/models/payloads.rs"
click node_auth_cleanup "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/services/background_tasks.rs"
click node_auth_db_init "https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/db/auth_db.rs"
click node_token_security "https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/tokens.rs"
click node_gateway_guard "https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/enforce_gateway.rs"
click node_request_middleware "https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/middleware.rs"
click node_notifications_app "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/main.rs"
click node_notification_delivery "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/notifications.rs"
click node_email_routes "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/routes.rs"
click node_email_sender "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/email.rs"
click node_email_config "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/config.rs"
click node_notification_store "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/mongo.rs"
click node_notification_models "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/models.rs"
click node_analytics_app "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/main.rs"
click node_log_handlers "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/handlers.rs"
click node_log_models "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/models.rs"
click node_log_storage "https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/storage.rs"

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_gateway_app,node_gateway_proxy,node_client toneBlue
class node_auth_app,node_auth_otp,node_auth_tenants,node_auth_accountants,node_auth_verification,node_auth_payloads,node_auth_cleanup,node_auth_db toneAmber
class node_auth_db_init,node_token_security,node_gateway_guard,node_request_middleware toneMint
class node_notifications_app,node_notification_delivery,node_email_routes,node_email_sender,node_email_config,node_notification_store,node_notification_models toneRose
class node_analytics_app,node_log_handlers,node_log_models,node_log_storage,node_log_db toneIndigo
```

## Components

### API Gateway

- [Gateway Service](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/api_gateway/src/main.rs): `services/api_gateway/src/main.rs`
- [Request Proxy](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/api_gateway/src/proxy.rs): `services/api_gateway/src/proxy.rs`

### Identity and Business

- [Auth Service](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/main.rs): `services/auth_service/src/main.rs`
- [OTP Verification](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/otp_handler.rs): `services/auth_service/src/handlers/otp_handler.rs`
- [Tenant Management](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/tentants.rs): `services/auth_service/src/handlers/tentants.rs`
- [Accountant Assignment](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/accountant.rs): `services/auth_service/src/handlers/accountant.rs`
- [Email Verification](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/handlers/verification.rs): `services/auth_service/src/handlers/verification.rs`
- [Auth Payloads](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/models/payloads.rs): `services/auth_service/src/models/payloads.rs`
- [OTP Cleanup](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/auth_service/src/services/background_tasks.rs): `services/auth_service/src/services/background_tasks.rs`
- **Auth PostgreSQL**

### Shared Security

- [Auth DB Setup](https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/db/auth_db.rs): `common/src/db/auth_db.rs`
- [Token Security](https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/tokens.rs): `common/src/tokens.rs`
- [Gateway Guard](https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/enforce_gateway.rs): `common/src/enforce_gateway.rs`
- [Auth Middleware](https://github.com/rezarasoulzadeh/biztrack/blob/master/common/src/middleware.rs): `common/src/middleware.rs`

### Notifications

- [Notifications Service](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/main.rs): `services/notifications/src/main.rs`
- [Notification Delivery](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/notifications.rs): `services/notifications/src/notifications.rs`
- [Verification Email Route](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/routes.rs): `services/notifications/src/routes.rs`
- [SMTP Email Sender](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/email.rs): `services/notifications/src/email.rs`
- [Email Configuration](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/config.rs): `services/notifications/src/config.rs`
- [Notification MongoDB](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/mongo.rs): `services/notifications/src/mongo.rs`
- [Notification Models](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/notifications/src/models.rs): `services/notifications/src/models.rs`

### Analytics and Logging

- [Analytics Service](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/main.rs): `services/analytics_logging/src/main.rs`
- [Log Ingestion](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/handlers.rs): `services/analytics_logging/src/handlers.rs`
- [Log Entry Model](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/models.rs): `services/analytics_logging/src/models.rs`
- [Log Storage Setup](https://github.com/rezarasoulzadeh/biztrack/blob/master/services/analytics_logging/src/storage.rs): `services/analytics_logging/src/storage.rs`
- **Logs MongoDB**

### Other components

- **API Client**

## Connections

- API Client → Gateway Service: sends requests
- Gateway Service → Request Proxy: dispatches requests (evidence: `services/api_gateway/src/main.rs`)
- Auth Service → OTP Verification: routes OTP (evidence: `services/auth_service/src/main.rs`)
- Auth Service → Tenant Management: routes tenants (evidence: `services/auth_service/src/main.rs`)
- Auth Service → Accountant Assignment: routes assignments (evidence: `services/auth_service/src/main.rs`)
- Auth Service → Email Verification: routes verification (evidence: `services/auth_service/src/main.rs`)
- Auth Service → Auth DB Setup: initializes database (evidence: `services/auth_service/src/main.rs`)
- Auth DB Setup → Auth PostgreSQL: initializes (evidence: `common/src/db/auth_db.rs`)
- Auth Service → OTP Cleanup: starts cleanup (evidence: `services/auth_service/src/main.rs`)
- OTP Cleanup → Auth PostgreSQL: deletes expired OTPs (evidence: `services/auth_service/src/services/background_tasks.rs`)
- OTP Verification → Auth Payloads: uses payloads (evidence: `services/auth_service/src/handlers/otp_handler.rs`)
- Tenant Management → Auth Payloads: uses payloads (evidence: `services/auth_service/src/handlers/tentants.rs`)
- Accountant Assignment → Auth Payloads: uses payloads (evidence: `services/auth_service/src/handlers/accountant.rs`)
- Email Verification → Auth Payloads: uses payloads (evidence: `services/auth_service/src/handlers/verification.rs`)
- OTP Verification → Auth PostgreSQL: reads and writes (evidence: `services/auth_service/src/handlers/otp_handler.rs`)
- OTP Verification → Token Security: stores tokens (evidence: `services/auth_service/src/handlers/otp_handler.rs`)
- Auth Middleware → Token Security: validates tokens (evidence: `common/src/middleware.rs`)
- Auth Service → Gateway Guard: enforces gateway access (evidence: `services/auth_service/src/main.rs`)
- Notifications Service → Notification Delivery: routes delivery (evidence: `services/notifications/src/main.rs`)
- Notifications Service → Notification MongoDB: initializes MongoDB (evidence: `services/notifications/src/main.rs`)
- Notifications Service → Email Configuration: loads configuration (evidence: `services/notifications/src/main.rs`)
- Notifications Service → Notification Models: configures state (evidence: `services/notifications/src/main.rs`)
- Notification Delivery → Notification Models: uses notifications (evidence: `services/notifications/src/notifications.rs`)
- Verification Email Route → SMTP Email Sender: sends email (evidence: `services/notifications/src/routes.rs`)
- Verification Email Route → Email Configuration: uses configuration (evidence: `services/notifications/src/routes.rs`)
- Analytics Service → Log Ingestion: routes log ingestion (evidence: `services/analytics_logging/src/main.rs`)
- Analytics Service → Log Storage Setup: initializes storage (evidence: `services/analytics_logging/src/main.rs`)
- Analytics Service → Logs MongoDB: configures log layer (evidence: `services/analytics_logging/src/main.rs`)
- Log Storage Setup → Logs MongoDB: initializes collection (evidence: `services/analytics_logging/src/storage.rs`)
- Log Ingestion → Logs MongoDB: inserts log records (evidence: `services/analytics_logging/src/handlers.rs`)
- Log Ingestion → Log Entry Model: receives entries (evidence: `services/analytics_logging/src/handlers.rs`)
