Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌿 EcoTrace β€” Personal Carbon Footprint Intelligence Platform

Live Demo License: MIT

A smart, AI-powered web app that helps individuals understand, track, and meaningfully reduce their carbon footprint β€” one action at a time.


🎯 Chosen Vertical

Environmental Sustainability / Personal Climate Action

The app targets one of the most critical challenges of our era: translating awareness of climate change into concrete, measurable individual action. While many people want to reduce their environmental impact, they lack the tools to understand where their emissions come from and what to do about it.


πŸš€ Live Demo

πŸ‘‰ Live Demo

On first load, the app seeds realistic demo data so you can immediately explore all features.


✨ Features

Feature Description
πŸ€– AI Eco-Coach Rule-based recommendation engine with 20+ pattern-aware tips + chat interface
πŸ“Š Live Dashboard Real-time carbon score, 7-day trend, category breakdown
πŸ“ Activity Logger Log transport, food, energy & shopping with instant COβ‚‚ preview
πŸ“ˆ Analytics 30-day trends, stacked charts, global average comparison
πŸ† Achievements 16 badges, streak tracking, weekly/daily goal rings
πŸ’‘ Impact Equivalencies Translate kg COβ‚‚e into trees, car km, flights, phone charges
πŸ“± Fully Responsive Desktop sidebar + mobile bottom navigation
β™Ώ Accessible WCAG AA, ARIA labels, keyboard navigation, skip link

🧠 Approach & Logic

Emission Calculation Engine

The core formula follows the GHG Protocol standard:

Emissions (kg COβ‚‚e) = Activity Data Γ— Emission Factor

Emission factors are sourced from EPA (2023) and DEFRA (2023):

Category Examples Data Unit
Transport Car (petrol: 0.192), Train (0.041), Bus (0.089) kg COβ‚‚e per km
Food Beef (6.61), Vegan meal (0.24), Chicken (0.69) kg COβ‚‚e per meal
Energy Grid electricity (0.233), Natural gas (0.202) kg COβ‚‚e per kWh
Shopping Electronics (12.0), Clothing (3.0), Delivery (0.5) kg COβ‚‚e per item

AI Engine (Rule-Based)

The AI engine uses a priority-weighted scoring system β€” no external API required:

1. Build Context  β†’ aggregate last 7 days of user logs
2. Pattern Match  β†’ run each tip's condition() against context
3. Score & Rank   β†’ HIGH (3pts), MEDIUM (2pts), LOW (1pt)
4. Deduplicate    β†’ deprioritize recently seen tips
5. Output         β†’ top 3 personalized, actionable insights

Example decision rules:

  • If transport > 2Γ— food emissions β†’ push transit/cycling alternatives
  • If beef meals β‰₯ 4/week β†’ suggest plant-based swaps with exact savings
  • If trend = worsening (+20%) β†’ show improvement-focused tips
  • If streak β‰₯ 5 days β†’ encourage with gamification messaging

Chat Interface

The chat system parses natural language with keyword matching and maps queries to context-aware response templates that reference the user's actual data.


πŸ—οΈ How It Works

User logs activity
       ↓
calculator.js  β€” applies emission factor β†’ kg COβ‚‚e
       ↓
storage.js     β€” persists to localStorage with date/category tagging
       ↓
ai-engine.js   β€” re-evaluates all tips against updated context
       ↓
gamification.js β€” checks badge conditions, updates streaks
       ↓
UI re-renders  β€” charts, scores, tips refresh in real time

Data Flow Diagram

[User Input] ──► [Calculator] ──► [Storage (localStorage)]
                                         β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                    β–Ό                    β–Ό
              [AI Engine]          [Gamification]
                    β”‚                    β”‚
                    β–Ό                    β–Ό
              [Insights/Tips]      [Badges/Goals]
                    β”‚                    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β–Ό
                      [UI / Charts]

πŸ“ Project Structure

ecotrace/
β”œβ”€β”€ index.html          # SPA shell: layout, navigation, accessibility
β”œβ”€β”€ css/
β”‚   └── style.css       # Design system: tokens, components, animations
β”œβ”€β”€ js/
β”‚   β”œβ”€β”€ calculator.js   # Emission factors & COβ‚‚ calculation engine
β”‚   β”œβ”€β”€ storage.js      # localStorage abstraction (type-safe read/write)
β”‚   β”œβ”€β”€ ai-engine.js    # Rule-based AI: pattern detection, tip ranking, chat
β”‚   β”œβ”€β”€ gamification.js # Badges (16), streaks, goal progress
β”‚   β”œβ”€β”€ charts.js       # Chart.js wrappers (donut, line, bar, sparkline)
β”‚   β”œβ”€β”€ ui.js           # DOM helpers, toast notifications, animations
β”‚   └── app.js          # View routing, all 5 page renderers, bootstrap
β”œβ”€β”€ tests/
β”‚   └── test.js         # Unit tests for calculator, storage, AI engine
└── README.md

