EcoTracker is an AI-assisted personal carbon tracker that helps users record footprint entries, compute CO2 equivalents, track eco-actions, and get tailored coaching from an AI Carbon Coach.
- Purpose: Track and visualize personal carbon emissions, recommend actions, and help users progress through gamified incentives.
- Audience: Individuals and power users interested in measuring and reducing personal emissions.
- Structure: React SPA (Vite) frontend + Node/Express backend bundled with
esbuild. Firestore is the primary DB with a local JSON fallback for offline/dev use.
- Record and categorize carbon logs (transport, food, electricity, waste, shopping, water)
- Convert inputs into CO2-equivalent values with domain heuristics
- AI Carbon Coach: interactive prompts and assessments via Google Gemini (
@google/genai) - Eco-actions, habit tracking, leaderboards, and offsets panel
- Dynamic export (ZIP) of project files (on-demand)
- Guide-first UX: structured flows and dashboards to help users identify high-impact actions.
- Backend proxy to Gemini: frontend never holds AI keys — server sanitizes prompts and calls Gemini.
- Graceful fallback: when Firestore is unavailable the server uses
local_database.jsonto keep functionality stable.
- User interacts with SPA (React) — adds logs, completes eco-actions.
- SPA calls Express REST endpoints (
/api/*) for reads/writes and AI interactions. - Server reads/writes Firestore or local fallback and calls Gemini for coaching endpoints.
- In production the app is packaged into a Docker image and deployed to Cloud Run; secrets are stored in Secret Manager.
graph TD
User[User]
subgraph Frontend
UI[React 19 + Vite]
Charts[Analytics Dashboard]
end
subgraph Backend
API[Express API Server]
AI[AI Sustainability Coach]
Carbon[Carbon Analytics Engine]
end
subgraph Data Layer
Firestore[Cloud Firestore]
LocalDB[Local JSON Fallback]
end
subgraph Google Cloud
Gemini[Google Gemini]
CloudRun[Cloud Run]
Secrets[Secret Manager]
end
User --> UI
UI --> API
API --> Carbon
API --> AI
AI --> Gemini
API --> Firestore
API --> LocalDB
Secrets --> API
CloudRun --> API
flowchart TD
Dev[Developer] --> Vite[Vite dev server]
Vite --> UI[React components]
Dev --> TSX[tsx dev runner]
TSX --> Server[Express server]
Server --> Build[esbuild -> dist/server.cjs]
Server --> Services[Firestore, Gemini]
- Frontend: React 19, Vite, Tailwind CSS, Recharts
- Backend: Node.js 18+, Express, esbuild
- AI: Google Gemini via
@google/genai - Database: Cloud Firestore (with
local_database.jsonfallback) - Dev: TypeScript, tsx, npm
- Deployment: Docker (Cloud Run recommended)
Prerequisites: Node.js >=18, npm
git clone https://github.com/ShreyashChaugule-github/EcoTracker.git
cd EcoTracker
npm ciRun dev server (Vite + Express):
npm run dev
# Open http://localhost:8080Build for production:
npm run buildSmoke test (built server healthcheck):
npm testBuild & push with Cloud Build:
gcloud builds submit --tag gcr.io/ecotracker-499709/ecotracker --project=ecotracker-499709Deploy to Cloud Run:
gcloud run deploy ecotracker \
--image gcr.io/ecotracker-499709/ecotracker \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--project ecotracker-499709Bind secrets (recommended):
echo -n "YOUR_GEMINI_KEY" | gcloud secrets create gemini-api-key --data-file=- --project=ecotracker-499709
gcloud run deploy ecotracker \
--image gcr.io/ecotracker-499709/ecotracker \
--set-secrets GEMINI_API_KEY=gemini-api-key:latest \
--platform managed --region us-central1 --project ecotracker-499709npm test— smoke test that builds and checks/api/health.- Recommended: add
jest+supertestfor integration tests andvitestfor frontend unit tests.
- Keep API keys in Secret Manager; never commit secrets.
- Server-side only AI calls (proxy pattern) to prevent key leakage.
- Use
helmetfor CSP andexpress-rate-limitfor AI endpoints. - Validate inputs via
express-validatorand avoid verbose error leakage in prod.
- Ensure interactive elements include
aria-*labels and keyboard navigation. - Provide textual or tabular equivalents for charts and visualizations.
server.ts— Express server and APIsrc/— React frontend componentsDockerfile— multistage buildtest/run-healthcheck.js— smoke testlocal_database.json— local fallback DB (do not use in production)
Created with ❤️ for Prompt Wars Challenge 3.