How devaprasath4/ecodecide works
Purpose and Runtime
EcoDecide is a sustainability decision assistant: users submit everyday choices and receive AI-generated, emissions-oriented guidance. It runs as a Node.js/Express server with a static vanilla-JS frontend, MongoDB persistence with an in-memory fallback, Google Gemini 2.5 Flash, and Chart.js visualizations. Primary backend entry point: server.js.
Client Application Surfaces
The static UI has separate landing, authentication, and authenticated dashboard pages:
• Landing and general interactions: public/index.html, public/js/main.js
• Login/authentication flow: public/login.html, public/js/auth.js
• Decision history, impact data, and charts: public/dashboard.html, public/js/dashboard.js
Shared presentation is delivered from public/css/style.css.
HTTP/API Boundary
server.js is the application boundary between browser clients, authentication, persistence, and Gemini. Express serves the public/ assets and exposes API endpoints consumed by the frontend scripts. The browser remains a thin client: it collects user input, stores/uses session credentials, renders responses, and visualizes returned impact/history data.
Identity and Session Control
Authentication is handled across public/js/auth.js and server.js. The server requires JWT_SECRET at startup, signs/verifies JWTs, and uses authenticated identity to scope user-specific decisions and dashboard data. This makes the API authentication boundary central rather than relying on frontend-only access control.
AI Decision and Emissions Stage
The core decision-analysis workflow is implemented server-side in server.js: incoming user choice context is sent to Google Gemini 2.5 Flash, whose response supplies sustainability guidance and CO₂ estimates. Prompting/calibration is expected to align with documented reference factors for transport, food, shopping, energy, and general lifecycle emissions; Gemini is an external service boundary and estimates are advisory rather than research-grade LCA results.
Persistence and Resilience
server.js owns data storage for users and/or decision records. MongoDB is the intended durable datastore, while an in-memory fallback allows operation when MongoDB is unavailable. This fallback changes durability characteristics: dashboard history and account/decision data may not survive process restarts without MongoDB.
Impact Reporting and Visualization
The dashboard client in public/js/dashboard.js retrieves authenticated user data from the API and renders decision/impact trends with Chart.js. public/dashboard.html is therefore the reporting endpoint, while public/index.html contains projected aggregate impact figures that are explicitly not live tracked metrics.
Main entry points: server.js Express application · dashboard.js Dashboard client · style.css Shared styles · index.html Landing page
Components 15
Browser Client
- Landing page · Collects everyday choice input and shows projected aggregate impact.
public/index.html - General interactions
public/js/main.js - Login page
public/login.html - Auth client · Manages login flow and session credentials.
public/js/auth.js - Dashboard page · Authenticated reporting surface.
public/dashboard.html - Dashboard client · Retrieves history and renders impact trends.
public/js/dashboard.js - Shared styles
public/css/style.css
Express Server
- Express application · Serves static assets and exposes frontend API endpoints.
server.js - JWT authentication · Requires JWT_SECRET and scopes requests to authenticated users.
server.js - Decision analysis · Builds sustainability guidance and advisory CO₂ estimates.
server.js - Data repository · Stores users and decision records.
server.js - In-memory fallback · Used when MongoDB is unavailable; data is lost on restart.
server.js
External Services
- Chart.js
- MongoDB
- Gemini 2.5 Flash · External source of generated guidance and emissions estimates.
Connections 17
- Landing page → General interactions: loads
- Login page → Auth client: loads
- Dashboard page → Dashboard client: loads
- Landing page → Shared styles: styled by
- Login page → Shared styles: styled by
- Dashboard page → Shared styles: styled by
- General interactions → Express application: submits choices
- Auth client → Express application: auth requests
- Dashboard client → Express application: authenticated data requests
- Dashboard client → Chart.js: renders charts
- Express application → JWT authentication: authenticates API requests
- Express application → Decision analysis: routes decision requests
- Express application → Data repository: reads and writes user data
- Decision analysis → Gemini 2.5 Flash: sends choice context
- Data repository → MongoDB: primary storage
- Data repository → In-memory fallback: on database failure
- JWT authentication → Data repository: scopes records by identity