How mohithkudumu/campus-carbon-pulse works
Purpose and Entry Points
Campus Carbon Pulse is a campus carbon-emissions digital twin: it forecasts 24 hours of per-building emissions, displays them on an interactive map, records threshold alerts, and generates sustainability insights. Browser entry is src/main.tsx, routing/app composition begins in src/App.tsx, and the main dashboard is src/pages/Index.tsx. The backend API application enters through backend/main.py.
Frontend Dashboard and State Flow
The React/TypeScript frontend runs under Vite and renders the operational dashboard from src/pages/Index.tsx. User time selection flows through src/components/TimeSlider.tsx; the selected hour drives backend emissions retrieval and updates map, aggregate analytics, and alert-oriented UI. src/pages/Insights.tsx separately requests and renders the AI report.
Geospatial Digital Twin
src/components/CampusMap.tsx uses MapLibre GL to render campus building GeoJSON as 3D structures, with color/state derived from forecast emissions. The map’s structural source is public/campus.json; backend-side backend/campus.json is the server-managed counterpart, described as receiving live-data injection. The map boundary is GeoJSON/building identifiers: forecast results must match these IDs.
Analytics and Alert Operations
src/components/AnalyticsPanel.tsx presents campus totals, trends, and historical charts, while src/components/AlertsBell.tsx surfaces unresolved threshold violations and supports resolution. Backend routes in backend/main.py expose hour-specific forecasts, historical aggregates, unresolved alerts, and alert resolution. This is a REST-over-HTTP boundary with CORS between Vite’s browser runtime and FastAPI.
Forecast Generation Pipeline
On FastAPI startup, backend/main.py initializes persistence and invokes forecast generation in backend/forecast.py. The forecaster loads one TensorFlow/Keras LSTM and one joblib scaler per monitored building from backend/models/, applies them to historical inputs from backend/snuc_carbon_year_2025.csv, and produces 24 hourly predictions. Outputs are written both as a file cache, backend/emissions.json, and to SQLite for API retrieval.
Persistence, Thresholds, and Historical Data
SQLite is accessed through backend/database.py and stored in backend/database.db. It persists predicted emissions, peak alerts with resolution status, and daily cached AI insight payloads. Forecast generation is also the alert-production boundary: values exceeding configured thresholds create peak_alerts records; frontend resolution mutates only alert status through the API.
AI Insights and External Services
backend/main.py serves the insight workflow, with supporting legacy logic in backend/insights.py. It composes emission-derived context, calls Google Gemini (requiring GEMINI_API_KEY from .env), and caches the structured response by date in SQLite to limit API consumption. Major runtimes are React/Vite in Node.js, FastAPI/Uvicorn in Python, TensorFlow/Keras for inference, and local SQLite; MapLibre and Gemini are the material external services.
Main entry points: main.py FastAPI application · Index.tsx Operations dashboard · forecast.py Forecast generator · App.tsx App routing
Components 19
Browser dashboard
- React/Vite entry
src/main.tsx - App routing
src/App.tsx - Operations dashboard
src/pages/Index.tsx - Hour selector · Selected hour drives forecast retrieval.
src/components/TimeSlider.tsx - 3D campus map
src/components/CampusMap.tsx - Analytics panel
src/components/AnalyticsPanel.tsx - Alerts bell
src/components/AlertsBell.tsx - Insights page
src/pages/Insights.tsx
FastAPI backend
- FastAPI application · Serves forecasts, history, alerts, and insights.
backend/main.py - Forecast generator · Startup job produces 24-hour building forecasts and threshold alerts.
backend/forecast.py - Database layer
backend/database.py - Insight support
backend/insights.py
Local data & persistence
- Building GeoJSON · Building IDs must match forecast results.
public/campus.json - Server campus data
backend/campus.json - Historical emissions
backend/snuc_carbon_year_2025.csv - Building models · One LSTM and scaler per monitored building.
- Emissions cache
backend/emissions.json - Operational database · Stores forecasts, peak alerts, and daily insight cache.
backend/database.db
External services
- Google Gemini
Connections 21
- React/Vite entry → App routing: mounts
- App routing → Operations dashboard: routes to
- App routing → Insights page: routes to
- Hour selector → Operations dashboard: selects hour
- Operations dashboard → 3D campus map: renders
- Operations dashboard → Analytics panel: renders
- Operations dashboard → Alerts bell: renders
- 3D campus map → Building GeoJSON: loads buildings
- Operations dashboard → FastAPI application: forecast, history, alerts HTTP · CORS REST boundary.
- Insights page → FastAPI application: insights HTTP
- Alerts bell → FastAPI application: resolve alert HTTP
- FastAPI application → Forecast generator: runs at startup
- Forecast generator → Building models: loads LSTM and scaler
- Forecast generator → Historical emissions: reads inputs
- Forecast generator → Emissions cache: writes forecasts
- Forecast generator → Database layer: persists forecasts and alerts
- FastAPI application → Database layer: queries and updates
- Database layer → Operational database: reads/writes
- FastAPI application → Insight support: builds insight context
- Insight support → Google Gemini: requests report
- FastAPI application → Server campus data: manages live data