# neowave2307/carbon-footprint-tracker architecture

> Architecture diagram of the GitHub repository neowave2307/carbon-footprint-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neowave2307/carbon-footprint-tracker
- Repository: https://github.com/neowave2307/carbon-footprint-tracker

## Overview

##### Project Type and Purpose
- This is a lightweight full-stack web application (“Carbon Footprint Tracker”) whose goal is to ingest raw user activity data, persist it, then run three core analytics routines (impact ranking, historical trend, eco-suggestions) before exposing results in a browser.

##### File Structure Analysis
Top-level files and directories:
- README.md – describes purpose, tech stack, algorithms
- app.py – Flask REST API entry point
- index.html – front-end client UI
- bst.py – Binary Search Tree implementation for historical trends
- trie.py – Prefix Tree implementation for eco-suggestions
- bst.py, trie.py, bst.py – custom data-structure modules
- __pycache__ – compiled Python artifacts

No separate “frontend/” or “backend/” folders, but the division is clear: index.html is the client; app.py + Python modules form the backend.

##### README Insights
- Backend: Flask serving HTTP endpoints, MySQL as persistent store
- Data pipelines:
- Bubble Sort for impact ranking
- BST + inorder traversal for time-sorted trend data
- Trie for real-time recommendations

##### Main Components
a. Frontend (Browser & index.html)
b. Backend API (Flask in app.py)
c. Data Structures & Algorithms Layer (bst.py, trie.py, Bubble Sort logic in e.g. bst.py or another module)
d. Database (MySQL)

##### Relationships and Data Flows
- Browser → HTTP requests → Flask API endpoints
- Flask API reads raw activity data, writes it to MySQL
- For “Impact Ranking” endpoint:
– Flask fetches raw data → invokes Bubble Sort module → returns sorted list
- For “Historical Trend” endpoint:
– Flask loads data from MySQL → builds/inserts into BST → performs inorder traversal → returns chronological dataset
- For “Eco-Suggestions” endpoint:
– Flask queries MySQL for possible suggestions dictionary → initializes Trie → performs prefix lookups → returns suggestions

##### Architectural Patterns and Principles
- Layered architecture: Presentation (HTML/JS), Application (Flask), Data-Structures/Business Logic, Persistence (MySQL)
- Single codebase but clear separation of concerns via modules
- Stateless HTTP API with in-memory data-structure usage scoped to each request

##### Technologies, Frameworks, Libraries
- Flask (Python web framework)
- MySQL (Relational database)
- Python custom modules for BST and Trie
- HTML (static client)

- Raw Activity Data → MySQL (persistence)
- MySQL → BST module → chronological output → API → Client
- MySQL → Sorting module → ranked output → API → Client
- Dictionary data → Trie module → suggestion output → API → Client

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Browser + index.html"]:::frontend

    subgraph "API Layer"
        direction TB
        API["Flask API (app.py)"]:::api
        Sorting["Impact Ranking Service\n(Bubble Sort)"]:::algo
        Trend["Historical Trend Service\n(BST)"]:::algo
        Suggestion["Eco-Suggestions Service\n(Trie)"]:::algo
    end

    DB["MySQL Database"]:::db

    Documentation["Documentation\n(README.md)"]:::doc

    Client -->|"GET /rank\nPOST /activity\nGET /trend\nGET /suggestions"| API
    API --> Sorting
    API --> Trend
    API --> Suggestion
    API -->|"Persist Activity Data"| DB
    DB --> Sorting
    DB --> Trend
    DB --> Suggestion
    Sorting -->|"Ranked List"| API
    Trend -->|"Chronological Data"| API
    Suggestion -->|"Suggestions"| API
    API -->|"API Response"| Client

    click Client "https://github.com/neowave2307/carbon-footprint-tracker/blob/main/index.html"
    click API "https://github.com/neowave2307/carbon-footprint-tracker/blob/main/app.py"
    click Sorting "https://github.com/neowave2307/carbon-footprint-tracker/blob/main/app.py"
    click Trend "https://github.com/neowave2307/carbon-footprint-tracker/blob/main/bst.py"
    click Suggestion "https://github.com/neowave2307/carbon-footprint-tracker/blob/main/trie.py"
    click Documentation "https://github.com/neowave2307/carbon-footprint-tracker/blob/main/README.md"

    classDef frontend fill:#8ecae6,stroke:#023047,stroke-width:2px;
    classDef api fill:#219ebc,stroke:#023047,stroke-width:2px;
    classDef algo fill:#fb8500,stroke:#023047,stroke-width:2px;
    classDef db fill:#cccccc,stroke:#023047,stroke-width:2px;
    classDef doc fill:#ffb703,stroke:#023047,stroke-width:2px;
```
