# pjh2558831-boop/chart architecture

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

- Interactive diagram: https://gitdiagram.com/pjh2558831-boop/chart
- Repository: https://github.com/pjh2558831-boop/chart

## Overview

ChartVision AI is a web product for uploading stock-chart images and receiving AI-generated technical analysis and trading reports. The main user flow runs from the homepage through the frontend API client and Next.js proxy to the Python analysis API, which processes the image, analyzes patterns and indicators, and assembles a report for display. The product also supports guest and Supabase-backed identity, usage limits, billing, saved analyses, and feedback. Backend orchestration and several repository relationships are supported by the source index; unsampled frontend and domain internals are represented conservatively.

Main entry points: [`backend/main.py`](https://github.com/pjh2558831-boop/chart/blob/main/backend/main.py) (Analysis API), [`app/page.tsx`](https://github.com/pjh2558831-boop/chart/blob/main/app/page.tsx) (Analysis homepage), [`backend/analysis_repository.py`](https://github.com/pjh2558831-boop/chart/blob/main/backend/analysis_repository.py) (Analysis history), [`lib/supabase.ts`](https://github.com/pjh2558831-boop/chart/blob/main/lib/supabase.ts) (Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_home["Analysis homepage<br/>[page.tsx]"]
  node_api_client["Analysis API client<br/>[api.ts]"]
  node_proxy_routes["API route handlers<br/>[route.ts]"]
  node_api_proxy["Backend proxy<br/>[apiProxy.ts]"]
  node_result_ui["Analysis result views<br/>[AnalysisResult.tsx]"]
end

subgraph group_identity["Identity and plans"]
  node_auth_context["Session context<br/>[AuthContext.tsx]"]
  node_auth_client["Supabase client<br/>[supabase.ts]"]
  node_login_flow["Login flow<br/>[auth.ts]"]
end

subgraph group_analysis["Chart analysis"]
  node_image_processing["Image processing"]
  node_ai_analysis["AI analysis<br/>[ai_analysis.py]"]
  node_pattern_analysis["Pattern analysis"]
  node_technical_analysis["Technical indicators"]
  node_market_data["Market data<br/>[market_data.py]"]
  node_visual_signal["Visual trade signal"]
  node_trading_report["Trading report<br/>[trading_report.py]"]
end

subgraph group_backend["Backend services"]
  node_usage_billing["Usage and billing<br/>[billing.py]"]
  node_backend_api["Analysis API<br/>[main.py]"]
  node_analysis_repo["Analysis history"]
  node_feedback_repo["Feedback records"]
  node_database[("SQLite database<br/>[database.py]")]
end

node_visitor(("Visitor"))
node_supabase_auth["Supabase Auth"]
node_supabase_store[("Supabase data")]

node_visitor -->|"uploads chart"| node_home
node_home -->|"requests analysis"| node_api_client
node_api_client -.->|"calls API route"| node_proxy_routes
node_proxy_routes -->|"delegates requests"| node_api_proxy
node_api_proxy -->|"forwards request"| node_backend_api
node_backend_api -->|"processes image"| node_image_processing
node_backend_api -->|"runs analysis"| node_ai_analysis
node_backend_api -->|"merges patterns"| node_pattern_analysis
node_backend_api -->|"requests indicators"| node_technical_analysis
node_backend_api -->|"requests market data"| node_market_data
node_backend_api -->|"generates signal"| node_visual_signal
node_backend_api -->|"builds report"| node_trading_report
node_backend_api -->|"checks usage"| node_usage_billing
node_backend_api -->|"reads and saves"| node_analysis_repo
node_backend_api -->|"records feedback"| node_feedback_repo
node_analysis_repo -->|"reads and writes"| node_database
node_analysis_repo -->|"replicates records"| node_supabase_store
node_feedback_repo -->|"uses storage"| node_database
node_home -->|"renders result"| node_result_ui
node_home -->|"uses session"| node_auth_context
node_auth_context -->|"reads auth state"| node_auth_client
node_login_flow -->|"starts OAuth"| node_auth_client
node_auth_client -.->|"authenticates user"| node_supabase_auth
node_usage_billing -->|"reads plan data"| node_supabase_store

click node_home "https://github.com/pjh2558831-boop/chart/blob/main/app/page.tsx"
click node_api_client "https://github.com/pjh2558831-boop/chart/blob/main/lib/api.ts"
click node_proxy_routes "https://github.com/pjh2558831-boop/chart/blob/main/app/api/analyze/route.ts"
click node_api_proxy "https://github.com/pjh2558831-boop/chart/blob/main/lib/apiProxy.ts"
click node_result_ui "https://github.com/pjh2558831-boop/chart/blob/main/components/AnalysisResult.tsx"
click node_auth_context "https://github.com/pjh2558831-boop/chart/blob/main/context/AuthContext.tsx"
click node_auth_client "https://github.com/pjh2558831-boop/chart/blob/main/lib/supabase.ts"
click node_login_flow "https://github.com/pjh2558831-boop/chart/blob/main/lib/auth.ts"
click node_usage_billing "https://github.com/pjh2558831-boop/chart/blob/main/backend/billing.py"
click node_backend_api "https://github.com/pjh2558831-boop/chart/blob/main/backend/main.py"
click node_image_processing "https://github.com/pjh2558831-boop/chart/blob/main/backend/image_processing.py"
click node_ai_analysis "https://github.com/pjh2558831-boop/chart/blob/main/backend/ai_analysis.py"
click node_pattern_analysis "https://github.com/pjh2558831-boop/chart/blob/main/backend/pattern_analysis.py"
click node_technical_analysis "https://github.com/pjh2558831-boop/chart/blob/main/backend/technical_analysis.py"
click node_market_data "https://github.com/pjh2558831-boop/chart/blob/main/backend/market_data.py"
click node_visual_signal "https://github.com/pjh2558831-boop/chart/blob/main/backend/visual_trade_signal.py"
click node_trading_report "https://github.com/pjh2558831-boop/chart/blob/main/backend/trading_report.py"
click node_analysis_repo "https://github.com/pjh2558831-boop/chart/blob/main/backend/analysis_repository.py"
click node_feedback_repo "https://github.com/pjh2558831-boop/chart/blob/main/backend/feedback_repository.py"
click node_database "https://github.com/pjh2558831-boop/chart/blob/main/backend/database.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_home,node_api_client,node_proxy_routes,node_api_proxy,node_result_ui toneBlue
class node_auth_context,node_auth_client,node_login_flow,node_supabase_store toneAmber
class node_image_processing,node_ai_analysis,node_pattern_analysis,node_technical_analysis,node_market_data,node_visual_signal,node_trading_report toneMint
class node_usage_billing,node_backend_api,node_analysis_repo,node_feedback_repo,node_database toneRose
class node_visitor,node_supabase_auth toneIndigo
```

## Components

### Web experience

- [Analysis homepage](https://github.com/pjh2558831-boop/chart/blob/main/app/page.tsx): `app/page.tsx`
- [Analysis API client](https://github.com/pjh2558831-boop/chart/blob/main/lib/api.ts): `lib/api.ts`
- [API route handlers](https://github.com/pjh2558831-boop/chart/blob/main/app/api/analyze/route.ts): `app/api/analyze/route.ts`
- [Backend proxy](https://github.com/pjh2558831-boop/chart/blob/main/lib/apiProxy.ts): `lib/apiProxy.ts`
- [Analysis result views](https://github.com/pjh2558831-boop/chart/blob/main/components/AnalysisResult.tsx): `components/AnalysisResult.tsx`

### Identity and plans

- [Session context](https://github.com/pjh2558831-boop/chart/blob/main/context/AuthContext.tsx): `context/AuthContext.tsx`
- [Supabase client](https://github.com/pjh2558831-boop/chart/blob/main/lib/supabase.ts): `lib/supabase.ts`
- [Login flow](https://github.com/pjh2558831-boop/chart/blob/main/lib/auth.ts): `lib/auth.ts`

### Chart analysis

- [Image processing](https://github.com/pjh2558831-boop/chart/blob/main/backend/image_processing.py): `backend/image_processing.py`
- [AI analysis](https://github.com/pjh2558831-boop/chart/blob/main/backend/ai_analysis.py): `backend/ai_analysis.py`
- [Pattern analysis](https://github.com/pjh2558831-boop/chart/blob/main/backend/pattern_analysis.py): `backend/pattern_analysis.py`
- [Technical indicators](https://github.com/pjh2558831-boop/chart/blob/main/backend/technical_analysis.py): `backend/technical_analysis.py`
- [Market data](https://github.com/pjh2558831-boop/chart/blob/main/backend/market_data.py): `backend/market_data.py`
- [Visual trade signal](https://github.com/pjh2558831-boop/chart/blob/main/backend/visual_trade_signal.py): `backend/visual_trade_signal.py`
- [Trading report](https://github.com/pjh2558831-boop/chart/blob/main/backend/trading_report.py): `backend/trading_report.py`

### Backend services

- [Usage and billing](https://github.com/pjh2558831-boop/chart/blob/main/backend/billing.py): `backend/billing.py`
- [Analysis API](https://github.com/pjh2558831-boop/chart/blob/main/backend/main.py): `backend/main.py`
- [Analysis history](https://github.com/pjh2558831-boop/chart/blob/main/backend/analysis_repository.py): `backend/analysis_repository.py`
- [Feedback records](https://github.com/pjh2558831-boop/chart/blob/main/backend/feedback_repository.py): `backend/feedback_repository.py`
- [SQLite database](https://github.com/pjh2558831-boop/chart/blob/main/backend/database.py): `backend/database.py`

### Other components

- **Visitor**
- **Supabase Auth**
- **Supabase data**

## Connections

- Visitor → Analysis homepage: uploads chart (evidence: `app/page.tsx`)
- Analysis homepage → Analysis API client: requests analysis (evidence: `app/page.tsx`)
- Analysis API client → API route handlers: calls API route
- API route handlers → Backend proxy: delegates requests (evidence: `app/api/analyze/route.ts`)
- Backend proxy → Analysis API: forwards request (evidence: `lib/apiProxy.ts`)
- Analysis API → Image processing: processes image (evidence: `backend/main.py`)
- Analysis API → AI analysis: runs analysis (evidence: `backend/main.py`)
- Analysis API → Pattern analysis: merges patterns (evidence: `backend/main.py`)
- Analysis API → Technical indicators: requests indicators (evidence: `backend/main.py`)
- Analysis API → Market data: requests market data (evidence: `backend/main.py`)
- Analysis API → Visual trade signal: generates signal (evidence: `backend/main.py`)
- Analysis API → Trading report: builds report (evidence: `backend/main.py`)
- Analysis API → Usage and billing: checks usage (evidence: `backend/main.py`)
- Analysis API → Analysis history: reads and saves (evidence: `backend/main.py`)
- Analysis API → Feedback records: records feedback (evidence: `backend/main.py`)
- Analysis history → SQLite database: reads and writes (evidence: `backend/analysis_repository.py`)
- Analysis history → Supabase data: replicates records (evidence: `backend/analysis_repository.py`)
- Feedback records → SQLite database: uses storage (evidence: `backend/feedback_repository.py`)
- Analysis homepage → Analysis result views: renders result (evidence: `app/page.tsx`)
- Analysis homepage → Session context: uses session (evidence: `app/page.tsx`)
- Session context → Supabase client: reads auth state (evidence: `context/AuthContext.tsx`)
- Login flow → Supabase client: starts OAuth (evidence: `lib/auth.ts`)
- Supabase client → Supabase Auth: authenticates user
- Usage and billing → Supabase data: reads plan data (evidence: `backend/billing.py`)
