# titan-255/defi-guardian-even-g2 architecture

> Architecture diagram of the GitHub repository titan-255/defi-guardian-even-g2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/titan-255/defi-guardian-even-g2
- Repository: https://github.com/titan-255/defi-guardian-even-g2

## Overview

DeFi Guardian combines a React wearable companion with a FastAPI service for live crypto intelligence, alerts, read-only wallet monitoring, and simulated trading. The user-facing workflow is: view live prices, inspect anomaly analysis, review portfolio or alerts, and preview then confirm a paper trade; Even G2 gestures navigate the screens. The graph preserves the documented browser-side statistical fallback and optional CoinGecko integration. Some subsystems are supported by README or source-index references rather than sampled implementation excerpts, so their links are limited to those explicit relationships.

Main entry points: [`frontend/src/App.tsx`](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/App.tsx) (Screen coordinator), [`backend/app/main.py`](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/main.py) (FastAPI application), [`backend/app/services/hyperliquid.py`](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/hyperliquid.py) (Hyperliquid service), [`backend/app/database.py`](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/database.py) (SQLite state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_wearable["Wearable companion"]
  node_glasses["G2 glasses"]
  node_app["Screen coordinator<br/>[App.tsx]"]
  node_bridge["Even Hub bridge<br/>[evenBridge.ts]"]
  node_market_view["Market glance<br/>[MarketGlance.tsx]"]
  node_insight_view["AI insight<br/>[AiInsight.tsx]"]
  node_attention_view["Market attention"]
  node_portfolio_view["Portfolio screen<br/>[PortfolioView.tsx]"]
  node_trading_view["Paper trading screen"]
  node_alerts_view["Alerts screen<br/>[AlertsView.tsx]"]
  node_settings_view["Settings screen<br/>[SettingsView.tsx]"]
  node_companion_view["Companion dashboard<br/>[CompanionView.tsx]"]
  node_api_client["API and fallback<br/>[api.ts]"]
end

subgraph group_backend_api["Backend API"]
  node_backend["FastAPI application<br/>[main.py]"]
  node_market_router["Market routes<br/>[market.py]"]
  node_intelligence_router["Intelligence routes<br/>[intelligence.py]"]
  node_portfolio_router["Portfolio routes<br/>[portfolio.py]"]
  node_trading_router["Trading routes<br/>[trading.py]"]
  node_alerts_router["Alert routes<br/>[alerts.py]"]
  node_wallet_router["Wallet routes<br/>[wallet.py]"]
  node_health_router["Health routes<br/>[health.py]"]
  node_demo_router["Demo reset<br/>[demo.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
end

subgraph group_market_intelligence["Market intelligence"]
  node_hyperliquid["Hyperliquid service<br/>[hyperliquid.py]"]
  node_hyperliquid_api["Hyperliquid API"]
  node_coingecko["CoinGecko service<br/>[coingecko.py]"]
  node_coingecko_api["CoinGecko API"]
  node_market_service["Market aggregation<br/>[market_service.py]"]
  node_anomaly["Isolation Forest engine<br/>[anomaly_engine.py]"]
end

subgraph group_portfolio_safety["Portfolio and safety"]
  node_alerts_service["Alert evaluation<br/>[alerts.py]"]
  node_paper_engine["Paper trading engine<br/>[paper_trading.py]"]
  node_database[("SQLite state<br/>[database.py]")]
  node_security["Mutation guard<br/>[security.py]"]
end

node_user(("Wearable user"))

node_user -->|"gestures"| node_glasses
node_glasses -->|"sends events"| node_bridge
node_bridge -->|"notifies navigation"| node_app
node_app -->|"initializes and subscribes"| node_bridge
node_app -->|"renders screen"| node_market_view
node_app -->|"renders screen"| node_insight_view
node_app -->|"renders screen"| node_attention_view
node_app -->|"renders screen"| node_portfolio_view
node_app -->|"renders screen"| node_trading_view
node_app -->|"renders screen"| node_alerts_view
node_app -->|"renders screen"| node_settings_view
node_app -->|"renders dashboard"| node_companion_view
node_app -->|"requests data"| node_api_client
node_api_client -->|"REST requests"| node_backend
node_api_client -.->|"browser fallback"| node_hyperliquid_api
node_backend -->|"registers routes"| node_market_router
node_backend -->|"registers routes"| node_intelligence_router
node_backend -->|"registers routes"| node_portfolio_router
node_backend -->|"registers routes"| node_trading_router
node_backend -->|"registers routes"| node_alerts_router
node_backend -->|"registers routes"| node_wallet_router
node_backend -->|"registers routes"| node_health_router
node_backend -->|"registers routes"| node_demo_router
node_backend -->|"initializes schema"| node_database
node_market_router -->|"delegates market data"| node_market_service
node_market_router -->|"requests prices"| node_hyperliquid
node_intelligence_router -->|"requests analysis"| node_anomaly
node_anomaly -->|"loads candles"| node_hyperliquid
node_hyperliquid -->|"fetches market state"| node_hyperliquid_api
node_market_service -->|"uses price data"| node_hyperliquid
node_health_router -->|"checks availability"| node_coingecko
node_coingecko -.->|"optional lookup"| node_coingecko_api
node_portfolio_router -->|"loads portfolio"| node_paper_engine
node_trading_router -->|"previews and confirms"| node_paper_engine
node_alerts_router -->|"delegates alert work"| node_alerts_service
node_alerts_service -->|"stores alert state"| node_database
node_paper_engine -->|"reads and writes trades"| node_database
node_paper_engine -->|"gets live prices"| node_hyperliquid
node_wallet_router -->|"loads public wallet"| node_hyperliquid
node_wallet_router -->|"stores wallet setting"| node_database
node_alerts_router -->|"guards mutations"| node_security
node_trading_router -->|"guards mutations"| node_security
node_wallet_router -->|"guards configuration"| node_security
node_demo_router -->|"resets demo state"| node_database
node_market_router -->|"validates and shapes"| node_schemas
node_intelligence_router -->|"shapes response"| node_schemas
node_trading_router -->|"validates trades"| node_schemas

click node_app "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/App.tsx"
click node_bridge "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/services/evenBridge.ts"
click node_market_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/MarketGlance.tsx"
click node_insight_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/AiInsight.tsx"
click node_attention_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/MarketAttention.tsx"
click node_portfolio_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/PortfolioView.tsx"
click node_trading_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/PaperTradingView.tsx"
click node_alerts_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/AlertsView.tsx"
click node_settings_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/SettingsView.tsx"
click node_companion_view "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/CompanionView.tsx"
click node_api_client "https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/services/api.ts"
click node_backend "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/main.py"
click node_market_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/market.py"
click node_intelligence_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/intelligence.py"
click node_portfolio_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/portfolio.py"
click node_trading_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/trading.py"
click node_alerts_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/alerts.py"
click node_wallet_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/wallet.py"
click node_health_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/health.py"
click node_demo_router "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/demo.py"
click node_schemas "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/schemas.py"
click node_hyperliquid "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/hyperliquid.py"
click node_coingecko "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/coingecko.py"
click node_market_service "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/market_service.py"
click node_anomaly "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/anomaly_engine.py"
click node_alerts_service "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/alerts.py"
click node_paper_engine "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/paper_trading.py"
click node_database "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/database.py"
click node_security "https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/security.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_glasses,node_app,node_bridge,node_market_view,node_insight_view,node_attention_view,node_portfolio_view,node_trading_view,node_alerts_view,node_settings_view,node_companion_view,node_api_client,node_user toneBlue
class node_backend,node_market_router,node_intelligence_router,node_portfolio_router,node_trading_router,node_alerts_router,node_wallet_router,node_health_router,node_demo_router,node_schemas toneAmber
class node_hyperliquid,node_hyperliquid_api,node_coingecko,node_coingecko_api,node_market_service,node_anomaly toneMint
class node_alerts_service,node_paper_engine,node_database,node_security toneRose
```

## Components

### Wearable companion

- **G2 glasses**
- [Screen coordinator](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Even Hub bridge](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/services/evenBridge.ts): `frontend/src/services/evenBridge.ts`
- [Market glance](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/MarketGlance.tsx): `frontend/src/components/MarketGlance.tsx`
- [AI insight](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/AiInsight.tsx): `frontend/src/components/AiInsight.tsx`
- [Market attention](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/MarketAttention.tsx): `frontend/src/components/MarketAttention.tsx`
- [Portfolio screen](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/PortfolioView.tsx): `frontend/src/components/PortfolioView.tsx`
- [Paper trading screen](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/PaperTradingView.tsx): `frontend/src/components/PaperTradingView.tsx`
- [Alerts screen](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/AlertsView.tsx): `frontend/src/components/AlertsView.tsx`
- [Settings screen](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/SettingsView.tsx): `frontend/src/components/SettingsView.tsx`
- [Companion dashboard](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/components/CompanionView.tsx): `frontend/src/components/CompanionView.tsx`
- [API and fallback](https://github.com/titan-255/defi-guardian-even-g2/blob/master/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### Backend API

- [FastAPI application](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/main.py): `backend/app/main.py`
- [Market routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/market.py): `backend/app/routers/market.py`
- [Intelligence routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/intelligence.py): `backend/app/routers/intelligence.py`
- [Portfolio routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/portfolio.py): `backend/app/routers/portfolio.py`
- [Trading routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/trading.py): `backend/app/routers/trading.py`
- [Alert routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/alerts.py): `backend/app/routers/alerts.py`
- [Wallet routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/wallet.py): `backend/app/routers/wallet.py`
- [Health routes](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/health.py): `backend/app/routers/health.py`
- [Demo reset](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/routers/demo.py): `backend/app/routers/demo.py`
- [Request and response schemas](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/schemas.py): `backend/app/schemas.py`

### Market intelligence

- [Hyperliquid service](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/hyperliquid.py): `backend/app/services/hyperliquid.py`
- **Hyperliquid API**
- [CoinGecko service](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/coingecko.py): `backend/app/services/coingecko.py`
- **CoinGecko API**
- [Market aggregation](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/market_service.py): `backend/app/services/market_service.py`
- [Isolation Forest engine](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/anomaly_engine.py): `backend/app/services/anomaly_engine.py`

### Portfolio and safety

- [Alert evaluation](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/alerts.py): `backend/app/services/alerts.py`
- [Paper trading engine](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/services/paper_trading.py): `backend/app/services/paper_trading.py`
- [SQLite state](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/database.py): `backend/app/database.py`
- [Mutation guard](https://github.com/titan-255/defi-guardian-even-g2/blob/master/backend/app/security.py): `backend/app/security.py`

### Other components

- **Wearable user**

## Connections

- Wearable user → G2 glasses: gestures
- G2 glasses → Even Hub bridge: sends events
- Even Hub bridge → Screen coordinator: notifies navigation (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Even Hub bridge: initializes and subscribes (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Market glance: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → AI insight: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Market attention: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Portfolio screen: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Paper trading screen: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Alerts screen: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Settings screen: renders screen (evidence: `frontend/src/App.tsx`)
- Screen coordinator → Companion dashboard: renders dashboard (evidence: `frontend/src/App.tsx`)
- Screen coordinator → API and fallback: requests data (evidence: `frontend/src/App.tsx`)
- API and fallback → FastAPI application: REST requests
- API and fallback → Hyperliquid API: browser fallback
- FastAPI application → Market routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Intelligence routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Portfolio routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Trading routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Alert routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Wallet routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Health routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Demo reset: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → SQLite state: initializes schema (evidence: `backend/app/main.py`)
- Market routes → Market aggregation: delegates market data (evidence: `backend/app/routers/market.py`)
- Market routes → Hyperliquid service: requests prices (evidence: `backend/app/routers/market.py`)
- Intelligence routes → Isolation Forest engine: requests analysis (evidence: `backend/app/routers/intelligence.py`)
- Isolation Forest engine → Hyperliquid service: loads candles (evidence: `backend/app/services/anomaly_engine.py`)
- Hyperliquid service → Hyperliquid API: fetches market state (evidence: `backend/app/services/hyperliquid.py`)
- Market aggregation → Hyperliquid service: uses price data (evidence: `backend/app/services/market_service.py`)
- Health routes → CoinGecko service: checks availability (evidence: `backend/app/routers/health.py`)
- CoinGecko service → CoinGecko API: optional lookup (evidence: `backend/app/services/coingecko.py`)
- Portfolio routes → Paper trading engine: loads portfolio (evidence: `backend/app/routers/portfolio.py`)
- Trading routes → Paper trading engine: previews and confirms (evidence: `backend/app/routers/trading.py`)
- Alert routes → Alert evaluation: delegates alert work (evidence: `backend/app/routers/alerts.py`)
- Alert evaluation → SQLite state: stores alert state (evidence: `backend/app/services/alerts.py`)
- Paper trading engine → SQLite state: reads and writes trades (evidence: `backend/app/services/paper_trading.py`)
- Paper trading engine → Hyperliquid service: gets live prices (evidence: `backend/app/services/paper_trading.py`)
- Wallet routes → Hyperliquid service: loads public wallet (evidence: `backend/app/routers/wallet.py`)
- Wallet routes → SQLite state: stores wallet setting (evidence: `backend/app/routers/wallet.py`)
- Alert routes → Mutation guard: guards mutations (evidence: `backend/app/routers/alerts.py`)
- Trading routes → Mutation guard: guards mutations (evidence: `backend/app/routers/trading.py`)
- Wallet routes → Mutation guard: guards configuration (evidence: `backend/app/routers/wallet.py`)
- Demo reset → SQLite state: resets demo state (evidence: `backend/app/routers/demo.py`)
- Market routes → Request and response schemas: validates and shapes (evidence: `backend/app/routers/market.py`)
- Intelligence routes → Request and response schemas: shapes response (evidence: `backend/app/routers/intelligence.py`)
- Trading routes → Request and response schemas: validates trades (evidence: `backend/app/routers/trading.py`)
