# adilonam/itrade architecture

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

- Interactive diagram: https://gitdiagram.com/adilonam/itrade
- Repository: https://github.com/adilonam/itrade

## Overview

Trade Nova is a multi-tenant trading and investment platform with role-based navigation and shared authentication. Users enter through the dashboard, choose a trading room or investment workflow, and use API routes to retrieve or change account, market, and position data; scheduled jobs also refresh and close positions. The README documents stock, trading, investment, administration, and super-admin configuration capabilities. The tree also shows a distinct Polymarket-style prediction-market product. Several subsystem links use README documentation or indexed module references; unsampled route internals are not assumed.

Main entry points: [`src/components/layout/dashboard-layout-client.tsx`](https://github.com/adilonam/itrade/blob/main/src/components/layout/dashboard-layout-client.tsx) (Role-based dashboard), [`src/app/api/user/positions/route.ts`](https://github.com/adilonam/itrade/blob/main/src/app/api/user/positions/route.ts) (Position workflows), [`src/lib/prisma.ts`](https://github.com/adilonam/itrade/blob/main/src/lib/prisma.ts) (PostgreSQL database), [`src/app/api/schedule/close-positions/route.ts`](https://github.com/adilonam/itrade/blob/main/src/app/api/schedule/close-positions/route.ts) (Position scheduling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["App shell and identity"]
  node_dashboard["Role-based dashboard"]
  node_navigation["Tenant navigation<br/>[data.ts]"]
  node_auth["Shared authentication<br/>[auth.ts]"]
end

subgraph group_trading["Trading and market data"]
  node_trade_rooms["Trading rooms"]
  node_market_api["Market endpoints<br/>[route.ts]"]
  node_price_feed["Live price context"]
  node_ws_manager["WebSocket manager"]
  node_market_service["Market data service<br/>[twelvedata.ts]"]
  node_position_api["Position workflows<br/>[route.ts]"]
  node_position_jobs["Position scheduling<br/>[route.ts]"]
  node_trade_calcs["Trading calculations"]
end

subgraph group_invest["Invest and account"]
  node_invest_ui["Investment experience"]
  node_invest_api["Investment endpoints<br/>[route.ts]"]
  node_balance["Balance management<br/>[balance.ts]"]
  node_database[("PostgreSQL database<br/>[prisma.ts]")]
end

subgraph group_operations["Administration"]
  node_admin["Admin operations"]
  node_superadmin["Platform configuration"]
end

subgraph group_prediction["Prediction markets"]
  node_prediction_ui["Prediction market app<br/>[markets-page.tsx]"]
  node_prediction_api["Prediction market APIs"]
end

node_user(("Platform user"))
node_twelve_data["Twelve Data service"]

node_user -->|"opens"| node_dashboard
node_dashboard -->|"selects routes"| node_navigation
node_dashboard -->|"uses shared auth"| node_auth
node_dashboard -->|"renders"| node_trade_rooms
node_trade_rooms -.->|"requests markets"| node_market_api
node_dashboard -->|"provides live prices"| node_price_feed
node_price_feed -->|"connects and subscribes"| node_ws_manager
node_ws_manager -->|"opens WebSocket"| node_twelve_data
node_market_api -->|"loads quotes"| node_market_service
node_market_service -->|"fetches market data"| node_twelve_data
node_user -->|"places trades"| node_position_api
node_position_api -->|"checks session"| node_auth
node_position_api -->|"validates and values"| node_trade_calcs
node_position_api -->|"resolves funding"| node_balance
node_position_api -->|"reads and writes"| node_database
node_position_jobs -->|"calculates position PnL"| node_trade_calcs
node_position_jobs -->|"loads and closes positions"| node_database
node_user -->|"browses investments"| node_invest_ui
node_invest_ui -.->|"loads investment data"| node_invest_api
node_invest_api -.->|"persists investments"| node_database
node_user -->|"administers platform"| node_admin
node_admin -.->|"manages records"| node_database
node_superadmin -.->|"configures settings"| node_database
node_user -.->|"browses markets"| node_prediction_ui
node_prediction_ui -.->|"uses market APIs"| node_prediction_api

click node_dashboard "https://github.com/adilonam/itrade/blob/main/src/components/layout/dashboard-layout-client.tsx"
click node_navigation "https://github.com/adilonam/itrade/blob/main/src/constants/data.ts"
click node_auth "https://github.com/adilonam/itrade/blob/main/src/lib/auth.ts"
click node_trade_rooms "https://github.com/adilonam/itrade/blob/main/src/components/trading-room/trading-room-shell.tsx"
click node_market_api "https://github.com/adilonam/itrade/blob/main/src/app/api/markets/route.ts"
click node_price_feed "https://github.com/adilonam/itrade/blob/main/src/contexts/markets-websocket-context.tsx"
click node_ws_manager "https://github.com/adilonam/itrade/blob/main/src/lib/twelve-data-websocket-manager.ts"
click node_market_service "https://github.com/adilonam/itrade/blob/main/src/lib/twelvedata.ts"
click node_position_api "https://github.com/adilonam/itrade/blob/main/src/app/api/user/positions/route.ts"
click node_position_jobs "https://github.com/adilonam/itrade/blob/main/src/app/api/schedule/close-positions/route.ts"
click node_trade_calcs "https://github.com/adilonam/itrade/blob/main/src/lib/calculator-server.ts"
click node_invest_ui "https://github.com/adilonam/itrade/blob/main/src/components/investments/investment-details.tsx"
click node_invest_api "https://github.com/adilonam/itrade/blob/main/src/app/api/investments/route.ts"
click node_balance "https://github.com/adilonam/itrade/blob/main/src/lib/balance.ts"
click node_database "https://github.com/adilonam/itrade/blob/main/src/lib/prisma.ts"
click node_admin "https://github.com/adilonam/itrade/tree/main/src/app/api/admin"
click node_superadmin "https://github.com/adilonam/itrade/tree/main/src/app/api/super-admin"
click node_prediction_ui "https://github.com/adilonam/itrade/blob/main/src/components/polymarket/markets/markets-page.tsx"
click node_prediction_api "https://github.com/adilonam/itrade/tree/main/src/app/api/polymarket"

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_navigation,node_auth,node_user toneBlue
class node_trade_rooms,node_market_api,node_price_feed,node_ws_manager,node_market_service,node_position_api,node_position_jobs,node_trade_calcs toneAmber
class node_invest_ui,node_invest_api,node_balance,node_database toneMint
class node_admin,node_superadmin toneRose
class node_prediction_ui,node_prediction_api,node_twelve_data toneIndigo
```

## Components

### App shell and identity

- [Role-based dashboard](https://github.com/adilonam/itrade/blob/main/src/components/layout/dashboard-layout-client.tsx): `src/components/layout/dashboard-layout-client.tsx`
- [Tenant navigation](https://github.com/adilonam/itrade/blob/main/src/constants/data.ts): `src/constants/data.ts`
- [Shared authentication](https://github.com/adilonam/itrade/blob/main/src/lib/auth.ts): `src/lib/auth.ts`

### Trading and market data

- [Trading rooms](https://github.com/adilonam/itrade/blob/main/src/components/trading-room/trading-room-shell.tsx): `src/components/trading-room/trading-room-shell.tsx`
- [Market endpoints](https://github.com/adilonam/itrade/blob/main/src/app/api/markets/route.ts): `src/app/api/markets/route.ts`
- [Live price context](https://github.com/adilonam/itrade/blob/main/src/contexts/markets-websocket-context.tsx): `src/contexts/markets-websocket-context.tsx`
- [WebSocket manager](https://github.com/adilonam/itrade/blob/main/src/lib/twelve-data-websocket-manager.ts): `src/lib/twelve-data-websocket-manager.ts`
- [Market data service](https://github.com/adilonam/itrade/blob/main/src/lib/twelvedata.ts): `src/lib/twelvedata.ts`
- [Position workflows](https://github.com/adilonam/itrade/blob/main/src/app/api/user/positions/route.ts): `src/app/api/user/positions/route.ts`
- [Position scheduling](https://github.com/adilonam/itrade/blob/main/src/app/api/schedule/close-positions/route.ts): `src/app/api/schedule/close-positions/route.ts`
- [Trading calculations](https://github.com/adilonam/itrade/blob/main/src/lib/calculator-server.ts): `src/lib/calculator-server.ts`

### Invest and account

- [Investment experience](https://github.com/adilonam/itrade/blob/main/src/components/investments/investment-details.tsx): `src/components/investments/investment-details.tsx`
- [Investment endpoints](https://github.com/adilonam/itrade/blob/main/src/app/api/investments/route.ts): `src/app/api/investments/route.ts`
- [Balance management](https://github.com/adilonam/itrade/blob/main/src/lib/balance.ts): `src/lib/balance.ts`
- [PostgreSQL database](https://github.com/adilonam/itrade/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`

### Administration

- [Admin operations](https://github.com/adilonam/itrade/tree/main/src/app/api/admin): `src/app/api/admin`
- [Platform configuration](https://github.com/adilonam/itrade/tree/main/src/app/api/super-admin): `src/app/api/super-admin`

### Prediction markets

- [Prediction market app](https://github.com/adilonam/itrade/blob/main/src/components/polymarket/markets/markets-page.tsx): `src/components/polymarket/markets/markets-page.tsx`
- [Prediction market APIs](https://github.com/adilonam/itrade/tree/main/src/app/api/polymarket): `src/app/api/polymarket`

### Other components

- **Platform user**
- **Twelve Data service**

## Connections

- Platform user → Role-based dashboard: opens
- Role-based dashboard → Tenant navigation: selects routes
- Role-based dashboard → Shared authentication: uses shared auth
- Role-based dashboard → Trading rooms: renders (evidence: `src/components/layout/dashboard-layout-client.tsx`)
- Trading rooms → Market endpoints: requests markets
- Role-based dashboard → Live price context: provides live prices (evidence: `src/components/layout/dashboard-layout-client.tsx`)
- Live price context → WebSocket manager: connects and subscribes (evidence: `src/contexts/markets-websocket-context.tsx`)
- WebSocket manager → Twelve Data service: opens WebSocket (evidence: `src/lib/twelve-data-websocket-manager.ts`)
- Market endpoints → Market data service: loads quotes (evidence: `src/app/api/markets/route.ts`)
- Market data service → Twelve Data service: fetches market data (evidence: `src/lib/twelvedata.ts`)
- Platform user → Position workflows: places trades
- Position workflows → Shared authentication: checks session (evidence: `src/app/api/user/positions/route.ts`)
- Position workflows → Trading calculations: validates and values (evidence: `src/app/api/user/positions/route.ts`)
- Position workflows → Balance management: resolves funding (evidence: `src/app/api/user/positions/route.ts`)
- Position workflows → PostgreSQL database: reads and writes (evidence: `src/app/api/user/positions/route.ts`)
- Position scheduling → Trading calculations: calculates position PnL (evidence: `src/app/api/schedule/close-positions/route.ts`)
- Position scheduling → PostgreSQL database: loads and closes positions (evidence: `src/app/api/schedule/close-positions/route.ts`)
- Platform user → Investment experience: browses investments
- Investment experience → Investment endpoints: loads investment data
- Investment endpoints → PostgreSQL database: persists investments
- Platform user → Admin operations: administers platform
- Admin operations → PostgreSQL database: manages records (evidence: `src/app/api/admin/positions/route.ts`)
- Platform configuration → PostgreSQL database: configures settings
- Platform user → Prediction market app: browses markets
- Prediction market app → Prediction market APIs: uses market APIs
