How neowave2307/carbon-footprint-tracker works
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