# vinistan/tradeapp architecture

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

- Interactive diagram: https://gitdiagram.com/vinistan/tradeapp
- Repository: https://github.com/vinistan/tradeapp

## Overview

RFlekts is a leader–follower copy-trading platform. A leader connects a brokerage account; followers browse leaders, subscribe with sizing and risk settings, and connect execution accounts. Stream workers detect leader fills and invoke fanout, which checks eligibility and safety constraints, records durable order intent, and submits through broker adapters when the two-key execution gate is open. The graph also includes account, administration, and performance surfaces. Some API and worker internals were not sampled; dashed links mark unverified integration points, while documented product flows are cited to the README.

Main entry points: [`packages/copytrade/maxmar_copytrade/fanout.py`](https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/fanout.py) (Fill fanout), [`apps/web-trade/maxmar/web_trade/app/main.py`](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/main.py) (HTTP application), [`apps/web-trade-frontend/src/app/accounts/page.tsx`](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/accounts/page.tsx) (Account connections), [`apps/web-trade/maxmar/web_trade/app/api/leaders.py`](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/leaders.py) (Leader subscriptions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_webui["Trading interface"]
  node_accountui["Account connections<br/>[page.tsx]"]
  node_dashboardui["Follower dashboard<br/>[useDashboard.ts]"]
  node_authui["Sign-in flow<br/>[useSignIn.ts]"]
end

subgraph group_service["Application services"]
  node_api["HTTP application<br/>[main.py]"]
  node_leaderapi["Leader subscriptions<br/>[leaders.py]"]
  node_accountapi["Broker accounts API<br/>[accounts.py]"]
  node_controls["Execution controls"]
  node_auth["JWT authentication<br/>[deps.py]"]
end

subgraph group_execution["Copy execution"]
  node_tradierworker["Tradier stream<br/>[main.py]"]
  node_snapworker["SnapTrade poller<br/>[poller.py]"]
  node_webullworker["Webull stream<br/>[main.py]"]
  node_fanout["Fill fanout<br/>[fanout.py]"]
  node_constraints["Risk constraints<br/>[constraints.py]"]
  node_ledger["Position ledger<br/>[ledger.py]"]
  node_brokers["Broker adapters<br/>[base.py]"]
end

subgraph group_platform["Platform state"]
  node_postgres[("Trading database<br/>[mirrored_fill.py]")]
  node_leaderstate[("Leader profiles<br/>[leader_profile.py]")]
  node_subscriptionstate[("Subscriptions")]
  node_userstate[("User accounts<br/>[user.py]")]
  node_gate["Auto-execution gate"]
end

node_follower(("Follower"))
node_leader(("Leader"))
node_brokerage{{"Brokerage services"}}

node_follower -->|"browses leaders"| node_webui
node_follower -->|"connects accounts"| node_accountui
node_leader -->|"connects brokerage"| node_accountui
node_follower -.->|"signs in"| node_authui
node_webui -.->|"loads catalog"| node_leaderapi
node_accountui -.->|"links broker"| node_accountapi
node_dashboardui -.->|"requests dashboard"| node_api
node_authui -.->|"authenticates"| node_api
node_api -->|"routes requests"| node_leaderapi
node_api -->|"routes requests"| node_accountapi
node_api -->|"routes controls"| node_controls
node_leaderapi -.->|"manages subscriptions"| node_subscriptionstate
node_accountapi -.->|"manages accounts"| node_userstate
node_api -.->|"authenticates requests"| node_auth
node_tradierworker -->|"dispatches fills"| node_fanout
node_snapworker -.->|"dispatches fills"| node_fanout
node_webullworker -->|"dispatches fills"| node_fanout
node_fanout -->|"checks limits"| node_constraints
node_fanout -->|"loads positions"| node_ledger
node_fanout -->|"records outcomes"| node_postgres
node_fanout -->|"submits orders"| node_brokers
node_brokers -->|"places orders"| node_brokerage
node_fanout -->|"checks execution gate"| node_gate
node_controls -->|"attests execution"| node_gate
node_tradierworker -->|"discovers leaders"| node_leaderstate
node_fanout -->|"loads leader"| node_leaderstate
node_fanout -->|"selects followers"| node_subscriptionstate

click node_webui "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/leaders/useLeadersCatalog.ts"
click node_accountui "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/accounts/page.tsx"
click node_dashboardui "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/dashboard/useDashboard.ts"
click node_authui "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/sign-in/useSignIn.ts"
click node_api "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/main.py"
click node_leaderapi "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/leaders.py"
click node_accountapi "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/accounts.py"
click node_controls "https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/trading_controls.py"
click node_auth "https://github.com/vinistan/tradeapp/blob/main/packages/auth/maxmar_auth/deps.py"
click node_tradierworker "https://github.com/vinistan/tradeapp/blob/main/apps/workers/tradier-stream/maxmar/workers/tradier_stream/main.py"
click node_snapworker "https://github.com/vinistan/tradeapp/blob/main/apps/workers/snaptrade-stream/maxmar/workers/snaptrade_stream/poller.py"
click node_webullworker "https://github.com/vinistan/tradeapp/blob/main/apps/workers/webull-stream/maxmar/workers/webull_stream/main.py"
click node_fanout "https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/fanout.py"
click node_constraints "https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/constraints.py"
click node_ledger "https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/ledger.py"
click node_brokers "https://github.com/vinistan/tradeapp/blob/main/packages/brokers/maxmar_brokers/base.py"
click node_postgres "https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/copy_trader/mirrored_fill.py"
click node_leaderstate "https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/copy_trader/leader_profile.py"
click node_subscriptionstate "https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/copy_trader/leader_subscription.py"
click node_userstate "https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/accounts/user.py"
click node_gate "https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/execution_policy.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_webui,node_accountui,node_dashboardui,node_authui toneBlue
class node_api,node_leaderapi,node_accountapi,node_controls,node_auth toneAmber
class node_tradierworker,node_snapworker,node_webullworker,node_fanout,node_constraints,node_ledger,node_brokers toneMint
class node_postgres,node_leaderstate,node_subscriptionstate,node_userstate,node_gate toneRose
class node_follower,node_leader,node_brokerage toneIndigo
```

## Components

### User experience

- [Trading interface](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/leaders/useLeadersCatalog.ts): `apps/web-trade-frontend/src/app/leaders/useLeadersCatalog.ts`
- [Account connections](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/accounts/page.tsx): `apps/web-trade-frontend/src/app/accounts/page.tsx`
- [Follower dashboard](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/dashboard/useDashboard.ts): `apps/web-trade-frontend/src/app/dashboard/useDashboard.ts`
- [Sign-in flow](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade-frontend/src/app/sign-in/useSignIn.ts): `apps/web-trade-frontend/src/app/sign-in/useSignIn.ts`

### Application services

- [HTTP application](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/main.py): `apps/web-trade/maxmar/web_trade/app/main.py`
- [Leader subscriptions](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/leaders.py): `apps/web-trade/maxmar/web_trade/app/api/leaders.py`
- [Broker accounts API](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/accounts.py): `apps/web-trade/maxmar/web_trade/app/api/accounts.py`
- [Execution controls](https://github.com/vinistan/tradeapp/blob/main/apps/web-trade/maxmar/web_trade/app/api/trading_controls.py): `apps/web-trade/maxmar/web_trade/app/api/trading_controls.py`
- [JWT authentication](https://github.com/vinistan/tradeapp/blob/main/packages/auth/maxmar_auth/deps.py): `packages/auth/maxmar_auth/deps.py`

### Copy execution

- [Tradier stream](https://github.com/vinistan/tradeapp/blob/main/apps/workers/tradier-stream/maxmar/workers/tradier_stream/main.py): `apps/workers/tradier-stream/maxmar/workers/tradier_stream/main.py`
- [SnapTrade poller](https://github.com/vinistan/tradeapp/blob/main/apps/workers/snaptrade-stream/maxmar/workers/snaptrade_stream/poller.py): `apps/workers/snaptrade-stream/maxmar/workers/snaptrade_stream/poller.py`
- [Webull stream](https://github.com/vinistan/tradeapp/blob/main/apps/workers/webull-stream/maxmar/workers/webull_stream/main.py): `apps/workers/webull-stream/maxmar/workers/webull_stream/main.py`
- [Fill fanout](https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/fanout.py): `packages/copytrade/maxmar_copytrade/fanout.py`
- [Risk constraints](https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/constraints.py): `packages/copytrade/maxmar_copytrade/constraints.py`
- [Position ledger](https://github.com/vinistan/tradeapp/blob/main/packages/copytrade/maxmar_copytrade/ledger.py): `packages/copytrade/maxmar_copytrade/ledger.py`
- [Broker adapters](https://github.com/vinistan/tradeapp/blob/main/packages/brokers/maxmar_brokers/base.py): `packages/brokers/maxmar_brokers/base.py`

### Platform state

- [Trading database](https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/copy_trader/mirrored_fill.py): `packages/db/maxmar_db/models/copy_trader/mirrored_fill.py`
- [Leader profiles](https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/copy_trader/leader_profile.py): `packages/db/maxmar_db/models/copy_trader/leader_profile.py`
- [Subscriptions](https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/copy_trader/leader_subscription.py): `packages/db/maxmar_db/models/copy_trader/leader_subscription.py`
- [User accounts](https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/models/accounts/user.py): `packages/db/maxmar_db/models/accounts/user.py`
- [Auto-execution gate](https://github.com/vinistan/tradeapp/blob/main/packages/db/maxmar_db/execution_policy.py): `packages/db/maxmar_db/execution_policy.py`

### Other components

- **Follower**
- **Leader**
- **Brokerage services**

## Connections

- Follower → Trading interface: browses leaders
- Follower → Account connections: connects accounts
- Leader → Account connections: connects brokerage
- Follower → Sign-in flow: signs in
- Trading interface → Leader subscriptions: loads catalog
- Account connections → Broker accounts API: links broker
- Follower dashboard → HTTP application: requests dashboard
- Sign-in flow → HTTP application: authenticates
- HTTP application → Leader subscriptions: routes requests (evidence: `apps/web-trade/maxmar/web_trade/app/main.py`)
- HTTP application → Broker accounts API: routes requests (evidence: `apps/web-trade/maxmar/web_trade/app/main.py`)
- HTTP application → Execution controls: routes controls (evidence: `apps/web-trade/maxmar/web_trade/app/main.py`)
- Leader subscriptions → Subscriptions: manages subscriptions
- Broker accounts API → User accounts: manages accounts
- HTTP application → JWT authentication: authenticates requests
- Tradier stream → Fill fanout: dispatches fills (evidence: `apps/workers/tradier-stream/maxmar/workers/tradier_stream/main.py`)
- SnapTrade poller → Fill fanout: dispatches fills
- Webull stream → Fill fanout: dispatches fills (evidence: `apps/workers/webull-stream/maxmar/workers/webull_stream/main.py`)
- Fill fanout → Risk constraints: checks limits (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
- Fill fanout → Position ledger: loads positions (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
- Fill fanout → Trading database: records outcomes (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
- Fill fanout → Broker adapters: submits orders (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
- Broker adapters → Brokerage services: places orders
- Fill fanout → Auto-execution gate: checks execution gate (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
- Execution controls → Auto-execution gate: attests execution
- Tradier stream → Leader profiles: discovers leaders (evidence: `apps/workers/tradier-stream/maxmar/workers/tradier_stream/main.py`)
- Fill fanout → Leader profiles: loads leader (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
- Fill fanout → Subscriptions: selects followers (evidence: `packages/copytrade/maxmar_copytrade/fanout.py`)
