# yasuo-kouki/stock-web-project architecture

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

- Interactive diagram: https://gitdiagram.com/yasuo-kouki/stock-web-project
- Repository: https://github.com/yasuo-kouki/stock-web-project

## Overview

1. **System shape**
   - This repo is a split-client/split-server stock analysis app.
   - The browser UI is a Next.js/React frontend; the API is a separate FastAPI service in Python.
   - The backend persists state in SQLite and calls OpenAI for prediction generation.

2. **Frontend boundary**
   - The documented frontend lives under `frontend/` and is a TypeScript Next.js app with React components and CSS/Tailwind-style styling.
   - It contains presentation components like `components/Chart.tsx` and `components/StockChart.tsx`, which are the main visualization layer for stock time series.
   - `pages/_app.tsx` and `pages/index.tsx` indicate a Pages Router-based client in this directory.

3. **Additional top-level Next.js app**
   - The repo root also contains an `app/` directory plus `public/` and `stocks.db`.
   - That suggests a second Next.js app shell or a migration artifact alongside the `frontend/` app.
   - For architecture diagrams, treat this as an overlapping front-end surface rather than a separate backend service.

4. **Backend service**
   - The backend is in `backend/main.py` and is the system’s API and business-logic entry point.
   - It exposes at least two HTTP endpoints: `POST /download_stock` and `POST /predict`.
   - `download_stock` fetches and returns stock data; `predict` runs a prediction flow using OpenAI.

5. **Data layer**
   - The backend uses SQLite, with database files present as `backend/stocks.db` and a root-level `stocks.db`.
   - This indicates local persistent storage for stock history and/or cached results rather than a remote database service.
   - The DB sits behind the FastAPI boundary and is not accessed directly by the frontend.

6. **External integrations**
   - OpenAI API is a core external dependency for the prediction path.
   - The stock data acquisition path is server-side as well, so the browser never talks directly to market-data providers.
   - This keeps secrets and data-fetching logic inside the backend.

7. **Request/response flow**
   - User actions in the frontend trigger HTTP requests to the backend at the URL configured by `NEXT_PUBLIC_API_URL`.
   - The backend returns either raw stock data for charting or a textual prediction payload.
   - The chart components consume the returned time-series data to render the UI.

8. **Runtime and configuration boundaries**
   - Local development expects the frontend on port `3000` and the backend on `8000`.
   - Backend CORS is controlled by `CORS_ORIGINS`, allowing the frontend origin(s) to call the API.
   - Frontend API base URL is environment-driven, which is the main coupling point between the two tiers.

9. **Deployment and packaging**
   - The backend has a `Dockerfile` and `.dockerignore`, so it is intended to be containerized.
   - The repo also includes a GitHub Actions workflow under `.github/workflows/` and Azure-related docs, indicating Azure deployment automation.
   - The presence of both Docker artifacts and an Azure Static Web Apps workflow suggests mixed or evolving deployment paths.

10. **Repo-level structure to diagram**
   - Show three major blocks: frontend client, FastAPI backend, and SQLite storage.
   - Add an external dependency block for OpenAI, and optionally a stock-data source if you want to distinguish fetch vs predict flows.
   - Note the duplicate/overlapping Next.js app layouts (`frontend/` and root `app/`) as an implementation detail that may affect build/deploy boundaries.

