# favoursui/bagsflow architecture

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

- Interactive diagram: https://gitdiagram.com/favoursui/bagsflow
- Repository: https://github.com/favoursui/bagsflow

## Overview

#### Purpose and Deployment Boundary
BAGS//FLOW is a single-origin Solana/Bags.fm trading dashboard: it displays live Bags-token order flow and lets a connected browser wallet execute swaps. Nginx serves the compiled static UI and reverse-proxies API and WebSocket traffic to FastAPI. Deployment is containerized through `docker-compose.yaml`, with proxy behavior in `nginx.conf`.

#### Browser Application
The frontend is a static Vanilla JS application using Chart.js and Tailwind-generated CSS. Dashboard code consumes live events, maintains feed/chart/leaderboard views, and surfaces token launches; swap code handles wallet connection, quote interaction, transaction signing, and Solscan links.
- `frontend/build/index.html`
- `frontend/build/js/dashboard.js`
- `frontend/build/js/swap.js`

#### FastAPI Application and Entry Points
The backend application is initialized in FastAPI, registers HTTP route modules, and owns lifecycle work such as the launch poller and real-time stream startup. It is runnable directly or as the backend container.
- `backend/app/main.py`
- `backend/run.py`
- `backend/app/api/routes.py`

#### HTTP API: Token, Analytics, and Swap Workflows
The API boundary separates browser-facing operations from upstream providers. Token endpoints validate token addresses and retrieve metadata/quotes; swap endpoints obtain executable swap transactions and support submission flow; analytics exposes aggregated session-facing data. Browser wallet signing remains client-side, while the backend brokers provider requests.
- `backend/app/api/tokens.py`
- `backend/app/api/swap.py`
- `backend/app/api/analytics.py`

#### Real-Time Trade Pipeline
A Helius WebSocket subscription watches Solana program logs relevant to Meteora DBC and Bags activity. Streamed logs are parsed/enriched into trade events, classified for whale thresholds, and distributed to connected dashboard clients through the backend WebSocket endpoint. This isolates chain-stream/provider protocol handling from browser presentation.
- `backend/app/services/bitquery.py`
- `backend/app/core/websocket.py`
- `backend/app/main.py`

#### Provider Integration Layer
Service clients encapsulate external dependencies: Bags.fm REST for token/swap functionality, Helius RPC/DAS for chain and token metadata access, and related provider handling for streaming/enrichment. Environment-backed settings centralize API keys, RPC URL, browser origin, and whale threshold.
- `backend/app/services/bags.py`
- `backend/app/services/helius.py`
- `backend/app/core/config.py`

#### Runtime and External Infrastructure
The production path is browser → Nginx → FastAPI for `/api/`, while `/ws` is proxied bidirectionally for live events. FastAPI runs on Python/uvicorn; frontend assets require no application server beyond Nginx. Core external systems are Solana mainnet RPC, Helius WebSocket/DAS APIs, Bags.fm APIs, Meteora DAMM v2 routing/liquidity, and browser wallets such as Phantom, Backpack, or Solflare.

