A gamified, eco-focused web app that helps users track sustainable tasks, estimate carbon footprint, fetch environmental news, and earn rewards for green actions.
- User authentication and profiles (MongoDB + Express)
- Task management with gamified points and leaderboard
- Carbon footprint prediction using a Python model (PyCaret)
- Environmental news fetcher (NewsAPI)
- Green tips and actionable suggestions
- Backend: Node.js, Express
- Database: MongoDB (Mongoose)
- Views: EJS templates
- Frontend: static assets in public/ and views/
- Machine learning: Python (PyCaret) model in model/
- app.js — main/root server entry (Express app)
- backend/app.js — alternative/expanded Express server with APIs and ML integration
- backend/ — Python scripts and helpers (predictor.py, newsFetcher.py, suggestions.js, train_model.py)
- model/ — trained ML artifacts loaded by predictor.py
- public/ — static frontend assets (CSS, JS)
- views/ — EJS templates for the UI
- data/ — CSV and JSON data used for training or bootstrapping
Prerequisites:
- Node.js (v16+ recommended)
- Python 3.8+ (with required ML libraries)
- MongoDB running locally (or update connection string)
Install Node dependencies:
npm installInstall Python dependencies (example):
python -m pip install pandas requests pycaretNotes: PyCaret and some ML dependencies can be large and may require additional system packages. If you don't need ML features, you can skip installing PyCaret and the model/ usage.
Start MongoDB (locally) then run:
npm start
# or
node app.jsBy default the app listens on http://localhost:3000.
- GET / — home (redirects to login or serves public/index.html depending on server file)
- GET /login, POST /login — authentication
- GET /signup, POST /signup — create account
- GET /tasks, POST /tasks — task list and creation
- POST /tasks/done — mark task complete (session-protected)
- POST /api/complete — API endpoint to complete a task and award points (uses tasks.json + leaderboard.json in backend/)
- POST /api/refresh-tasks — triggers Python task generation (ml_task.py) and refreshes tasks.json
- POST /chat — sends input to model/predict.py and returns model reply
- GET /get-news?q=... — fetches environmental news via newsFetcher.py (uses NewsAPI key)
- POST /calculate — sends numeric inputs to backend/predictor.py to estimate carbon emissions
- backend/predictor.py loads a PyCaret model from model/carbon_model and expects three numeric args: electricity, car, meat.
- If the model is absent or fails, the code falls back to a simple heuristic calculation.
- Training scripts (if present) are in backend/train_model.py or similar; check data/eco_user_behavior.csv for training data.
- backend/newsFetcher.py currently contains an API key placeholder. Replace it with an environment variable or a secure secret manager before production.
- MongoDB connection string is currently mongodb://localhost:27017/eco_auth in the server files — update for production environments.
- Do not commit real API keys or credentials.
- Validate and sanitize user inputs before executing external commands or Python scripts — the code currently spawns Python processes with passed arguments.
EcoTasker — a clear, friendly name conveying eco-friendly task tracking and gamification.
- Extract secrets to environment variables and add a .env.example file.
- Add a requirements.txt for Python dependencies and/or a pyproject.toml for reproducible ML environment.
- Add tests (backend API unit tests) and a simple CI workflow.
- Harden input validation around Python subprocess calls.
Add a LICENSE file (MIT or your preferred license).
Generated from repository analysis on May 28, 2026.