How arjunbalaji123/campus-energy-consumption-and-anomaly-detection-system--ml- works
This is a campus energy decision-support prototype: users register buildings and enter or import readings, then review expected-load predictions, anomaly investigations, savings recommendations, dashboards, model comparisons, and threshold settings. The graph follows the documented React-to-FastAPI-to-database workflow and the sampled anomaly and reading service references. Training and several API/UI branches are represented from the README and source index; their detailed runtime wiring was not sampled.
Main entry points: main.py FastAPI service · App.tsx Application router · api.ts Fetch API client · anomaly_service.py Dual anomaly detection
Components 34
Campus interface
- Application router
frontend/src/App.tsx - Energy dashboard
frontend/src/pages/Overview.tsx - Building registry
frontend/src/pages/Buildings.tsx - Readings entry
frontend/src/pages/EnergyData.tsx - Prediction view
frontend/src/pages/Predictions.tsx - Anomaly dossier
frontend/src/pages/AnomalyCenter.tsx - Action recommendations
frontend/src/pages/Recommendations.tsx - Model comparison
frontend/src/pages/ModelPerformance.tsx - Threshold settings
frontend/src/pages/Settings.tsx - Fetch API client
frontend/src/services/api.ts
REST interface
- FastAPI service
backend/app/main.py - Building routes
backend/app/api/buildings.py - Reading routes
backend/app/api/readings.py - Prediction routes
backend/app/api/predictions.py - Anomaly routes
backend/app/api/anomalies.py - Recommendation routes
backend/app/api/recommendations.py - Dashboard routes
backend/app/api/dashboard.py - Model routes
backend/app/api/models.py - Settings routes
backend/app/api/settings.py
Energy analytics
- Building management
backend/app/services/building_service.py - Reading management
backend/app/services/reading_service.py - Baseline prediction
backend/app/services/prediction_service.py - Dual anomaly detection
backend/app/services/anomaly_service.py - Rule explanations
backend/app/services/explanation_engine.py - Operational directives
backend/app/services/recommendation_engine.py - Dashboard analytics
backend/app/services/dashboard_service.py
Modeling
- Feature preprocessing
backend/ml/preprocessing.py - Random Forest training
backend/ml/train_rf.py - Isolation Forest training
backend/ml/train_isolation_forest.py - LSTM training
backend/ml/train_lstm.py - LSTM implementation
backend/ml/lstm_model.py
Persistence
- SQL database
backend/app/core/database.py - Building records
backend/app/models/building.py
Other components
- Campus staff
Connections 41
- Campus staff → Application router: uses
- Application router → Energy dashboard: routes to
frontend/src/App.tsx - Application router → Building registry: routes to
frontend/src/App.tsx - Application router → Readings entry: routes to
frontend/src/App.tsx - Application router → Prediction view: routes to
frontend/src/App.tsx - Application router → Anomaly dossier: routes to
frontend/src/App.tsx - Application router → Action recommendations: routes to
frontend/src/App.tsx - Application router → Model comparison: routes to
frontend/src/App.tsx - Application router → Threshold settings: routes to
frontend/src/App.tsx - Energy dashboard → Fetch API client: requests data
frontend/src/pages/Overview.tsx - Building registry → Fetch API client: requests data
frontend/src/pages/Buildings.tsx - Readings entry → Fetch API client: submits readings
frontend/src/pages/EnergyData.tsx - Prediction view → Fetch API client: requests predictions
frontend/src/pages/Predictions.tsx - Anomaly dossier → Fetch API client: requests cases
frontend/src/pages/AnomalyCenter.tsx - Action recommendations → Fetch API client: requests actions
frontend/src/pages/Recommendations.tsx - Model comparison → Fetch API client: requests metrics
frontend/src/pages/ModelPerformance.tsx - Fetch API client → FastAPI service: REST JSON
- FastAPI service → Building routes: registers router
backend/app/main.py - FastAPI service → Reading routes: registers router
backend/app/main.py - FastAPI service → Prediction routes: registers router
backend/app/main.py - FastAPI service → Anomaly routes: registers router
backend/app/main.py - FastAPI service → Recommendation routes: registers router
backend/app/main.py - FastAPI service → Dashboard routes: registers router
backend/app/main.py - FastAPI service → Model routes: registers router
backend/app/main.py - FastAPI service → Settings routes: registers router
backend/app/main.py - Reading routes → Reading management: delegates to
backend/app/api/readings.py - Anomaly routes → Dual anomaly detection: delegates to
backend/app/api/anomalies.py - Recommendation routes → Operational directives: delegates to
backend/app/api/recommendations.py - Building routes → Building management: delegates to
- Dashboard routes → Dashboard analytics: delegates to
- Prediction routes → Baseline prediction: delegates to
- Reading management → Building management: uses building service
backend/app/services/reading_service.py - Dual anomaly detection → Baseline prediction: requests prediction
backend/app/services/anomaly_service.py - Dual anomaly detection → Rule explanations: evaluates cause
backend/app/services/anomaly_service.py - Dual anomaly detection → Operational directives: generates directives
backend/app/services/anomaly_service.py - Baseline prediction → Feature preprocessing: prepares features
backend/app/services/prediction_service.py - LSTM training → LSTM implementation: trains model
backend/ml/train_lstm.py - LSTM training → Feature preprocessing: uses features
backend/ml/train_lstm.py - Random Forest training → Feature preprocessing: uses features
backend/ml/train_rf.py - FastAPI service → SQL database: provides sessions
backend/app/main.py - SQL database → Building records: defines ORM base
backend/app/models/building.py