# ashwinssj/cardataset architecture

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

- Interactive diagram: https://gitdiagram.com/ashwinssj/cardataset
- Repository: https://github.com/ashwinssj/cardataset

## Overview

1. **Overall shape**
   - This repository is a two-tier telemetry analytics system: a **Flask/Python backend** for ingesting and classifying OBD-II CSV data, and a **React/Vite frontend** for interactive visualization and behavior monitoring.
   - The primary runtime boundary is **HTTP between frontend and backend**; the backend owns data processing, persistence, and ML inference.

2. **Frontend subsystem**
   - `frontend/` is a single-page app built with **React 18 + Vite**.
   - The UI appears centered around `src/App.jsx` and a chart component `src/components/TimeChart.jsx`, suggesting one main dashboard view with time-based analytics and snapshot metrics.
   - Styling is handled with local CSS files (`App.css`, `index.css`) and the README indicates a dark/glassmorphism presentation layer.

3. **Frontend responsibilities**
   - The frontend is responsible for **uploading CSV telemetry**, displaying **classification results**, and rendering **time-series charts** and summary ratios.
   - It does not appear to own business logic for prediction; it is a presentation and interaction layer consuming backend responses.

4. **Backend entrypoint and API layer**
   - `backend/main.py` is the likely Flask application entrypoint and API hub.
   - The backend is described as using **Flask-CORS**, so the API is designed to be called directly from the browser-based frontend without cross-origin friction.
   - This layer is the main integration point for file upload, telemetry analysis, and returning dashboard-ready JSON.

5. **Data processing and normalization**
   - `backend/preprocess_data.py` indicates a distinct preprocessing stage for cleaning and normalizing uploaded CSVs before they are analyzed or stored.
   - The README calls out timestamp resolution logic, including a fallback that anchors data to the current day when timestamps are missing, which suggests preprocessing is responsible for converting raw CSV rows into a time-aware session model.

6. **Machine learning inference path**
   - The backend integrates **pre-trained scikit-learn Random Forest models** for two classification tasks: **driving behavior** and **car health**.
   - The model artifacts are referenced in the README as `rf_behavior_model.pkl` and `rf_health_model.pkl`, implying inference happens server-side after preprocessing and before results are returned to the UI.

7. **Persistence and session history**
   - The README mentions **SQLite3 storage** with automated schema initialization, so the backend likely persists uploads, analysis results, or session metadata locally.
   - This creates a second data path beyond live inference: processed telemetry can be stored for date-wise filtering and historical analysis in the dashboard.

8. **Visualization model**
   - The frontend charting is based on **Recharts** and focuses on **time-anchored telemetry trends**.
   - The architecture therefore transforms raw OBD-II rows into a structure suitable for timeline visualization, with the backend controlling the timestamp semantics and the frontend only rendering the resulting series.

9. **Offline data assets and exploratory analysis**
   - The repository includes many labeled CSV files such as `idle*.csv`, `drive*.csv`, `live*.csv`, `long*.csv`, and `ufpe*.csv`, which look like collected telemetry datasets used for experimentation, validation, or model development.
   - `car_obd_analysis.ipynb` reinforces that part of the repo serves as an **offline analytics/training workspace**, separate from the production app path.

10. **Testing and validation**
   - `backend/test_up.py` suggests a lightweight backend validation or upload test script, likely used to exercise the ingestion/inference flow outside the browser.
   - This points to a development workflow where CSV datasets are used to validate preprocessing, prediction, and database writes independently of the frontend.

11. **Dependency and runtime boundaries**
   - Backend dependencies center on **Flask, Flask-CORS, Pandas, scikit-learn, joblib, and SQLite**; frontend dependencies center on **React, Vite, and Recharts**.
   - The system is therefore a local-first analytics application: Python handles compute and storage, while the browser handles interactivity and visualization.

