# code-leafy/v2leafy architecture

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

- Interactive diagram: https://gitdiagram.com/code-leafy/v2leafy
- Repository: https://github.com/code-leafy/v2leafy

## Overview

V2Leafy is a single-process FastAPI dashboard and VLESS-over-WebSocket gateway. The main workflow is browser login, client and subscription management, then using generated links to connect through the gateway; the dashboard also receives live usage and status. The backend is concentrated in main.py, so its distinct responsibilities are shown as components sharing that implementation path. README documents several dashboard capabilities whose individual handlers are outside the excerpts; those links are cited to the README. The excerpts do not expose all frontend or handler wiring.

Main entry points: [`main.py`](https://github.com/code-leafy/v2leafy/blob/main/main.py) (HTTP app), [`index.html`](https://github.com/code-leafy/v2leafy/blob/main/index.html) (Dashboard UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Dashboard"]
  node_dashboard["Dashboard UI<br/>[index.html]"]
  node_http_app["HTTP app<br/>[main.py]"]
end

subgraph group_management["Management"]
  node_authentication["Password and sessions<br/>[main.py]"]
  node_client_profiles["Client profiles<br/>[main.py]"]
  node_subscription_lab["Subscription builder<br/>[main.py]"]
  node_link_generation["VLESS link generation<br/>[main.py]"]
end

subgraph group_gateway["Gateway"]
  node_gateway_controls["Gateway controls<br/>[main.py]"]
  node_vless_tunnel["WebSocket VLESS tunnel<br/>[main.py]"]
end

subgraph group_runtime["Runtime"]
  node_state_manager["State manager<br/>[main.py]"]
  node_state_store[("Runtime state<br/>[main.py]")]
  node_analytics["Live analytics<br/>[main.py]"]
  node_logs_alerts["Logs and alerts<br/>[main.py]"]
end

node_browser(("Admin browser"))
node_vless_client(("VLESS client"))
node_hosting(("Railway / Codespaces"))
node_webhook(("Alert destination"))

node_browser -->|"opens"| node_dashboard
node_http_app -->|"serves"| node_dashboard
node_dashboard -->|"uses dashboard"| node_http_app
node_http_app -->|"checks sessions"| node_authentication
node_http_app -->|"manages clients"| node_client_profiles
node_http_app -->|"builds layouts"| node_subscription_lab
node_http_app -->|"generates links"| node_link_generation
node_http_app -->|"uses state"| node_state_manager
node_state_manager -->|"loads and saves"| node_state_store
node_dashboard -->|"controls gateway"| node_gateway_controls
node_vless_client -->|"opens tunnel"| node_vless_tunnel
node_dashboard -->|"receives live metrics"| node_analytics
node_dashboard -->|"views logs"| node_logs_alerts
node_logs_alerts -.->|"posts alerts"| node_webhook
node_hosting -->|"hosts service"| node_http_app

click node_dashboard "https://github.com/code-leafy/v2leafy/blob/main/index.html"
click node_http_app "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_authentication "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_client_profiles "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_subscription_lab "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_link_generation "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_state_manager "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_state_store "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_gateway_controls "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_vless_tunnel "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_analytics "https://github.com/code-leafy/v2leafy/blob/main/main.py"
click node_logs_alerts "https://github.com/code-leafy/v2leafy/blob/main/main.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_dashboard,node_http_app,node_browser,node_vless_client toneBlue
class node_authentication,node_client_profiles,node_subscription_lab,node_link_generation toneAmber
class node_gateway_controls,node_vless_tunnel toneMint
class node_state_manager,node_state_store,node_analytics,node_logs_alerts toneRose
class node_hosting,node_webhook toneIndigo
```

## Components

### Dashboard

- [Dashboard UI](https://github.com/code-leafy/v2leafy/blob/main/index.html): `index.html`
- [HTTP app](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`

### Management

- [Password and sessions](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [Client profiles](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [Subscription builder](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [VLESS link generation](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`

### Gateway

- [Gateway controls](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [WebSocket VLESS tunnel](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`

### Runtime

- [State manager](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [Runtime state](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [Live analytics](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`
- [Logs and alerts](https://github.com/code-leafy/v2leafy/blob/main/main.py): `main.py`

### Other components

- **Admin browser**
- **VLESS client**
- **Railway / Codespaces**
- **Alert destination**

## Connections

- Admin browser → Dashboard UI: opens (evidence: `README.md`)
- HTTP app → Dashboard UI: serves (evidence: `main.py`)
- Dashboard UI → HTTP app: uses dashboard (evidence: `README.md`)
- HTTP app → Password and sessions: checks sessions (evidence: `main.py`)
- HTTP app → Client profiles: manages clients (evidence: `README.md`)
- HTTP app → Subscription builder: builds layouts (evidence: `README.md`)
- HTTP app → VLESS link generation: generates links (evidence: `main.py`)
- HTTP app → State manager: uses state (evidence: `main.py`)
- State manager → Runtime state: loads and saves (evidence: `main.py`)
- Dashboard UI → Gateway controls: controls gateway (evidence: `README.md`)
- VLESS client → WebSocket VLESS tunnel: opens tunnel (evidence: `main.py`)
- Dashboard UI → Live analytics: receives live metrics (evidence: `README.md`)
- Dashboard UI → Logs and alerts: views logs (evidence: `README.md`)
- Logs and alerts → Alert destination: posts alerts (evidence: `main.py`)
- Railway / Codespaces → HTTP app: hosts service (evidence: `README.md`)
