# tekniktjek/fullstack-trading-app architecture

> Architecture diagram of the GitHub repository tekniktjek/fullstack-trading-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tekniktjek/fullstack-trading-app
- Repository: https://github.com/tekniktjek/fullstack-trading-app

## Overview

##### Project Type and Purpose
- This is a full-stack Python trading application that uses the Alpaca API for live trading and historical data access.
- It includes data-ingestion scripts to populate minute-level price data into a relational database, a backtesting module, and (implied) a user-facing UI.

##### Main Components
a. Frontend (Web UI)
- Could be implemented in HTML/CSS/JavaScript or a framework like React/Vue.
- Presents real-time quotes, trading dashboard, backtest results, and trade execution controls.
b. Backend API (Python)
- Exposes REST or WebSocket endpoints for the frontend.
- Routes user actions (e.g., place order, request historical data, start backtest).
- Coordinates with the Alpaca SDK for market data and order execution.
c. Data Ingestion Scripts
- populate_stock_minute_table.py: reads CSV (qqq.csv) or Alpaca’s historical data endpoints, and loads into the SQL schema defined in stock_price_minute_table.sql.
- backtest.py: imports minute-level data from the database, runs strategy simulations, and outputs performance metrics.
d. Database (PostgreSQL/MySQL/SQLite)
- Holds the minute price table and any user/trade history.
- Defined by stock_price_minute_table.sql.
e. External Services
- Alpaca API (market data, order execution).

##### Relationships and Data Flows
- User → Frontend: interacts via browser.
- Frontend → Backend API: HTTP/WS calls.
- Backend → Database: CRUD queries for price data, backtest results, trade logs.
- Backend → Alpaca API: market data requests and order submissions.
- Data Ingestion Script → Database: batch import of historical minute data.
- Backtest Script → Database: reads historical data; → Backend or local output.

##### Architectural Patterns and Design Principles
- 3-Tier (Presentation, Application, Data).
- Separation of concerns: ingestion, backtesting, trading execution, and UI are distinct modules.
- Single responsibility: each Python script has a clear role.
- Potential to evolve into microservices (e.g., separate container for ingestion, backtest, order execution).

- Frontend (e.g., blue rectangle)
- Backend API (green rectangle)
1. Browser / Frontend
2. Python Backend (API server)
3. Database (minute price table)
4. Alpaca API (external)
5. Data Ingestion Script
6. Backtest Script
- Frontend → Backend: “HTTP/WS calls”
- Backend → Database: “SELECT/INSERT price & trade data”
- Backend → Alpaca API: “GET historical data / POST order”
- Ingestion Script → Database: “Bulk insert minute-level data”
- Backtest Script → Database: “Read historical data” → “Write results”
d. Technologies
- Frontend: HTML/CSS/JavaScript or React
- Backend: Python (Flask/FastAPI)
- DB: PostgreSQL (or SQLite for local dev)
- Alpaca Python SDK
- Scripts: standalone Python modules

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client"
        Browser["Web Browser"]:::frontend
    end

    subgraph "Frontend Layer"
        Frontend["Web UI (React/HTML/CSS/JS)"]:::frontend
    end

    subgraph "Backend Services"
        API["Backend API (Flask/FastAPI)"]:::backend
        Ingest["Data Ingestion Script"]:::script
        Backtest["Backtest Script"]:::script
    end

    subgraph "Data Store"
        DB["Database (PostgreSQL)"]:::database
        Schema["Schema Definition"]:::database
    end

    External["Alpaca API"]:::external
    QCSV["qqq.csv"]:::script
    DocGroup["Project Files"]:::script
    Readme["README.md"]:::script
    Gitignore[".gitignore"]:::script

    Browser -->|"HTTP/WS calls"| API
    Frontend -->|"HTTP/WS calls"| API
    API -->|"SELECT/INSERT price & trade data"| DB
    API -->|"GET historical data / POST order"| External
    Ingest -->|"Reads CSV / Historical API"| DB
    Ingest --> QCSV
    Backtest -->|"Read historical data"| DB
    Backtest -->|"Write results"| DB

    DocGroup --> Readme
    DocGroup --> Gitignore

    click Ingest "https://github.com/tekniktjek/fullstack-trading-app/blob/main/populate_stock_minute_table.py"
    click Backtest "https://github.com/tekniktjek/fullstack-trading-app/blob/main/backtest.py"
    click Schema "https://github.com/tekniktjek/fullstack-trading-app/blob/main/stock_price_minute_table.sql"
    click QCSV "https://github.com/tekniktjek/fullstack-trading-app/blob/main/qqq.csv"
    click Readme "https://github.com/tekniktjek/fullstack-trading-app/blob/main/README.md"
    click Gitignore "https://github.com/tekniktjek/fullstack-trading-app/blob/main/.gitignore"

    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px;
    classDef backend fill:#D0FFD0,stroke:#333,stroke-width:1px;
    classDef database fill:#FFE0B2,stroke:#333,stroke-width:1px;
    classDef external fill:#E1BEE7,stroke:#333,stroke-width:1px;
    classDef script fill:#E0E0E0,stroke:#333,stroke-width:1px;
```
