# sahil-karkar/dysa-smart-energy architecture

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

- Interactive diagram: https://gitdiagram.com/sahil-karkar/dysa-smart-energy
- Repository: https://github.com/sahil-karkar/dysa-smart-energy

## Overview

DYSA is a simulated home-energy dashboard: a visitor explores a home, changes scenarios or circuits, and sees room-level usage, safety notices, pattern analysis, and analytics. The dashboard and 3D scene use the API to read or change session-scoped home state; the API builds simulated readings and evaluates alerts. Pattern analysis has both server-side model evaluation and browser-worker analysis, while the README also documents forecasting and replay. Some UI and model implementations were not sampled, so those subsystems are retained without guessing their internal call paths.

Main entry points: [`profiles.mjs`](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs) (Home state and API), [`src/main.tsx`](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/main.tsx) (Energy dashboard), [`security.mjs`](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/security.mjs) (API security), [`build-worker.mjs`](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/build-worker.mjs) (Worker API entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Home experience"]
  node_dashboard["Energy dashboard<br/>[main.tsx]"]
  node_insights["ML insights<br/>[MLInsights.tsx]"]
  node_home_setup["Home setup<br/>[HomeSetup.tsx]"]
  node_scene["3D home scene<br/>[home.js]"]
  node_scene_boot["Scene bootstrap<br/>[boot.js]"]
  node_control_sync["Control synchronization<br/>[control-sync.js]"]
end

subgraph group_simulation["Home simulation"]
  node_home_state["Home state and API<br/>[profiles.mjs]"]
  node_safety_rules["Safety rules<br/>[profiles.mjs]"]
end

subgraph group_analysis["Energy analysis"]
  node_usage_model["Isolation Forest model"]
  node_browser_analysis["Browser pattern analysis"]
  node_analytics["Usage analytics<br/>[profiles.mjs]"]
end

subgraph group_services["API and persistence"]
  node_api_security["API security<br/>[security.mjs]"]
  node_worker_api["Worker API entry<br/>[build-worker.mjs]"]
  node_local_server["Local server<br/>[server.mjs]"]
  node_local_adapter["SQLite adapter<br/>[local-db.mjs]"]
  node_database[("Home data store")]
end

node_visitor(("Visitor"))

node_visitor -->|"explores"| node_dashboard
node_visitor -->|"operates"| node_scene
node_dashboard -.->|"requests home data"| node_home_state
node_dashboard -.->|"presents analysis"| node_insights
node_dashboard -.->|"configures homes"| node_home_setup
node_scene_boot -->|"loads"| node_scene
node_scene -->|"uses controls"| node_control_sync
node_control_sync -->|"requests state and changes"| node_home_state
node_home_state -.->|"evaluates load"| node_safety_rules
node_home_state -->|"evaluates usage"| node_usage_model
node_home_state -.->|"builds usage history"| node_analytics
node_dashboard -.->|"runs pattern analysis"| node_browser_analysis
node_insights -.->|"shows pattern results"| node_browser_analysis
node_worker_api -->|"secures API requests"| node_api_security
node_worker_api -->|"dispatches API"| node_home_state
node_api_security -->|"authorizes and invokes"| node_home_state
node_local_server -->|"forwards requests"| node_worker_api
node_local_server -->|"opens database"| node_local_adapter
node_home_state -->|"reads and writes"| node_database
node_api_security -->|"reads and writes limits and sessions"| node_database
node_local_adapter -.->|"implements local storage"| node_database

click node_dashboard "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/main.tsx"
click node_insights "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/MLInsights.tsx"
click node_home_setup "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/HomeSetup.tsx"
click node_scene "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/simulator/home.js"
click node_scene_boot "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/simulator/boot.js"
click node_control_sync "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/simulator/control-sync.js"
click node_home_state "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs"
click node_safety_rules "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs"
click node_usage_model "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/isolation-forest.mjs"
click node_browser_analysis "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/isolation-worker.js"
click node_analytics "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs"
click node_api_security "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/security.mjs"
click node_worker_api "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/build-worker.mjs"
click node_local_server "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/server.mjs"
click node_local_adapter "https://github.com/sahil-karkar/dysa-smart-energy/blob/main/local-db.mjs"

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_dashboard,node_insights,node_home_setup,node_scene,node_scene_boot,node_control_sync toneBlue
class node_home_state,node_safety_rules toneAmber
class node_usage_model,node_browser_analysis,node_analytics toneMint
class node_api_security,node_worker_api,node_local_server,node_local_adapter,node_database toneRose
class node_visitor toneIndigo
```

## Components

### Home experience

- [Energy dashboard](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/main.tsx): `src/main.tsx`
- [ML insights](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/MLInsights.tsx): `src/MLInsights.tsx`
- [Home setup](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/HomeSetup.tsx): `src/HomeSetup.tsx`
- [3D home scene](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/simulator/home.js): `simulator/home.js`
- [Scene bootstrap](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/simulator/boot.js): `simulator/boot.js`
- [Control synchronization](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/simulator/control-sync.js): `simulator/control-sync.js`

### Home simulation

- [Home state and API](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs): `profiles.mjs`
- [Safety rules](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs): `profiles.mjs`

### Energy analysis

- [Isolation Forest model](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/isolation-forest.mjs): `isolation-forest.mjs`
- [Browser pattern analysis](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/src/isolation-worker.js): `src/isolation-worker.js`
- [Usage analytics](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/profiles.mjs): `profiles.mjs`

### API and persistence

- [API security](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/security.mjs): `security.mjs`
- [Worker API entry](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/build-worker.mjs): `build-worker.mjs`
- [Local server](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/server.mjs): `server.mjs`
- [SQLite adapter](https://github.com/sahil-karkar/dysa-smart-energy/blob/main/local-db.mjs): `local-db.mjs`
- **Home data store**

### Other components

- **Visitor**

## Connections

- Visitor → Energy dashboard: explores (evidence: `README.md`)
- Visitor → 3D home scene: operates (evidence: `README.md`)
- Energy dashboard → Home state and API: requests home data
- Energy dashboard → ML insights: presents analysis
- Energy dashboard → Home setup: configures homes
- Scene bootstrap → 3D home scene: loads (evidence: `simulator/boot.js`)
- 3D home scene → Control synchronization: uses controls (evidence: `simulator/home.js`)
- Control synchronization → Home state and API: requests state and changes (evidence: `simulator/control-sync.js`)
- Home state and API → Safety rules: evaluates load (evidence: `profiles.mjs`)
- Home state and API → Isolation Forest model: evaluates usage (evidence: `profiles.mjs`)
- Home state and API → Usage analytics: builds usage history (evidence: `profiles.mjs`)
- Energy dashboard → Browser pattern analysis: runs pattern analysis
- ML insights → Browser pattern analysis: shows pattern results
- Worker API entry → API security: secures API requests (evidence: `build-worker.mjs`)
- Worker API entry → Home state and API: dispatches API (evidence: `build-worker.mjs`)
- API security → Home state and API: authorizes and invokes (evidence: `build-worker.mjs`)
- Local server → Worker API entry: forwards requests (evidence: `server.mjs`)
- Local server → SQLite adapter: opens database (evidence: `server.mjs`)
- Home state and API → Home data store: reads and writes (evidence: `profiles.mjs`)
- API security → Home data store: reads and writes limits and sessions (evidence: `security.mjs`)
- SQLite adapter → Home data store: implements local storage
