# roshithabasuru/energywatch architecture

> Architecture diagram of the GitHub repository roshithabasuru/energywatch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roshithabasuru/energywatch
- Repository: https://github.com/roshithabasuru/energywatch

## Overview

EnergyWatch is a Flask smart-grid portal for consumers and utility operators. Consumers authenticate, review consumption, manage schedules and alerts, participate in demand-response events, and access billing; operators manage zones and pricing, monitor grid usage, and create events. The app factory registers these route modules, which use SQLAlchemy-backed domain models; audit records use MongoDB. The README describes the product capabilities, while billing, consumption, and several other route implementations were not excerpted, so their internal steps are not expanded here.

Main entry points: [`app/__init__.py`](https://github.com/roshithabasuru/energywatch/blob/main/app/__init__.py) (Flask app), [`app/blueprints/demand_response/routes.py`](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/demand_response/routes.py) (Demand response), [`scheduler.py`](https://github.com/roshithabasuru/energywatch/blob/main/scheduler.py) (Scheduled processing), [`app/blueprints/schedules/routes.py`](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/schedules/routes.py) (Schedules and alerts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web entry and access"]
  node_app_factory["Flask app<br/>[__init__.py]"]
  node_auth_routes["Authentication<br/>[routes.py]"]
  node_access_control["Role access<br/>[decorators.py]"]
end

subgraph group_grid["Grid and consumption"]
  node_consumption_routes["Consumption views<br/>[routes.py]"]
  node_meter_data[("Meter data<br/>[consumption.py]")]
  node_zone_data[("Grid zones<br/>[grid.py]")]
end

subgraph group_consumer["Consumer services"]
  node_consumer_routes["Consumer profile<br/>[routes.py]"]
  node_schedule_routes["Schedules and alerts<br/>[routes.py]"]
  node_schedule_data[("Load schedules<br/>[scheduler.py]")]
  node_alert_data[("Alerts and notices<br/>[alert.py]")]
  node_billing_routes["Billing<br/>[routes.py]"]
  node_billing_data[("Billing records<br/>[billing.py]")]
  node_notification_routes["Notifications<br/>[routes.py]"]
end

subgraph group_utility["Utility operations"]
  node_operator_routes["Grid operations<br/>[routes.py]"]
  node_pricing_data[("Pricing tiers<br/>[pricing.py]")]
  node_dr_routes["Demand response<br/>[routes.py]"]
  node_dr_data[("DR events<br/>[demand_response.py]")]
  node_scheduler_worker["Scheduled processing<br/>[scheduler.py]"]
end

subgraph group_state["Persistence and audit"]
  node_user_data[("Users and profiles<br/>[user.py]")]
  node_audit_data[("Audit log<br/>[audit.py]")]
  node_sql_extensions["SQLAlchemy services<br/>[extensions.py]"]
end

node_consumer_actor(("Consumer"))
node_operator_actor(("Operator"))

node_consumer_actor -->|"uses portal"| node_app_factory
node_operator_actor -->|"uses portal"| node_app_factory
node_app_factory -->|"registers"| node_auth_routes
node_app_factory -->|"registers"| node_consumer_routes
node_app_factory -->|"registers"| node_operator_routes
node_app_factory -->|"registers"| node_consumption_routes
node_app_factory -->|"registers"| node_dr_routes
node_app_factory -->|"registers"| node_schedule_routes
node_app_factory -->|"registers"| node_notification_routes
node_app_factory -->|"registers"| node_billing_routes
node_auth_routes -->|"authenticates"| node_user_data
node_operator_routes -->|"checks role"| node_access_control
node_dr_routes -->|"checks role"| node_access_control
node_schedule_routes -->|"checks role"| node_access_control
node_consumer_routes -->|"reads and updates"| node_zone_data
node_consumption_routes -->|"reads and writes"| node_meter_data
node_operator_routes -->|"manages"| node_zone_data
node_operator_routes -->|"manages"| node_pricing_data
node_operator_routes -->|"aggregates"| node_meter_data
node_dr_routes -->|"selects zone"| node_zone_data
node_dr_routes -->|"creates and enrolls"| node_dr_data
node_dr_routes -->|"calculates baseline"| node_meter_data
node_dr_routes -->|"queues notices"| node_alert_data
node_dr_routes -->|"reads profiles"| node_user_data
node_schedule_routes -->|"manages schedules"| node_schedule_data
node_schedule_routes -->|"manages rules"| node_alert_data
node_schedule_routes -->|"checks rates"| node_pricing_data
node_billing_routes -->|"uses consumption"| node_meter_data
node_billing_routes -->|"uses rates"| node_pricing_data
node_billing_routes -->|"manages billing"| node_billing_data
node_notification_routes -->|"reads notices"| node_alert_data
node_scheduler_worker -->|"processes events"| node_dr_data
node_scheduler_worker -->|"updates notices"| node_alert_data
node_scheduler_worker -->|"reads consumption"| node_meter_data
node_scheduler_worker -->|"reads rates"| node_pricing_data
node_scheduler_worker -->|"updates billing"| node_billing_data
node_scheduler_worker -->|"reads users"| node_user_data
node_sql_extensions -->|"provides ORM"| node_meter_data
node_sql_extensions -->|"provides ORM"| node_user_data
node_operator_routes -->|"records actions"| node_audit_data
node_dr_routes -->|"records actions"| node_audit_data
node_schedule_routes -->|"records actions"| node_audit_data

click node_app_factory "https://github.com/roshithabasuru/energywatch/blob/main/app/__init__.py"
click node_auth_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/auth/routes.py"
click node_access_control "https://github.com/roshithabasuru/energywatch/blob/main/app/utils/decorators.py"
click node_consumer_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/consumer/routes.py"
click node_consumption_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/consumption/routes.py"
click node_meter_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/consumption.py"
click node_operator_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/operator/routes.py"
click node_zone_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/grid.py"
click node_pricing_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/pricing.py"
click node_dr_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/demand_response/routes.py"
click node_dr_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/demand_response.py"
click node_schedule_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/schedules/routes.py"
click node_schedule_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/scheduler.py"
click node_alert_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/alert.py"
click node_billing_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/billing/routes.py"
click node_billing_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/billing.py"
click node_notification_routes "https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/notifications/routes.py"
click node_scheduler_worker "https://github.com/roshithabasuru/energywatch/blob/main/scheduler.py"
click node_user_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/user.py"
click node_audit_data "https://github.com/roshithabasuru/energywatch/blob/main/app/models/audit.py"
click node_sql_extensions "https://github.com/roshithabasuru/energywatch/blob/main/app/extensions.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_factory,node_auth_routes,node_access_control toneBlue
class node_consumption_routes,node_meter_data,node_zone_data toneAmber
class node_consumer_routes,node_schedule_routes,node_schedule_data,node_alert_data,node_billing_routes,node_billing_data,node_notification_routes toneMint
class node_operator_routes,node_pricing_data,node_dr_routes,node_dr_data,node_scheduler_worker toneRose
class node_user_data,node_audit_data,node_sql_extensions,node_consumer_actor,node_operator_actor toneIndigo
```

## Components

### Web entry and access

- [Flask app](https://github.com/roshithabasuru/energywatch/blob/main/app/__init__.py): `app/__init__.py`
- [Authentication](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/auth/routes.py): `app/blueprints/auth/routes.py`
- [Role access](https://github.com/roshithabasuru/energywatch/blob/main/app/utils/decorators.py): `app/utils/decorators.py`

### Grid and consumption

- [Consumption views](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/consumption/routes.py): `app/blueprints/consumption/routes.py`
- [Meter data](https://github.com/roshithabasuru/energywatch/blob/main/app/models/consumption.py): `app/models/consumption.py`
- [Grid zones](https://github.com/roshithabasuru/energywatch/blob/main/app/models/grid.py): `app/models/grid.py`

### Consumer services

- [Consumer profile](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/consumer/routes.py): `app/blueprints/consumer/routes.py`
- [Schedules and alerts](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/schedules/routes.py): `app/blueprints/schedules/routes.py`
- [Load schedules](https://github.com/roshithabasuru/energywatch/blob/main/app/models/scheduler.py): `app/models/scheduler.py`
- [Alerts and notices](https://github.com/roshithabasuru/energywatch/blob/main/app/models/alert.py): `app/models/alert.py`
- [Billing](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/billing/routes.py): `app/blueprints/billing/routes.py`
- [Billing records](https://github.com/roshithabasuru/energywatch/blob/main/app/models/billing.py): `app/models/billing.py`
- [Notifications](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/notifications/routes.py): `app/blueprints/notifications/routes.py`

### Utility operations

- [Grid operations](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/operator/routes.py): `app/blueprints/operator/routes.py`
- [Pricing tiers](https://github.com/roshithabasuru/energywatch/blob/main/app/models/pricing.py): `app/models/pricing.py`
- [Demand response](https://github.com/roshithabasuru/energywatch/blob/main/app/blueprints/demand_response/routes.py): `app/blueprints/demand_response/routes.py`
- [DR events](https://github.com/roshithabasuru/energywatch/blob/main/app/models/demand_response.py): `app/models/demand_response.py`
- [Scheduled processing](https://github.com/roshithabasuru/energywatch/blob/main/scheduler.py): `scheduler.py`

### Persistence and audit

- [Users and profiles](https://github.com/roshithabasuru/energywatch/blob/main/app/models/user.py): `app/models/user.py`
- [Audit log](https://github.com/roshithabasuru/energywatch/blob/main/app/models/audit.py): `app/models/audit.py`
- [SQLAlchemy services](https://github.com/roshithabasuru/energywatch/blob/main/app/extensions.py): `app/extensions.py`

### Other components

- **Consumer**
- **Operator**

## Connections

- Consumer → Flask app: uses portal
- Operator → Flask app: uses portal
- Flask app → Authentication: registers (evidence: `app/__init__.py`)
- Flask app → Consumer profile: registers (evidence: `app/__init__.py`)
- Flask app → Grid operations: registers (evidence: `app/__init__.py`)
- Flask app → Consumption views: registers (evidence: `app/__init__.py`)
- Flask app → Demand response: registers (evidence: `app/__init__.py`)
- Flask app → Schedules and alerts: registers (evidence: `app/__init__.py`)
- Flask app → Notifications: registers (evidence: `app/__init__.py`)
- Flask app → Billing: registers (evidence: `app/__init__.py`)
- Authentication → Users and profiles: authenticates (evidence: `app/blueprints/auth/routes.py`)
- Grid operations → Role access: checks role (evidence: `app/blueprints/operator/routes.py`)
- Demand response → Role access: checks role (evidence: `app/blueprints/demand_response/routes.py`)
- Schedules and alerts → Role access: checks role (evidence: `app/blueprints/schedules/routes.py`)
- Consumer profile → Grid zones: reads and updates (evidence: `app/blueprints/consumer/routes.py`)
- Consumption views → Meter data: reads and writes (evidence: `app/blueprints/consumption/routes.py`)
- Grid operations → Grid zones: manages (evidence: `app/blueprints/operator/routes.py`)
- Grid operations → Pricing tiers: manages (evidence: `app/blueprints/operator/routes.py`)
- Grid operations → Meter data: aggregates (evidence: `app/blueprints/operator/routes.py`)
- Demand response → Grid zones: selects zone (evidence: `app/blueprints/demand_response/routes.py`)
- Demand response → DR events: creates and enrolls (evidence: `app/blueprints/demand_response/routes.py`)
- Demand response → Meter data: calculates baseline (evidence: `app/blueprints/demand_response/routes.py`)
- Demand response → Alerts and notices: queues notices (evidence: `app/blueprints/demand_response/routes.py`)
- Demand response → Users and profiles: reads profiles (evidence: `app/blueprints/demand_response/routes.py`)
- Schedules and alerts → Load schedules: manages schedules (evidence: `app/blueprints/schedules/routes.py`)
- Schedules and alerts → Alerts and notices: manages rules (evidence: `app/blueprints/schedules/routes.py`)
- Schedules and alerts → Pricing tiers: checks rates (evidence: `app/blueprints/schedules/routes.py`)
- Billing → Meter data: uses consumption (evidence: `app/blueprints/billing/routes.py`)
- Billing → Pricing tiers: uses rates (evidence: `app/blueprints/billing/routes.py`)
- Billing → Billing records: manages billing (evidence: `app/blueprints/billing/routes.py`)
- Notifications → Alerts and notices: reads notices (evidence: `app/blueprints/notifications/routes.py`)
- Scheduled processing → DR events: processes events (evidence: `scheduler.py`)
- Scheduled processing → Alerts and notices: updates notices (evidence: `scheduler.py`)
- Scheduled processing → Meter data: reads consumption (evidence: `scheduler.py`)
- Scheduled processing → Pricing tiers: reads rates (evidence: `scheduler.py`)
- Scheduled processing → Billing records: updates billing (evidence: `scheduler.py`)
- Scheduled processing → Users and profiles: reads users (evidence: `scheduler.py`)
- SQLAlchemy services → Meter data: provides ORM (evidence: `app/models/consumption.py`)
- SQLAlchemy services → Users and profiles: provides ORM (evidence: `app/models/user.py`)
- Grid operations → Audit log: records actions (evidence: `app/blueprints/operator/routes.py`)
- Demand response → Audit log: records actions (evidence: `app/blueprints/demand_response/routes.py`)
- Schedules and alerts → Audit log: records actions (evidence: `app/blueprints/schedules/routes.py`)