πŸ› οΈ Tech Stack

Technology Purpose Why
Vanilla HTML/CSS/JS Core Zero dependencies = maximum readability & instant load
Chart.js 4.4 (CDN) Data visualization Industry-standard, lightweight, beautiful charts
localStorage Data persistence No backend = no security risk, works offline
Google Fonts Typography Plus Jakarta Sans for modern, premium feel

No build tools. No npm. Open index.html directly.


πŸ“‹ Assumptions Made

  1. Emission factors use global averages from EPA/DEFRA 2023. Location-specific factors (e.g., regional electricity grids) are a future enhancement.

  2. Food quantities are measured in "meals/servings" rather than exact grams, to minimize user friction and keep logging fast.

  3. Energy data requires the user to know their approximate kWh usage. A future version could integrate with smart meter APIs.

  4. No user authentication β€” data lives in the browser. This is intentional: zero security surface area, no data privacy concerns.

  5. AI insights are deterministic and rule-based. They do not call any external API, ensuring the app works fully offline and poses no key exposure risk.

  6. Demo data is seeded on first load so evaluators can immediately see all features without manual data entry.


πŸ§ͺ Testing

Open tests/test.js in a browser console or run with Node.js:

node tests/test.js

Tests cover:

  • βœ… Emission factor calculations (all 4 categories)
  • βœ… COβ‚‚e equivalency conversions
  • βœ… Daily rating classification
  • βœ… Storage read/write/delete operations
  • βœ… AI engine tip matching logic
  • βœ… Goal progress calculations
  • βœ… Streak update logic

β™Ώ Accessibility

  • WCAG 2.1 AA color contrast ratios throughout
  • ARIA labels on all interactive elements, charts, and live regions
  • Keyboard navigation β€” full tab order, Enter/Space triggers
  • Skip link for screen reader users
  • aria-live="polite" on main content area for dynamic updates
  • Focus-visible outlines on all focusable elements
  • role attributes β€” main, navigation, list, listitem, log, img, article
  • Semantic HTML β€” <header>, <main>, <nav>, <h1>–<h2>, <form>, <button>

πŸ”’ Security

  • No external API calls (no API keys)
  • No eval() or dynamic Function() usage
  • All user data stays on the user's device (localStorage)
  • Input sanitization via textContent (not innerHTML) for user data
  • novalidate + JS validation to prevent native browser form exploits
  • CSP-compatible (no inline event attributes except framework-level onclick)

πŸš€ Getting Started

Option 1: Direct browser (simplest)

1. Download or clone this repository
2. Open index.html in any modern browser
3. That's it β€” no server needed!

Option 2: Local server (avoids CORS for font loading)

# Python
python -m http.server 8080

# Node.js
npx serve .

# Then visit http://localhost:8080

Option 3: Vercel (live deployment)

1. Import repository on vercel.com
2. Deploy
3. Visit https://eco-trace-six-sepia.vercel.app/

πŸ’‘ Technical Interview Talking Points & Architecture Tradeoffs

1. Local-First & Zero-Backend Architecture

  • Tradeoff: We opted for a pure client-side architecture using localStorage instead of building a traditional REST API + Database server.
  • Why:
    1. Data Sovereignty / Absolute Privacy: Carbon footprint data details daily personal habits (diet, commute routes, purchases). Keeping data strictly on the user's device eliminates data liability under GDPR/CCPA.
    2. Zero Maintenance & Operational Costs: Serving a static SPA via CDN means the application is infinitely scalable at near-zero hosting cost.
    3. Offline capability: The application requires no network connectivity, offering sub-millisecond interaction times.
  • Mitigations: Multi-device sync is a limitation. In a production roadmap, this would be addressed using a cryptographic sync protocol (like CRDTs over WebRTC or local storage synchronization with private end-to-end encrypted backup files).

2. Heuristics & Deterministic Rule Engine vs. External LLM Calls

  • Tradeoff: The AI Eco-Coach leverages a local priority-weighted rule engine instead of calling remote Generative AI APIs (e.g. OpenAI GPT-4).
  • Why:
    1. Resource Efficiency: Zero network overhead, zero latency, and zero token costs.
    2. Security: Zero danger of exposing sensitive user logs to third-party APIs.
    3. Reliability: No possibility of LLM hallucinations; recommendations are scientifically validated against local calculations.

🌍 Impact Potential

If EcoTrace achieved 1 million active users who each reduced their footprint by just 5%:

  • Average footprint: ~4 tonnes COβ‚‚e/year
  • 5% reduction: 200 kg COβ‚‚e/user/year
  • Total: 200,000 tonnes COβ‚‚e avoided per year
  • Equivalent to taking ~43,000 cars off the road

πŸ“œ License

MIT License β€” see LICENSE for details.


Built for the Prompt War Hackathon 2024 β€” Vertical: Environmental Sustainability

About

Personal carbon footprint tracker and analytics dashboard with local-first storage and a rule-based AI eco-coach.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages