# stackoverflowed512/data_analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/stackoverflowed512/data_analyzer
- Repository: https://github.com/stackoverflowed512/data_analyzer

## Overview

1. This is a two-tier application: a React single-page frontend in `frontend/` and a Flask-based Python backend in `backend/`. The frontend handles user interaction and visualization; the backend owns all data analysis, AI calls, and chart generation.

2. The main user flow starts in the frontend UI (`App.tsx` plus components like `EnhancedQueryInterface`, `DatasetSelector`, `FileUploader`, `DatasetPreview`, `QueryHistory`, and `ChartTypeSelector`). These components let a user pick or upload a dataset, enter a natural-language question, inspect results, and review prior queries.

3. Frontend-to-backend communication is centralized in `frontend/src/services/api.ts`. That service layer is the boundary between the browser app and the Flask API, which keeps the UI dumb and makes the backend the single place where data processing and Mistral requests happen.

4. The backend exposes REST endpoints in `api_server.py` for health checking, initialization, dataset metadata, analysis, downloads, and example queries. This suggests a request/response architecture where the frontend sends a query and dataset context, and the backend returns both analysis output and chart-ready results.

5. The backend’s core pipeline is split into three responsibilities under `backend/src/`:
   - `data_processor.py` for reading, cleaning, summarizing, and aggregating tabular data with Pandas
   - `llm_client.py` for calling the Mistral AI chat-completions API using environment-configured credentials
   - `chart_generator.py` for turning analysis results into an appropriate visualization, likely supporting multiple chart types

6. The AI integration is a key architectural boundary: the frontend does not talk to Mistral directly. The backend protects the API key and uses Mistral to interpret the natural-language query, infer relevant columns, and decide how to structure the analysis or visualization.

7. Visualization is a dual-path concern. The README and file layout indicate support for both Plotly and Matplotlib, while the frontend includes Plotly-related typings and chart UI components. In practice, the backend likely returns chart data/configuration, and the frontend renders it interactively.

8. Data sources are local and file-based. The repo ships sample CSVs such as `backend/data/automobile.csv` and `sales_data_sample.csv`, plus a bundled SQLite database file `backend/data/app_database.db`. That points to a local analysis workflow with optional persisted state or cached metadata, rather than a cloud database dependency.

9. There is also a non-web entrypoint in `backend/app.py`, which likely reuses the same backend modules for command-line or standalone execution. So the backend is not just an API layer; it is the shared analysis engine for both HTTP and CLI usage.

10. Configuration is environment-driven. `backend/config/settings.py`, the `.env.example` files, and the README’s Mistral variables show that API credentials and model selection are externalized. This is important for deployment because the app can run locally or in hosted environments without code changes.

11. The repository includes deployment artifacts (`Procfile`, `render.yaml`, and `frontend/RENDER_INSTRUCTIONS.md`), indicating it is designed for a hosted deployment where the frontend is built separately and the Flask backend is served as an API process.

12. For an architecture diagram, the clearest boundaries are: user/browser UI, frontend service layer, Flask API, backend analysis/LLM/chart pipeline, and local data assets. The main data flow is: user query + dataset selection -> backend analysis -> Mistral interpretation + Pandas processing -> chart/result generation -> frontend rendering/download.