12. **High-level data flow**
   - The main flow is: **CSV upload → backend preprocessing → ML classification + time resolution → optional SQLite persistence → JSON response → frontend charts and summary UI**.
   - The key architectural seam is the backend response contract: the UI depends on the server to return already-classified, time-structured telemetry rather than raw CSV rows.

Main entry points: [`frontend/src/App.jsx`](https://github.com/ashwinssj/cardataset/blob/main/frontend/src/App.jsx) (Dashboard), [`backend/main.py`](https://github.com/ashwinssj/cardataset/blob/main/backend/main.py) (API server), [`backend/preprocess_data.py`](https://github.com/ashwinssj/cardataset/blob/main/backend/preprocess_data.py) (Preprocess data), [`car_obd_analysis.ipynb`](https://github.com/ashwinssj/cardataset/blob/main/car_obd_analysis.ipynb) (Analysis notebook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_main["App shell<br/>React SPA entry<br/>[main.jsx]"]
  node_frontend_app["Dashboard<br/>React view<br/>[App.jsx]"]
  node_frontend_chart["Time chart<br/>Recharts component<br/>[TimeChart.jsx]"]
  node_frontend_styles["UI styles<br/>CSS presentation<br/>[App.css]"]
end

subgraph group_backend["Backend"]
  node_backend_main["API server<br/>Flask entrypoint<br/>[main.py]"]
  node_backend_preprocess["Preprocess data<br/>CSV normalization<br/>[preprocess_data.py]"]
  node_backend_inference{{"Classify telemetry<br/>ML inference"}}
  node_behavior_model(("Behavior model<br/>scikit-learn artifact"))
  node_health_model(("Health model<br/>scikit-learn artifact"))
  node_backend_store[("Session store<br/>SQLite persistence")]
  node_backend_test["Upload test<br/>Validation script<br/>[test_up.py]"]
end

subgraph group_data["Data Assets"]
  node_raw_csvs["Telemetry CSVs<br/>Sample datasets"]
  node_analysis_notebook["Analysis notebook<br/>Offline notebook"]
end

node_frontend_main -->|"renders"| node_frontend_app
node_frontend_app -->|"uses"| node_frontend_chart
node_frontend_app -->|"styled by"| node_frontend_styles
node_frontend_app -->|"API calls"| node_backend_main
node_backend_main -->|"normalizes"| node_backend_preprocess
node_backend_main -->|"invokes"| node_backend_inference
node_backend_inference -->|"loads"| node_behavior_model
node_backend_inference -->|"loads"| node_health_model
node_backend_preprocess -->|"persists"| node_backend_store
node_backend_inference -->|"records"| node_backend_store
node_backend_main -->|"returns JSON"| node_frontend_app
node_raw_csvs -->|"feeds"| node_backend_test
node_raw_csvs -->|"analyzed in"| node_analysis_notebook
node_analysis_notebook -.->|"trains"| node_behavior_model
node_analysis_notebook -.->|"trains"| node_health_model
node_backend_preprocess -.->|"structures data"| node_frontend_chart

click node_frontend_main "https://github.com/ashwinssj/cardataset/blob/main/frontend/src/main.jsx"
click node_frontend_app "https://github.com/ashwinssj/cardataset/blob/main/frontend/src/App.jsx"
click node_frontend_chart "https://github.com/ashwinssj/cardataset/blob/main/frontend/src/components/TimeChart.jsx"
click node_frontend_styles "https://github.com/ashwinssj/cardataset/blob/main/frontend/src/App.css"
click node_backend_main "https://github.com/ashwinssj/cardataset/blob/main/backend/main.py"
click node_backend_preprocess "https://github.com/ashwinssj/cardataset/blob/main/backend/preprocess_data.py"
click node_backend_test "https://github.com/ashwinssj/cardataset/blob/main/backend/test_up.py"
click node_analysis_notebook "https://github.com/ashwinssj/cardataset/blob/main/car_obd_analysis.ipynb"

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_main,node_frontend_app,node_frontend_chart,node_frontend_styles toneBlue
class node_backend_main,node_backend_preprocess,node_backend_inference,node_behavior_model,node_health_model,node_backend_store,node_backend_test toneAmber
class node_raw_csvs,node_analysis_notebook toneMint
```

## Components

### Frontend

React/Vite dashboard and visualization layer

- [App shell](https://github.com/ashwinssj/cardataset/blob/main/frontend/src/main.jsx): React SPA entry · Bootstraps the dashboard and overall client-side UI · `frontend/src/main.jsx`
- [Dashboard](https://github.com/ashwinssj/cardataset/blob/main/frontend/src/App.jsx): React view · Primary telemetry upload and results screen · `frontend/src/App.jsx`
- [Time chart](https://github.com/ashwinssj/cardataset/blob/main/frontend/src/components/TimeChart.jsx): Recharts component · Renders time-series telemetry and summary trends · `frontend/src/components/TimeChart.jsx`
- [UI styles](https://github.com/ashwinssj/cardataset/blob/main/frontend/src/App.css): CSS presentation · Local styling for the dashboard and page chrome · `frontend/src/App.css`

### Backend

Flask API, preprocessing, inference, and persistence

- [API server](https://github.com/ashwinssj/cardataset/blob/main/backend/main.py): Flask entrypoint · Hosts the HTTP API used by the browser app · `backend/main.py`
- [Preprocess data](https://github.com/ashwinssj/cardataset/blob/main/backend/preprocess_data.py): CSV normalization · Cleans uploads and resolves telemetry timestamps · `backend/preprocess_data.py`
- **Classify telemetry**: ML inference · Runs behavior and car-health prediction from uploaded data
- **Behavior model**: scikit-learn artifact · Pretrained random forest for driving behavior
- **Health model**: scikit-learn artifact · Pretrained random forest for car health
- **Session store**: SQLite persistence · Stores analysis history and processed upload metadata
- [Upload test](https://github.com/ashwinssj/cardataset/blob/main/backend/test_up.py): Validation script · Exercises ingestion and prediction flow outside the UI · `backend/test_up.py`

### Data Assets

CSV datasets and offline analysis materials

- **Telemetry CSVs**: Sample datasets · Collected OBD-II data used for analysis and validation
- [Analysis notebook](https://github.com/ashwinssj/cardataset/blob/main/car_obd_analysis.ipynb): Offline notebook · Exploratory analysis and model development workspace · `car_obd_analysis.ipynb`

## Connections

- App shell → Dashboard: renders · Client entry mounts the main dashboard view
- Dashboard → Time chart: uses · Dashboard delegates telemetry plotting to the chart component
- Dashboard → UI styles: styled by · Dashboard presentation is controlled by local CSS
- Dashboard → API server: API calls · Uploads and dashboard requests go over HTTP
- API server → Preprocess data: normalizes · Incoming CSV payloads are cleaned before analysis
- API server → Classify telemetry: invokes · API orchestrates classification after preprocessing
- Classify telemetry → Behavior model: loads · Behavior predictions use the pretrained model artifact
- Classify telemetry → Health model: loads · Health predictions use the pretrained model artifact
- Preprocess data → Session store: persists · Processed sessions and history are written to local storage
- Classify telemetry → Session store: records · Prediction results may be saved for later filtering and review
- API server → Dashboard: returns JSON · Server responds with classified, time-structured telemetry
- Telemetry CSVs → Upload test: feeds · Sample CSVs are used to validate the upload path
- Telemetry CSVs → Analysis notebook: analyzed in · Offline datasets support experimentation and model work
- Analysis notebook → Behavior model: trains · Notebook likely contributes to the behavior classifier
- Analysis notebook → Health model: trains · Notebook likely contributes to the health classifier
- Preprocess data → Time chart: structures data · Timestamp resolution and normalization prepare series for visualization
