Architecture
iTrades Application Architecture
Technology Stack
Frontend
- Next.js
- React
- TypeScript
- Tailwind CSS
Application Hosting
- Vercel
Authentication
- Supabase Auth
Database
- PostgreSQL
- Supabase hosted PostgreSQL
ORM
- Prisma
File Storage
- Supabase Storage
Charting
- TradingView
High-Level Architecture
User Browser | v Next.js Application | +-- UI Components | +-- Server Components / Server Actions / API Routes | v Authentication Supabase Auth | v Application Services | +-- Trade Engine +-- P&L Calculation +-- Journal Services +-- Analytics | v Prisma | v PostgreSQL
External Services:
TradingView Supabase Storage Vercel
Primary Domain Structure
User | +-- Trading Accounts | | | +-- Trades | | | +-- Executions | +-- Trade Journal | +-- Screenshots | +-- Daily Journals | +-- Strategies | +-- Tags | +-- Settings
Architectural Principles
User Ownership
Every user-owned record must ultimately be attributable to an authenticated user.
Users must never be able to access another user's trading records.
Authorization must be enforced server-side and not only through UI filtering.
Accounts Are First-Class Entities
Trades must belong to a trading account.
Analytics may aggregate multiple accounts, but account-level attribution must remain available.
Trades and Executions Are Separate
A Trade represents the overall trading idea or position.
An Execution represents an individual transaction within that trade.
Example:
Trade: AAPL Long
Executions:
BUY 50 BUY 50 SELL 25 SELL 75
This allows scale-ins, scale-outs, partial closes, and accurate average pricing.
Asset Types Share a Common Trade Core
Equities, options, futures, forex, and cryptocurrency should share a common Trade model where possible.
Asset-specific information should extend the core trade rather than creating independent trading systems.
Calculations Have One Source of Truth
P&L calculations should be centralized rather than recreated independently on the dashboard, calendar, reports, and trade detail pages.
Time Is Important
Execution timestamps must preserve exact date and time.
Time zones must be handled intentionally because execution timestamps affect TradingView placement and daily P&L calculations.
Database Values vs Derived Values
Values that can reliably be calculated should not be independently editable in multiple locations.
Examples:
Average Entry — Derived Average Exit — Derived Gross P&L — Derived Net P&L — Derived
Inputs such as execution price, quantity, commission, and fees are stored.