# dankehidayat/selene architecture

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

- Interactive diagram: https://gitdiagram.com/dankehidayat/selene
- Repository: https://github.com/dankehidayat/selene

## Overview

Selene collects energy and climate telemetry from IoT sensors, stores readings for analysis, and presents live dashboards and analytics through a web app. The primary documented production workflow runs through the backend monolith, which also handles authentication, notifications, and firmware management; a standalone ingestor and domain-split services are alternate or evolving deployments. The graph includes those documented capabilities, while some subsystem links rely on README descriptions because their implementation files were not sampled.

Main entry points: [`apps/backend/src/index.ts`](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/index.ts) (Fastify backend), [`apps/backend/src/routes/auth.ts`](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/auth.ts) (Authentication routes), [`packages/sensors/src/parsers/registry.ts`](https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/registry.ts) (Parser registry), [`apps/backend/src/timescale.ts`](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/timescale.ts) (Readings store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Telemetry ingestion"]
  node_mqtt["Monolith MQTT client<br/>[mqtt.ts]"]
  node_parsers["Parser registry<br/>[registry.ts]"]
  node_energyparser["Energy parser<br/>[energy.ts]"]
  node_climateparser["Climate parser<br/>[climate.ts]"]
  node_sensorstore[("Readings store<br/>[timescale.ts]")]
end

subgraph group_backend["Monolith API"]
  node_userstore[("User and settings store<br/>[db.ts]")]
  node_api["Fastify backend<br/>[index.ts]"]
  node_authroutes["Authentication routes<br/>[auth.ts]"]
  node_authlogic["Auth and tokens<br/>[auth.ts]"]
  node_totp["Two-factor auth<br/>[totp.ts]"]
  node_mail["Email delivery<br/>[mail.ts]"]
  node_analytics["Analytics queries<br/>[timescale.ts]"]
  node_firmware["Firmware management<br/>[firmware.ts]"]
  node_notifications["Notifications<br/>[notifications.ts]"]
end

subgraph group_web["Web application"]
  node_spa["React application<br/>[main.tsx]"]
  node_router["Page router<br/>[router.tsx]"]
  node_dashboard["Dashboard and charts<br/>[Dashboard.tsx]"]
  node_analyticsui["Analytics and logs<br/>[Analytics.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_modular["Domain services"]
  node_ingestor["Standalone ingestor<br/>[index.ts]"]
  node_analytics_service["Analytics service<br/>[routes.ts]"]
  node_analytics_db["Analytics data access<br/>[db.ts]"]
  node_fuzzy["Fuzzy analytics<br/>[fuzzy.ts]"]
  node_auth_service["Auth service<br/>[auth.ts]"]
  node_sessions["Session management<br/>[sessions.ts]"]
  node_domain_services["Energy and climate services<br/>[index.ts]"]
  node_firmware_service["Firmware service<br/>[index.ts]"]
end

node_devices(("ESP32 sensors"))
node_broker(("MQTT broker"))
node_user(("Web user"))

node_devices -->|"publishes telemetry"| node_broker
node_broker -->|"delivers MQTT"| node_mqtt
node_mqtt -->|"dispatches payloads"| node_parsers
node_parsers -->|"selects parser"| node_energyparser
node_parsers -->|"selects parser"| node_climateparser
node_parsers -->|"inserts readings"| node_sensorstore
node_user -->|"uses dashboard"| node_spa
node_spa -->|"renders routes"| node_router
node_router -->|"routes to"| node_dashboard
node_router -->|"routes to"| node_analyticsui
node_dashboard -.->|"requests data"| node_api_client
node_analyticsui -.->|"requests analytics"| node_api_client
node_api_client -->|"calls API"| node_api
node_api -.->|"registers routes"| node_authroutes
node_authroutes -->|"reads and writes"| node_userstore
node_authroutes -->|"uses tokens"| node_authlogic
node_authroutes -->|"uses TOTP"| node_totp
node_authroutes -->|"sends reset email"| node_mail
node_api -.->|"serves analytics"| node_analytics
node_api -.->|"registers routes"| node_firmware
node_api -.->|"registers routes"| node_notifications
node_api -->|"queries readings"| node_sensorstore
node_ingestor -->|"subscribes MQTT"| node_broker
node_ingestor -->|"uses registry"| node_parsers
node_ingestor -->|"writes readings"| node_sensorstore
node_analytics_service -->|"queries readings"| node_analytics_db
node_analytics_service -->|"runs fuzzy analysis"| node_fuzzy
node_analytics_service -->|"loads ranges"| node_analytics_db
node_auth_service -->|"issues sessions"| node_sessions
node_auth_service -.->|"uses auth database"| node_userstore
node_domain_services -.->|"uses readings"| node_sensorstore
node_firmware_service -->|"sends MQTT commands"| node_broker

click node_mqtt "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/mqtt.ts"
click node_parsers "https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/registry.ts"
click node_energyparser "https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/energy.ts"
click node_climateparser "https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/climate.ts"
click node_sensorstore "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/timescale.ts"
click node_userstore "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/db.ts"
click node_api "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/index.ts"
click node_authroutes "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/auth.ts"
click node_authlogic "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/auth.ts"
click node_totp "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/totp.ts"
click node_mail "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/mail.ts"
click node_analytics "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/timescale.ts"
click node_firmware "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/firmware.ts"
click node_notifications "https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/notifications.ts"
click node_spa "https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/main.tsx"
click node_router "https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/router.tsx"
click node_dashboard "https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/pages/Dashboard.tsx"
click node_analyticsui "https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/pages/Analytics.tsx"
click node_api_client "https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/services/api.ts"
click node_ingestor "https://github.com/dankehidayat/selene/blob/master/services/ingestor/src/index.ts"
click node_analytics_service "https://github.com/dankehidayat/selene/blob/master/services/analytics/src/routes.ts"
click node_analytics_db "https://github.com/dankehidayat/selene/blob/master/services/analytics/src/db.ts"
click node_fuzzy "https://github.com/dankehidayat/selene/blob/master/packages/shared/src/analytics/fuzzy.ts"
click node_auth_service "https://github.com/dankehidayat/selene/blob/master/services/auth/src/routes/auth.ts"
click node_sessions "https://github.com/dankehidayat/selene/blob/master/services/auth/src/sessions.ts"
click node_domain_services "https://github.com/dankehidayat/selene/blob/master/services/energy/src/index.ts"
click node_firmware_service "https://github.com/dankehidayat/selene/blob/master/services/firmware/src/index.ts"

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_mqtt,node_parsers,node_energyparser,node_climateparser,node_sensorstore,node_user toneBlue
class node_userstore,node_api,node_authroutes,node_authlogic,node_totp,node_mail,node_analytics,node_firmware,node_notifications toneAmber
class node_spa,node_router,node_dashboard,node_analyticsui,node_api_client toneMint
class node_ingestor,node_analytics_service,node_analytics_db,node_fuzzy,node_auth_service,node_sessions,node_domain_services,node_firmware_service toneRose
class node_devices,node_broker toneIndigo
```

## Components

### Telemetry ingestion

- [Monolith MQTT client](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/mqtt.ts): `apps/backend/src/mqtt.ts`
- [Parser registry](https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/registry.ts): `packages/sensors/src/parsers/registry.ts`
- [Energy parser](https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/energy.ts): `packages/sensors/src/parsers/energy.ts`
- [Climate parser](https://github.com/dankehidayat/selene/blob/master/packages/sensors/src/parsers/climate.ts): `packages/sensors/src/parsers/climate.ts`
- [Readings store](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/timescale.ts): `apps/backend/src/timescale.ts`

### Monolith API

- [User and settings store](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/db.ts): `apps/backend/src/db.ts`
- [Fastify backend](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/index.ts): `apps/backend/src/index.ts`
- [Authentication routes](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/auth.ts): `apps/backend/src/routes/auth.ts`
- [Auth and tokens](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/auth.ts): `apps/backend/src/auth.ts`
- [Two-factor auth](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/totp.ts): `apps/backend/src/totp.ts`
- [Email delivery](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/mail.ts): `apps/backend/src/mail.ts`
- [Analytics queries](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/timescale.ts): `apps/backend/src/timescale.ts`
- [Firmware management](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/firmware.ts): `apps/backend/src/routes/firmware.ts`
- [Notifications](https://github.com/dankehidayat/selene/blob/master/apps/backend/src/routes/notifications.ts): `apps/backend/src/routes/notifications.ts`

### Web application

- [React application](https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/main.tsx): `apps/frontend/src/main.tsx`
- [Page router](https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/router.tsx): `apps/frontend/src/router.tsx`
- [Dashboard and charts](https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/pages/Dashboard.tsx): `apps/frontend/src/pages/Dashboard.tsx`
- [Analytics and logs](https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/pages/Analytics.tsx): `apps/frontend/src/pages/Analytics.tsx`
- [API client](https://github.com/dankehidayat/selene/blob/master/apps/frontend/src/services/api.ts): `apps/frontend/src/services/api.ts`

### Domain services

- [Standalone ingestor](https://github.com/dankehidayat/selene/blob/master/services/ingestor/src/index.ts): `services/ingestor/src/index.ts`
- [Analytics service](https://github.com/dankehidayat/selene/blob/master/services/analytics/src/routes.ts): `services/analytics/src/routes.ts`
- [Analytics data access](https://github.com/dankehidayat/selene/blob/master/services/analytics/src/db.ts): `services/analytics/src/db.ts`
- [Fuzzy analytics](https://github.com/dankehidayat/selene/blob/master/packages/shared/src/analytics/fuzzy.ts): `packages/shared/src/analytics/fuzzy.ts`
- [Auth service](https://github.com/dankehidayat/selene/blob/master/services/auth/src/routes/auth.ts): `services/auth/src/routes/auth.ts`
- [Session management](https://github.com/dankehidayat/selene/blob/master/services/auth/src/sessions.ts): `services/auth/src/sessions.ts`
- [Energy and climate services](https://github.com/dankehidayat/selene/blob/master/services/energy/src/index.ts): `services/energy/src/index.ts`
- [Firmware service](https://github.com/dankehidayat/selene/blob/master/services/firmware/src/index.ts): `services/firmware/src/index.ts`

### Other components

- **ESP32 sensors**
- **MQTT broker**
- **Web user**

## Connections

- ESP32 sensors → MQTT broker: publishes telemetry
- MQTT broker → Monolith MQTT client: delivers MQTT
- Monolith MQTT client → Parser registry: dispatches payloads
- Parser registry → Energy parser: selects parser (evidence: `packages/sensors/src/parsers/registry.ts`)
- Parser registry → Climate parser: selects parser (evidence: `packages/sensors/src/parsers/registry.ts`)
- Parser registry → Readings store: inserts readings
- Web user → React application: uses dashboard
- React application → Page router: renders routes (evidence: `apps/frontend/src/main.tsx`)
- Page router → Dashboard and charts: routes to (evidence: `apps/frontend/src/router.tsx`)
- Page router → Analytics and logs: routes to (evidence: `apps/frontend/src/router.tsx`)
- Dashboard and charts → API client: requests data
- Analytics and logs → API client: requests analytics
- API client → Fastify backend: calls API
- Fastify backend → Authentication routes: registers routes
- Authentication routes → User and settings store: reads and writes (evidence: `apps/backend/src/routes/auth.ts`)
- Authentication routes → Auth and tokens: uses tokens (evidence: `apps/backend/src/routes/auth.ts`)
- Authentication routes → Two-factor auth: uses TOTP (evidence: `apps/backend/src/routes/auth.ts`)
- Authentication routes → Email delivery: sends reset email (evidence: `apps/backend/src/routes/auth.ts`)
- Fastify backend → Analytics queries: serves analytics
- Fastify backend → Firmware management: registers routes
- Fastify backend → Notifications: registers routes
- Fastify backend → Readings store: queries readings
- Standalone ingestor → MQTT broker: subscribes MQTT
- Standalone ingestor → Parser registry: uses registry (evidence: `services/ingestor/src/index.ts`)
- Standalone ingestor → Readings store: writes readings
- Analytics service → Analytics data access: queries readings (evidence: `services/analytics/src/routes.ts`)
- Analytics service → Fuzzy analytics: runs fuzzy analysis (evidence: `services/analytics/src/routes.ts`)
- Analytics service → Analytics data access: loads ranges (evidence: `services/analytics/src/routes.ts`)
- Auth service → Session management: issues sessions (evidence: `services/auth/src/routes/auth.ts`)
- Auth service → User and settings store: uses auth database
- Energy and climate services → Readings store: uses readings
- Firmware service → MQTT broker: sends MQTT commands