Main entry points: [`backend/api_server.py`](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/api_server.py) (Flask API), [`frontend/src/App.tsx`](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/App.tsx) (App shell), [`backend/src/data_processor.py`](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/data_processor.py) (Data processor), [`frontend/src/services/api.ts`](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/services/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>React SPA<br/>[App.tsx]"]
  node_frontend_query["Query UI<br/>React component"]
  node_frontend_dataset["Dataset picker<br/>React component"]
  node_frontend_history["History panel<br/>React component<br/>[QueryHistory.tsx]"]
  node_frontend_chart["Chart chooser<br/>React component"]
  node_frontend_api["API client<br/>service layer<br/>[api.ts]"]
  node_frontend_plotly["Plot types<br/>frontend typing<br/>[react-plotly.d.ts]"]
end

subgraph group_backend["Backend"]
  node_backend_server["Flask API<br/>HTTP server<br/>[api_server.py]"]
  node_backend_entry["CLI entry<br/>app entrypoint<br/>[app.py]"]
  node_backend_settings["Settings<br/>config<br/>[settings.py]"]
  node_backend_data["Data processor<br/>analysis module<br/>[data_processor.py]"]
  node_backend_llm["Mistral client<br/>AI integration<br/>[llm_client.py]"]
  node_backend_chart["Chart engine<br/>visualization module<br/>[chart_generator.py]"]
end

subgraph group_data["Data"]
  node_data_csv[("Sample CSVs<br/>dataset<br/>[automobile.csv]")]
  node_data_db[("SQLite store<br/>database<br/>[app_database.db]")]
end

subgraph group_deploy["Deployment"]
  node_backend_env["Env files<br/>runtime config<br/>[.env.example]"]
  node_deploy_render["Render config<br/>deployment manifest<br/>[render.yaml]"]
  node_deploy_procfile["Procfile<br/>deployment manifest"]
end

node_frontend_app -->|"drives"| node_frontend_query
node_frontend_app -->|"drives"| node_frontend_dataset
node_frontend_app -->|"drives"| node_frontend_history
node_frontend_app -->|"drives"| node_frontend_chart
node_frontend_query -->|"requests"| node_frontend_api
node_frontend_dataset -->|"uploads"| node_frontend_api
node_frontend_history -->|"loads"| node_frontend_api
node_frontend_chart -->|"renders with"| node_frontend_plotly
node_frontend_api -->|"calls"| node_backend_server
node_backend_server -->|"analyzes"| node_backend_data
node_backend_server -->|"interprets"| node_backend_llm
node_backend_server -->|"builds charts"| node_backend_chart
node_backend_server -->|"reads config"| node_backend_settings
node_backend_entry -->|"reuses"| node_backend_data
node_backend_entry -->|"reuses"| node_backend_llm
node_backend_entry -->|"reuses"| node_backend_chart
node_backend_data -->|"reads"| node_data_csv
node_backend_data -->|"reads/writes"| node_data_db
node_backend_llm -->|"configured by"| node_backend_env
node_backend_server -->|"deployed with"| node_deploy_render
node_backend_server -->|"started by"| node_deploy_procfile

click node_frontend_app "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/App.tsx"
click node_frontend_query "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/EnhancedQueryInterface.tsx"
click node_frontend_dataset "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/DatasetSelector.tsx"
click node_frontend_history "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/QueryHistory.tsx"
click node_frontend_chart "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/ChartTypeSelector.tsx"
click node_frontend_api "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/services/api.ts"
click node_frontend_plotly "https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/types/react-plotly.d.ts"
click node_backend_server "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/api_server.py"
click node_backend_entry "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/app.py"
click node_backend_settings "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/config/settings.py"
click node_backend_data "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/data_processor.py"
click node_backend_llm "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/llm_client.py"
click node_backend_chart "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/chart_generator.py"
click node_backend_env "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/.env.example"
click node_deploy_render "https://github.com/stackoverflowed512/data_analyzer/blob/main/render.yaml"
click node_deploy_procfile "https://github.com/stackoverflowed512/data_analyzer/tree/main/Procfile"
click node_data_csv "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/data/automobile.csv"
click node_data_db "https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/data/app_database.db"

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_app,node_frontend_query,node_frontend_dataset,node_frontend_history,node_frontend_chart,node_frontend_api,node_frontend_plotly toneBlue
class node_backend_server,node_backend_entry,node_backend_settings,node_backend_data,node_backend_llm,node_backend_chart toneAmber
class node_data_csv,node_data_db toneMint
class node_backend_env,node_deploy_render,node_deploy_procfile toneRose
```

## Components

### Frontend

React SPA and browser-side interaction layer

- [App shell](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/App.tsx): React SPA · Top-level browser application and user flow orchestration · `frontend/src/App.tsx`
- [Query UI](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/EnhancedQueryInterface.tsx): React component · Natural-language query input and analysis controls · `frontend/src/components/EnhancedQueryInterface.tsx`
- [Dataset picker](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/DatasetSelector.tsx): React component · Selects, uploads, and previews tabular datasets · `frontend/src/components/DatasetSelector.tsx`
- [History panel](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/QueryHistory.tsx): React component · Shows prior questions and saved interactions · `frontend/src/components/QueryHistory.tsx`
- [Chart chooser](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/components/ChartTypeSelector.tsx): React component · Lets the user switch visualization types · `frontend/src/components/ChartTypeSelector.tsx`
- [API client](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/services/api.ts): service layer · Central browser-to-backend request boundary · `frontend/src/services/api.ts`
- [Plot types](https://github.com/stackoverflowed512/data_analyzer/blob/main/frontend/src/types/react-plotly.d.ts): frontend typing · Chart-related typings for interactive rendering · `frontend/src/types/react-plotly.d.ts`

### Backend

Flask API and analysis pipeline

- [Flask API](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/api_server.py): HTTP server · REST endpoints for health, init, analysis, downloads, and examples · `backend/api_server.py`
- [CLI entry](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/app.py): app entrypoint · Standalone execution path that reuses backend modules · `backend/app.py`
- [Settings](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/config/settings.py): config · Environment-driven configuration for models and credentials · `backend/config/settings.py`
- [Data processor](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/data_processor.py): analysis module · Reads, cleans, summarizes, and aggregates tabular data · `backend/src/data_processor.py`
- [Mistral client](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/llm_client.py): AI integration · Calls the chat-completions API to interpret queries · `backend/src/llm_client.py`
- [Chart engine](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/src/chart_generator.py): visualization module · Converts analysis results into chart-ready output · `backend/src/chart_generator.py`

### Data

Bundled local datasets and persistent storage

- [Sample CSVs](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/data/automobile.csv): dataset · Bundled example tabular inputs for analysis · `backend/data/automobile.csv`
- [SQLite store](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/data/app_database.db): database · Bundled local database for persisted app data or metadata · `backend/data/app_database.db`

### Deployment

Hosting and runtime configuration

- [Env files](https://github.com/stackoverflowed512/data_analyzer/blob/main/backend/.env.example): runtime config · Example environment variables and deployment-time secrets · `backend/.env.example`
- [Render config](https://github.com/stackoverflowed512/data_analyzer/blob/main/render.yaml): deployment manifest · Process and hosting configuration for deployment · `render.yaml`
- [Procfile](https://github.com/stackoverflowed512/data_analyzer/tree/main/Procfile): deployment manifest · Process start command for hosted execution · `Procfile`

## Connections

- App shell → Query UI: drives · Main UI embeds the query experience
- App shell → Dataset picker: drives · Main UI embeds dataset selection and upload
- App shell → History panel: drives · Main UI shows prior queries
- App shell → Chart chooser: drives · Main UI controls visualization choice
- Query UI → API client: requests · Sends user question and dataset context to backend
- Dataset picker → API client: uploads · Transfers dataset selection and file data through the client layer
- History panel → API client: loads · Fetches or replays prior query state
- Chart chooser → Plot types: renders with · Interactive chart rendering uses Plotly-compatible types
- API client → Flask API: calls · Browser service layer communicates with Flask endpoints
- Flask API → Data processor: analyzes · API routes delegate tabular processing to the data pipeline
- Flask API → Mistral client: interprets · API routes invoke Mistral for query understanding
- Flask API → Chart engine: builds charts · API routes return chart-ready output from analysis results
- Flask API → Settings: reads config · Server loads environment-based settings
- CLI entry → Data processor: reuses · CLI entry shares the same analysis engine
- CLI entry → Mistral client: reuses · Standalone execution can still call the model client
- CLI entry → Chart engine: reuses · Standalone execution can produce visual outputs
- Data processor → Sample CSVs: reads · Processes bundled CSV datasets
- Data processor → SQLite store: reads/writes · May persist or retrieve local application data
- Mistral client → Env files: configured by · API credentials and model selection come from environment files
- Flask API → Render config: deployed with · Hosted runtime is defined by deployment manifest
- Flask API → Procfile: started by · Process entry is defined for deployment
