# prasanth866/watchtower architecture

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

- Interactive diagram: https://gitdiagram.com/prasanth866/watchtower
- Repository: https://github.com/prasanth866/watchtower

## Overview

WatchTower serves a browser dashboard for live crypto analysis, threshold alerts, and simulated trading. Users authenticate, then the frontend requests REST data and subscribes to a WebSocket price feed; they can configure alerts or transact against a virtual portfolio. Backend workers collect market data and process alert/email side effects, while PostgreSQL and Redis provide durable and low-latency state. The graph preserves documented chart caching and trading capabilities; unsampled routers and workers are included only where README or source-index evidence supports their role.

Main entry points: [`frontend/src/App.tsx`](https://github.com/prasanth866/watchtower/blob/main/frontend/src/App.tsx) (Dashboard shell), [`frontend/src/api.ts`](https://github.com/prasanth866/watchtower/blob/main/frontend/src/api.ts) (HTTP and WebSocket client), [`backend/main.py`](https://github.com/prasanth866/watchtower/blob/main/backend/main.py) (FastAPI application), [`backend/core/database.py`](https://github.com/prasanth866/watchtower/blob/main/backend/core/database.py) (PostgreSQL state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Dashboard"]
  node_app["Dashboard shell<br/>[App.tsx]"]
  node_auth_ui["Authentication UI<br/>[AuthLayout.tsx]"]
  node_market_ui["Market analysis<br/>[CoinAnalysis.tsx]"]
  node_triggers_ui["Alert controls<br/>[TriggerEngine.tsx]"]
  node_trading_ui["Trading terminal"]
  node_toasts["Toast notifications<br/>[ToastProvider.tsx]"]
  node_client_api["HTTP and WebSocket client<br/>[api.ts]"]
end

subgraph group_api["API and Services"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_auth["Authentication routes<br/>[auth.py]"]
  node_coins["Coin and chart routes<br/>[coins_router.py]"]
  node_triggers["Trigger routes<br/>[trigger_router.py]"]
  node_trading["Paper trading routes"]
  node_health["Health monitoring<br/>[health.py]"]
  node_trigger_logic["Trigger services"]
  node_auth_logic["Authentication service<br/>[auth_service.py]"]
end

subgraph group_market["Market and Alerts"]
  node_market_worker["Market data worker<br/>[crypto.py]"]
  node_broadcaster["Price broadcaster<br/>[broadcaster.py]"]
  node_event_processing["Event processing"]
  node_email_worker["Email queue worker<br/>[email_worker.py]"]
  node_email_service["Email delivery<br/>[email_service.py]"]
end

subgraph group_runtime["Runtime State"]
  node_postgres[("PostgreSQL state<br/>[database.py]")]
  node_redis[("Redis cache and Pub/Sub")]
end

node_user(("Dashboard user"))
node_coingecko["CoinGecko"]
node_brevo["Brevo email API"]

node_user -->|"uses"| node_app
node_app -->|"shows"| node_auth_ui
node_app -->|"shows"| node_market_ui
node_app -->|"shows"| node_triggers_ui
node_app -->|"shows"| node_trading_ui
node_app -->|"connects feed"| node_client_api
node_auth_ui -->|"calls"| node_client_api
node_market_ui -->|"requests data"| node_client_api
node_triggers_ui -->|"manages alerts"| node_client_api
node_trading_ui -->|"places trades"| node_client_api
node_app -->|"renders"| node_toasts
node_client_api -.->|"HTTP and WS"| node_fastapi
node_fastapi -.->|"routes"| node_auth
node_fastapi -.->|"routes"| node_coins
node_fastapi -.->|"routes"| node_triggers
node_fastapi -.->|"routes"| node_trading
node_fastapi -.->|"routes"| node_health
node_auth -.->|"delegates"| node_auth_logic
node_auth_logic -.->|"reads users"| node_postgres
node_triggers -->|"delegates"| node_trigger_logic
node_trigger_logic -->|"uses models"| node_postgres
node_trading -->|"uses models"| node_postgres
node_coins -.->|"caches charts"| node_redis
node_coins -.->|"proxies charts"| node_coingecko
node_market_worker -.->|"collects prices"| node_coingecko
node_market_worker -.->|"publishes events"| node_broadcaster
node_broadcaster -->|"uses Pub/Sub"| node_redis
node_broadcaster -->|"dispatches events"| node_event_processing
node_broadcaster -.->|"streams prices"| node_client_api
node_event_processing -.->|"checks thresholds"| node_trigger_logic
node_event_processing -.->|"queues alerts"| node_email_worker
node_email_worker -->|"sends pending"| node_email_service
node_email_service -->|"reads queue"| node_postgres
node_email_service -.->|"delivers mail"| node_brevo
node_health -.->|"checks database"| node_postgres

click node_app "https://github.com/prasanth866/watchtower/blob/main/frontend/src/App.tsx"
click node_auth_ui "https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/AuthLayout.tsx"
click node_market_ui "https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/CoinAnalysis.tsx"
click node_triggers_ui "https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/TriggerEngine.tsx"
click node_trading_ui "https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/TradingTerminal.tsx"
click node_toasts "https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/ToastProvider.tsx"
click node_client_api "https://github.com/prasanth866/watchtower/blob/main/frontend/src/api.ts"
click node_fastapi "https://github.com/prasanth866/watchtower/blob/main/backend/main.py"
click node_auth "https://github.com/prasanth866/watchtower/blob/main/backend/api/auth.py"
click node_coins "https://github.com/prasanth866/watchtower/blob/main/backend/api/coins_router.py"
click node_triggers "https://github.com/prasanth866/watchtower/blob/main/backend/api/trigger_router.py"
click node_trading "https://github.com/prasanth866/watchtower/blob/main/backend/api/paper_trading_router.py"
click node_health "https://github.com/prasanth866/watchtower/blob/main/backend/api/health.py"
click node_trigger_logic "https://github.com/prasanth866/watchtower/blob/main/backend/services/trigger_services.py"
click node_auth_logic "https://github.com/prasanth866/watchtower/blob/main/backend/services/auth_service.py"
click node_market_worker "https://github.com/prasanth866/watchtower/blob/main/backend/workers/crypto.py"
click node_broadcaster "https://github.com/prasanth866/watchtower/blob/main/backend/services/broadcaster.py"
click node_event_processing "https://github.com/prasanth866/watchtower/blob/main/backend/services/event_processing_service.py"
click node_email_worker "https://github.com/prasanth866/watchtower/blob/main/backend/workers/email_worker.py"
click node_email_service "https://github.com/prasanth866/watchtower/blob/main/backend/services/email_service.py"
click node_postgres "https://github.com/prasanth866/watchtower/blob/main/backend/core/database.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_auth_ui,node_market_ui,node_triggers_ui,node_trading_ui,node_toasts,node_client_api,node_user toneBlue
class node_fastapi,node_auth,node_coins,node_triggers,node_trading,node_health,node_trigger_logic,node_auth_logic toneAmber
class node_market_worker,node_broadcaster,node_event_processing,node_email_worker,node_email_service,node_brevo toneMint
class node_postgres,node_redis toneRose
class node_coingecko toneIndigo
```

## Components

### Dashboard

- [Dashboard shell](https://github.com/prasanth866/watchtower/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Authentication UI](https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/AuthLayout.tsx): `frontend/src/components/AuthLayout.tsx`
- [Market analysis](https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/CoinAnalysis.tsx): `frontend/src/components/CoinAnalysis.tsx`
- [Alert controls](https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/TriggerEngine.tsx): `frontend/src/components/TriggerEngine.tsx`
- [Trading terminal](https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/TradingTerminal.tsx): `frontend/src/components/TradingTerminal.tsx`
- [Toast notifications](https://github.com/prasanth866/watchtower/blob/main/frontend/src/components/ToastProvider.tsx): `frontend/src/components/ToastProvider.tsx`
- [HTTP and WebSocket client](https://github.com/prasanth866/watchtower/blob/main/frontend/src/api.ts): `frontend/src/api.ts`

### API and Services

- [FastAPI application](https://github.com/prasanth866/watchtower/blob/main/backend/main.py): `backend/main.py`
- [Authentication routes](https://github.com/prasanth866/watchtower/blob/main/backend/api/auth.py): `backend/api/auth.py`
- [Coin and chart routes](https://github.com/prasanth866/watchtower/blob/main/backend/api/coins_router.py): `backend/api/coins_router.py`
- [Trigger routes](https://github.com/prasanth866/watchtower/blob/main/backend/api/trigger_router.py): `backend/api/trigger_router.py`
- [Paper trading routes](https://github.com/prasanth866/watchtower/blob/main/backend/api/paper_trading_router.py): `backend/api/paper_trading_router.py`
- [Health monitoring](https://github.com/prasanth866/watchtower/blob/main/backend/api/health.py): `backend/api/health.py`
- [Trigger services](https://github.com/prasanth866/watchtower/blob/main/backend/services/trigger_services.py): `backend/services/trigger_services.py`
- [Authentication service](https://github.com/prasanth866/watchtower/blob/main/backend/services/auth_service.py): `backend/services/auth_service.py`

### Market and Alerts

- [Market data worker](https://github.com/prasanth866/watchtower/blob/main/backend/workers/crypto.py): `backend/workers/crypto.py`
- [Price broadcaster](https://github.com/prasanth866/watchtower/blob/main/backend/services/broadcaster.py): `backend/services/broadcaster.py`
- [Event processing](https://github.com/prasanth866/watchtower/blob/main/backend/services/event_processing_service.py): `backend/services/event_processing_service.py`
- [Email queue worker](https://github.com/prasanth866/watchtower/blob/main/backend/workers/email_worker.py): `backend/workers/email_worker.py`
- [Email delivery](https://github.com/prasanth866/watchtower/blob/main/backend/services/email_service.py): `backend/services/email_service.py`

### Runtime State

- [PostgreSQL state](https://github.com/prasanth866/watchtower/blob/main/backend/core/database.py): `backend/core/database.py`
- **Redis cache and Pub/Sub**

### Other components

- **Dashboard user**
- **CoinGecko**
- **Brevo email API**

## Connections

- Dashboard user → Dashboard shell: uses (evidence: `frontend/src/App.tsx`)
- Dashboard shell → Authentication UI: shows (evidence: `frontend/src/App.tsx`)
- Dashboard shell → Market analysis: shows (evidence: `frontend/src/App.tsx`)
- Dashboard shell → Alert controls: shows (evidence: `frontend/src/App.tsx`)
- Dashboard shell → Trading terminal: shows (evidence: `frontend/src/App.tsx`)
- Dashboard shell → HTTP and WebSocket client: connects feed (evidence: `frontend/src/App.tsx`)
- Authentication UI → HTTP and WebSocket client: calls (evidence: `frontend/src/components/AuthLayout.tsx`)
- Market analysis → HTTP and WebSocket client: requests data (evidence: `frontend/src/components/CoinAnalysis.tsx`)
- Alert controls → HTTP and WebSocket client: manages alerts (evidence: `frontend/src/components/TriggerEngine.tsx`)
- Trading terminal → HTTP and WebSocket client: places trades (evidence: `frontend/src/components/TradingTerminal.tsx`)
- Dashboard shell → Toast notifications: renders (evidence: `frontend/src/App.tsx`)
- HTTP and WebSocket client → FastAPI application: HTTP and WS
- FastAPI application → Authentication routes: routes
- FastAPI application → Coin and chart routes: routes
- FastAPI application → Trigger routes: routes
- FastAPI application → Paper trading routes: routes
- FastAPI application → Health monitoring: routes
- Authentication routes → Authentication service: delegates
- Authentication service → PostgreSQL state: reads users
- Trigger routes → Trigger services: delegates (evidence: `backend/api/trigger_router.py`)
- Trigger services → PostgreSQL state: uses models (evidence: `backend/services/trigger_services.py`)
- Paper trading routes → PostgreSQL state: uses models (evidence: `backend/api/paper_trading_router.py`)
- Coin and chart routes → Redis cache and Pub/Sub: caches charts
- Coin and chart routes → CoinGecko: proxies charts (evidence: `README.md`)
- Market data worker → CoinGecko: collects prices (evidence: `README.md`)
- Market data worker → Price broadcaster: publishes events
- Price broadcaster → Redis cache and Pub/Sub: uses Pub/Sub (evidence: `backend/services/broadcaster.py`)
- Price broadcaster → Event processing: dispatches events (evidence: `backend/services/broadcaster.py`)
- Price broadcaster → HTTP and WebSocket client: streams prices (evidence: `README.md`)
- Event processing → Trigger services: checks thresholds
- Event processing → Email queue worker: queues alerts
- Email queue worker → Email delivery: sends pending (evidence: `backend/workers/email_worker.py`)
- Email delivery → PostgreSQL state: reads queue (evidence: `backend/services/email_service.py`)
- Email delivery → Brevo email API: delivers mail (evidence: `README.md`)
- Health monitoring → PostgreSQL state: checks database
