docs / 03-database.md

Database

iTrades Database Design

Purpose

This document defines the application's data model before implementation in Prisma.

The Prisma schema should reflect the design documented here.


Entity Overview

User | +-- UserSettings | +-- TradingAccount | | | +-- Trade | | | +-- Execution | +-- TradeJournal | +-- TradeScreenshot | +-- DailyJournal | +-- Strategy | +-- Tag


User

Purpose

Represents an authenticated iTrades user.

Relationships

User has many TradingAccounts.

User has many DailyJournals.

User has many Strategies.

User has many Tags.

User has one UserSettings record.

Initial Fields

id email displayName createdAt updatedAt


TradingAccount

Purpose

Represents an individual brokerage, exchange, prop-firm, retirement, or other trading account.

Relationships

Belongs to User.

Has many Trades.

Initial Fields

id userId name broker accountType currency startingBalance isActive createdAt updatedAt


Trade

Purpose

Represents one logical trading position or trading idea.

A Trade may contain multiple executions.

Relationships

Belongs to User.

Belongs to TradingAccount.

Has many Executions.

May have one TradeJournal.

May have many Screenshots.

May have strategies and tags.

Initial Fields

id userId accountId symbol assetType direction status openedAt closedAt createdAt updatedAt


Execution

Purpose

Represents one individual fill or transaction associated with a Trade.

Examples

BUY 100 AAPL @ 210.00

SELL 50 AAPL @ 215.00

SELL 50 AAPL @ 217.00

Relationships

Belongs to Trade.

Initial Fields

id tradeId side quantity price commission fees executedAt createdAt updatedAt


TradeJournal

Purpose

Contains qualitative review information for an individual Trade.

Potential fields include:

tradeThesis entryReason exitReason whatWentWell mistakes lessonsLearned futureImprovement

Exact fields will be finalized before implementation.


DailyJournal

Purpose

Represents the user's trading journal for a calendar day independently of individual trades.

A daily journal may exist even when no trades occurred.

Potential fields:

date marketBias preMarketNotes goals postMarketReview lessons notes


Strategy

Purpose

Allows users to categorize trades by trading strategy.

Examples:

Breakout Opening Range VWAP Reclaim Momentum Reversal Swing

Strategies are user-defined.


Tag

Purpose

Allows flexible additional categorization without changing the database schema.

Examples:

FOMO A+ Setup News Overtrade Earnings High Volume