Main entry points: [`frontend/pages/index.tsx`](https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/pages/index.tsx) (Frontend app), [`backend/main.py`](https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py) (FastAPI app), [`.github/workflows/azure-static-web-apps-victorious-pond-049969d00.yml`](https://github.com/yasuo-kouki/stock-web-project/blob/main/.github/workflows/azure-static-web-apps-victorious-pond-049969d00.yml) (Azure workflow), [`backend/stocks.db`](https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/stocks.db) (SQLite DB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend client"]
  node_frontend_shell["Frontend app<br/>Next.js pages app<br/>[index.tsx]"]
  node_frontend_app["App wrapper<br/>Next.js bootstrap<br/>[_app.tsx]"]
  node_chart["Chart<br/>visualization component<br/>[Chart.tsx]"]
  node_stockchart["Stock chart<br/>chart component<br/>[StockChart.tsx]"]
end

subgraph group_rootshell["Root app shell"]
  node_root_shell["Root app<br/>Next.js app router<br/>[page.tsx]"]
  node_root_layout["Layout<br/>App shell<br/>[layout.tsx]"]
  node_root_styles["Global styles<br/>CSS<br/>[globals.css]"]
end

subgraph group_backend["Backend API"]
  node_api["FastAPI app<br/>API service<br/>[main.py]"]
  node_download(("Download stock<br/>ingest endpoint<br/>[main.py]"))
  node_predict(("Predict<br/>analysis endpoint<br/>[main.py]"))
end

subgraph group_storage["Storage"]
  node_db[("SQLite DB<br/>local persistence<br/>[stocks.db]")]
  node_db_root[("DB copy<br/>local persistence<br/>[stocks.db]")]
end

subgraph group_external["External services"]
  node_openai{{"OpenAI<br/>LLM API"}}
  node_market{{"Market data<br/>data provider"}}
end

subgraph group_deploy["Deployment"]
  node_workflow["Azure workflow<br/>CI/CD workflow"]
  node_dockerfile["Dockerfile<br/>container build"]
  node_azure_docs["Azure docs<br/>deployment docs"]
end

node_frontend_shell -->|"HTTP requests"| node_api
node_frontend_app -->|"bootstraps"| node_frontend_shell
node_frontend_shell -->|"renders"| node_chart
node_frontend_shell -->|"renders"| node_stockchart
node_root_shell -->|"wraps"| node_root_layout
node_root_layout -->|"styles"| node_root_styles
node_api -->|"serves"| node_download
node_api -->|"serves"| node_predict
node_download -->|"fetches"| node_market
node_predict -->|"calls"| node_openai
node_download -->|"persists"| node_db
node_predict -->|"reads"| node_db
node_db_root -.->|"duplicate"| node_db
node_frontend_shell -.->|"overlaps"| node_root_shell
node_workflow -->|"deploys"| node_frontend_shell
node_workflow -->|"deploys"| node_api
node_dockerfile -->|"packages"| node_api
node_azure_docs -.->|"documents"| node_workflow

click node_frontend_shell "https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/pages/index.tsx"
click node_frontend_app "https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/pages/_app.tsx"
click node_chart "https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/components/Chart.tsx"
click node_stockchart "https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/components/StockChart.tsx"
click node_root_shell "https://github.com/yasuo-kouki/stock-web-project/blob/main/app/page.tsx"
click node_root_layout "https://github.com/yasuo-kouki/stock-web-project/blob/main/app/layout.tsx"
click node_root_styles "https://github.com/yasuo-kouki/stock-web-project/blob/main/app/globals.css"
click node_api "https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py"
click node_download "https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py"
click node_predict "https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py"
click node_db "https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/stocks.db"
click node_db_root "https://github.com/yasuo-kouki/stock-web-project/blob/main/stocks.db"
click node_workflow "https://github.com/yasuo-kouki/stock-web-project/blob/main/.github/workflows/azure-static-web-apps-victorious-pond-049969d00.yml"
click node_dockerfile "https://github.com/yasuo-kouki/stock-web-project/tree/main/backend/Dockerfile"
click node_azure_docs "https://github.com/yasuo-kouki/stock-web-project/blob/main/AZURE_DOCKER_DEPLOYMENT.md"

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_frontend_shell,node_frontend_app,node_chart,node_stockchart toneBlue
class node_root_shell,node_root_layout,node_root_styles toneAmber
class node_api,node_download,node_predict toneMint
class node_db,node_db_root toneRose
class node_openai,node_market toneIndigo
class node_workflow,node_dockerfile,node_azure_docs toneTeal
```

## Components

### Frontend client

Next.js/React UI under frontend/ for browsing stock data and triggering analysis.

- [Frontend app](https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/pages/index.tsx): Next.js pages app · Primary browser client with Pages Router entrypoints and shared UI. · `frontend/pages/index.tsx`
- [App wrapper](https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/pages/_app.tsx): Next.js bootstrap · Client bootstrap and global composition for the frontend app. · `frontend/pages/_app.tsx`
- [Chart](https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/components/Chart.tsx): visualization component · Renders stock time-series visuals. · `frontend/components/Chart.tsx`
- [Stock chart](https://github.com/yasuo-kouki/stock-web-project/blob/main/frontend/components/StockChart.tsx): chart component · Stock-specific chart presentation layer. · `frontend/components/StockChart.tsx`

### Root app shell

Top-level Next.js surface in app/ that overlaps with the frontend client boundary.

- [Root app](https://github.com/yasuo-kouki/stock-web-project/blob/main/app/page.tsx): Next.js app router · Overlapping top-level Next.js surface in the repository root. · `app/page.tsx`
- [Layout](https://github.com/yasuo-kouki/stock-web-project/blob/main/app/layout.tsx): App shell · Root app router layout and global frame. · `app/layout.tsx`
- [Global styles](https://github.com/yasuo-kouki/stock-web-project/blob/main/app/globals.css): CSS · Shared styling for the root app shell. · `app/globals.css`

### Backend API

FastAPI service that fetches data, persists state, and generates predictions.

- [FastAPI app](https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py): API service · Main backend entrypoint exposing stock download and prediction endpoints. · `backend/main.py`
- [Download stock](https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py): ingest endpoint · Server-side stock data acquisition and response path. · `backend/main.py`
- [Predict](https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/main.py): analysis endpoint · Prediction flow that produces model output for the UI. · `backend/main.py`

### Storage

Local SQLite persistence used by the backend.

- [SQLite DB](https://github.com/yasuo-kouki/stock-web-project/blob/main/backend/stocks.db): local persistence · File-backed storage for stock history or cached results. · `backend/stocks.db`
- [DB copy](https://github.com/yasuo-kouki/stock-web-project/blob/main/stocks.db): local persistence · Repository-root SQLite database artifact overlapping the backend store. · `stocks.db`

### External services

Third-party APIs the backend depends on.

- **OpenAI**: LLM API · External prediction dependency used by the backend.
- **Market data**: data provider · External stock-data source reached only from the backend.

### Deployment

Container and workflow artifacts for shipping the app.

- [Azure workflow](https://github.com/yasuo-kouki/stock-web-project/blob/main/.github/workflows/azure-static-web-apps-victorious-pond-049969d00.yml): CI/CD workflow · GitHub Actions automation for Azure deployment. · `.github/workflows/azure-static-web-apps-victorious-pond-049969d00.yml`
- [Dockerfile](https://github.com/yasuo-kouki/stock-web-project/tree/main/backend/Dockerfile): container build · Backend container packaging for local or cloud deployment. · `backend/Dockerfile`
- [Azure docs](https://github.com/yasuo-kouki/stock-web-project/blob/main/AZURE_DOCKER_DEPLOYMENT.md): deployment docs · Documentation for Azure-oriented deployment paths. · `AZURE_DOCKER_DEPLOYMENT.md`

## Connections

- Frontend app → FastAPI app: HTTP requests · Browser actions call the backend API configured by environment.
- App wrapper → Frontend app: bootstraps · Shared client setup wraps the page surface.
- Frontend app → Chart: renders · Main page feeds chart components with stock data.
- Frontend app → Stock chart: renders · Stock-specific visualization layer consumes the returned series.
- Root app → Layout: wraps · Root app router layout frames the overlapping Next.js surface.
- Layout → Global styles: styles · Layout applies global root styling.
- FastAPI app → Download stock: serves · Backend exposes stock download behavior through its main entrypoint.
- FastAPI app → Predict: serves · Backend exposes prediction behavior through its main entrypoint.
- Download stock → Market data: fetches · Stock acquisition is performed server-side against external sources.
- Predict → OpenAI: calls · Prediction generation depends on OpenAI.
- Download stock → SQLite DB: persists · Fetched or cached stock data is stored locally.
- Predict → SQLite DB: reads · Prediction flow uses local persisted history or cached state.
- DB copy → SQLite DB: duplicate · Repository contains overlapping SQLite database artifacts.
- Frontend app → Root app: overlaps · The repository has two Next.js surfaces that likely share build/deploy concerns.
- Azure workflow → Frontend app: deploys · CI workflow supports shipping the web client.
- Azure workflow → FastAPI app: deploys · CI workflow also suggests backend or integrated deployment automation.
- Dockerfile → FastAPI app: packages · Backend service is containerized for deployment.
- Azure docs → Azure workflow: documents · Docs describe the Azure deployment path and workflow usage.