Main entry points: [`backend/app/api/routes.py`](https://github.com/favoursui/bagsflow/blob/main/backend/app/api/routes.py) (Route registration), [`backend/app/main.py`](https://github.com/favoursui/bagsflow/blob/main/backend/app/main.py) (FastAPI application), [`nginx.conf`](https://github.com/favoursui/bagsflow/blob/main/nginx.conf) (Nginx reverse proxy), [`frontend/build/index.html`](https://github.com/favoursui/bagsflow/blob/main/frontend/build/index.html) (Static dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser UI"]
  node_frontend["Static dashboard<br/>Vanilla JS UI<br/>[index.html]"]
  node_dashboard["Live dashboard<br/>dashboard module<br/>[dashboard.js]"]
  node_swap_ui["Wallet swap flow<br/>swap module<br/>[swap.js]"]
  node_wallet["Browser wallet<br/>wallet extension"]
end

subgraph group_backend["FastAPI backend"]
  node_main["FastAPI application<br/>application lifecycle<br/>[main.py]"]
  node_runner["Backend runner<br/>uvicorn entry point<br/>[run.py]"]
  node_routes["Route registration<br/>HTTP route boundary<br/>[routes.py]"]
  node_token_api["Token API<br/>token endpoints<br/>[tokens.py]"]
  node_swap_api["Swap API<br/>swap endpoints<br/>[swap.py]"]
  node_analytics_api["Analytics API<br/>analytics endpoints<br/>[analytics.py]"]
  node_stream["Trade stream processor<br/>Helius log stream<br/>[bitquery.py]"]
  node_ws_hub["Dashboard WebSocket hub<br/>event distribution<br/>[websocket.py]"]
end

subgraph group_providers["Chain &amp; trading providers"]
  node_bags["Bags.fm API<br/>trading provider<br/>[bags.py]"]
  node_helius["Helius RPC, DAS &amp; WebSocket<br/>chain provider<br/>[helius.py]"]
  node_solana["Solana mainnet<br/>blockchain network"]
end

node_nginx{{"Nginx reverse proxy<br/>edge proxy<br/>[nginx.conf]"}}

node_nginx -->|"serves static assets"| node_frontend
node_frontend -->|"loads"| node_dashboard
node_frontend -->|"loads"| node_swap_ui
node_dashboard -->|"HTTP API and /ws"| node_nginx
node_swap_ui -->|"swap and token API"| node_nginx
node_swap_ui -->|"requests transaction signature"| node_wallet
node_nginx -->|"proxies /api and /ws"| node_main
node_runner -->|"runs"| node_main
node_main -->|"registers"| node_routes
node_routes -->|"routes requests"| node_token_api
node_routes -->|"routes requests"| node_swap_api
node_routes -->|"routes requests"| node_analytics_api
node_main -->|"starts"| node_stream
node_stream -->|"trade events"| node_ws_hub
node_ws_hub -->|"live events"| node_dashboard
node_token_api -->|"token data and quotes"| node_bags
node_swap_api -->|"swap transactions"| node_bags
node_token_api -->|"token metadata"| node_helius
node_stream -->|"program-log subscription"| node_helius
node_helius -->|"RPC and chain data"| node_solana
node_wallet -->|"submits signed swaps"| node_solana

click node_nginx "https://github.com/favoursui/bagsflow/blob/main/nginx.conf"
click node_frontend "https://github.com/favoursui/bagsflow/blob/main/frontend/build/index.html"
click node_dashboard "https://github.com/favoursui/bagsflow/blob/main/frontend/build/js/dashboard.js"
click node_swap_ui "https://github.com/favoursui/bagsflow/blob/main/frontend/build/js/swap.js"
click node_main "https://github.com/favoursui/bagsflow/blob/main/backend/app/main.py"
click node_runner "https://github.com/favoursui/bagsflow/blob/main/backend/run.py"
click node_routes "https://github.com/favoursui/bagsflow/blob/main/backend/app/api/routes.py"
click node_token_api "https://github.com/favoursui/bagsflow/blob/main/backend/app/api/tokens.py"
click node_swap_api "https://github.com/favoursui/bagsflow/blob/main/backend/app/api/swap.py"
click node_analytics_api "https://github.com/favoursui/bagsflow/blob/main/backend/app/api/analytics.py"
click node_stream "https://github.com/favoursui/bagsflow/blob/main/backend/app/services/bitquery.py"
click node_ws_hub "https://github.com/favoursui/bagsflow/blob/main/backend/app/core/websocket.py"
click node_bags "https://github.com/favoursui/bagsflow/blob/main/backend/app/services/bags.py"
click node_helius "https://github.com/favoursui/bagsflow/blob/main/backend/app/services/helius.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_frontend,node_dashboard,node_swap_ui,node_wallet toneBlue
class node_main,node_runner,node_routes,node_token_api,node_swap_api,node_analytics_api,node_stream,node_ws_hub toneAmber
class node_bags,node_helius,node_solana toneMint
class node_nginx toneNeutral
```

## Components

### Browser UI

- [Static dashboard](https://github.com/favoursui/bagsflow/blob/main/frontend/build/index.html): Vanilla JS UI · `frontend/build/index.html`
- [Live dashboard](https://github.com/favoursui/bagsflow/blob/main/frontend/build/js/dashboard.js): dashboard module · Maintains feed, chart, leaderboard, and launch views. · `frontend/build/js/dashboard.js`
- [Wallet swap flow](https://github.com/favoursui/bagsflow/blob/main/frontend/build/js/swap.js): swap module · Connects wallets, requests quotes, signs transactions, and shows Solscan links. · `frontend/build/js/swap.js`
- **Browser wallet**: wallet extension · Signs swap transactions client-side.

### FastAPI backend

- [FastAPI application](https://github.com/favoursui/bagsflow/blob/main/backend/app/main.py): application lifecycle · Registers routes and starts launch polling and real-time streaming. · `backend/app/main.py`
- [Backend runner](https://github.com/favoursui/bagsflow/blob/main/backend/run.py): uvicorn entry point · `backend/run.py`
- [Route registration](https://github.com/favoursui/bagsflow/blob/main/backend/app/api/routes.py): HTTP route boundary · `backend/app/api/routes.py`
- [Token API](https://github.com/favoursui/bagsflow/blob/main/backend/app/api/tokens.py): token endpoints · Validates addresses and retrieves token metadata and quotes. · `backend/app/api/tokens.py`
- [Swap API](https://github.com/favoursui/bagsflow/blob/main/backend/app/api/swap.py): swap endpoints · Brokers executable swap transactions and submission flow. · `backend/app/api/swap.py`
- [Analytics API](https://github.com/favoursui/bagsflow/blob/main/backend/app/api/analytics.py): analytics endpoints · Exposes aggregated session-facing data. · `backend/app/api/analytics.py`
- [Trade stream processor](https://github.com/favoursui/bagsflow/blob/main/backend/app/services/bitquery.py): Helius log stream · Subscribes, parses, enriches, and classifies Bags/Meteora trades. · `backend/app/services/bitquery.py`
- [Dashboard WebSocket hub](https://github.com/favoursui/bagsflow/blob/main/backend/app/core/websocket.py): event distribution · Broadcasts trade events to connected dashboard clients. · `backend/app/core/websocket.py`

### Chain & trading providers

- [Bags.fm API](https://github.com/favoursui/bagsflow/blob/main/backend/app/services/bags.py): trading provider · `backend/app/services/bags.py`
- [Helius RPC, DAS & WebSocket](https://github.com/favoursui/bagsflow/blob/main/backend/app/services/helius.py): chain provider · `backend/app/services/helius.py`
- **Solana mainnet**: blockchain network · Includes Meteora DAMM v2 liquidity and routing.

### Other components

- [Nginx reverse proxy](https://github.com/favoursui/bagsflow/blob/main/nginx.conf): edge proxy · Serves the static UI and proxies API and WebSocket traffic. · `nginx.conf`

## Connections

- Nginx reverse proxy → Static dashboard: serves static assets
- Static dashboard → Live dashboard: loads
- Static dashboard → Wallet swap flow: loads
- Live dashboard → Nginx reverse proxy: HTTP API and /ws
- Wallet swap flow → Nginx reverse proxy: swap and token API
- Wallet swap flow → Browser wallet: requests transaction signature
- Nginx reverse proxy → FastAPI application: proxies /api and /ws
- Backend runner → FastAPI application: runs
- FastAPI application → Route registration: registers
- Route registration → Token API: routes requests
- Route registration → Swap API: routes requests
- Route registration → Analytics API: routes requests
- FastAPI application → Trade stream processor: starts
- Trade stream processor → Dashboard WebSocket hub: trade events
- Dashboard WebSocket hub → Live dashboard: live events
- Token API → Bags.fm API: token data and quotes
- Swap API → Bags.fm API: swap transactions
- Token API → Helius RPC, DAS & WebSocket: token metadata
- Trade stream processor → Helius RPC, DAS & WebSocket: program-log subscription
- Helius RPC, DAS & WebSocket → Solana mainnet: RPC and chain data
- Browser wallet → Solana mainnet: submits signed swaps
