# sa8650/homecoreos architecture

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

- Interactive diagram: https://gitdiagram.com/sa8650/homecoreos
- Repository: https://github.com/sa8650/homecoreos

## Overview

HomecoreOS is a multi-user smart-home platform: users configure homes and hardware, register and manage boards, then monitor devices and run automations. The web console calls a Worker API that coordinates persistent account, board, and device state with MQTT messaging and firmware services; ESP32 firmware provisions, senses, and controls the physical fleet. Other major branches include board-library management, visual wiring, guided planning, recovery, USB flashing, and administration. The README documents the product flows; source excerpts confirm selected planner, automation, controller-config, auth, realtime, and firmware relationships, so unsampled links are omitted.

Main entry points: [`apps/web/src/App.tsx`](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/App.tsx) (User and Admin Console), [`apps/worker/src/index.ts`](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/index.ts) (Worker API), [`packages/shared/src/planner/board-capability.ts`](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/board-capability.ts) (Board Capabilities), [`apps/worker/src/lib/db.ts`](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/db.ts) (PostgreSQL State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_console["Web Console"]
  node_web["User and Admin Console<br/>[App.tsx]"]
  node_boardui["Boards and Setup"]
  node_floorplan["Home Floor Plan<br/>[HomeFloorPlan.tsx]"]
  node_plannerui["Smart Home Planner<br/>[PlannerWizard.tsx]"]
  node_automationui["Automation Builder"]
  node_flashui["USB Flash Wizard<br/>[UsbFlashWizard.tsx]"]
  node_recoveryui["Recovery Flow<br/>[recovery-engine.ts]"]
end

subgraph group_api["Worker Services"]
  node_api["Worker API<br/>[index.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_boardroutes["Board and Device APIs"]
  node_plannerapi["Planner API<br/>[planner.ts]"]
  node_automation["Automation Runtime"]
  node_controllerconfig["Controller Configuration"]
  node_notifications["Notifications<br/>[notifications.ts]"]
  node_realtime["Realtime Sync<br/>[realtime.ts]"]
  node_database[("PostgreSQL State<br/>[db.ts]")]
  node_mqtt["EMQX Messaging<br/>[emqx.ts]"]
end

subgraph group_shared["Shared Domain Logic"]
  node_planner["Planner Engine<br/>[engine.ts]"]
  node_allocation["Board Allocation<br/>[allocation.ts]"]
  node_capability["Board Capabilities"]
  node_catalog[("Board Catalog")]
  node_compat["Firmware Compatibility"]
  node_validation["Board Validation"]
  node_sensors["Sensor Driver Registry<br/>[sensor-drivers.ts]"]
end

subgraph group_device["Device Firmware"]
  node_firmware["ESP32 Firmware<br/>[main.c]"]
  node_role["Board Role Runtime<br/>[role_runtime.c]"]
  node_io["IO and Sensor Drivers<br/>[io_manager.c]"]
  node_devicebroker["Device MQTT Client<br/>[mqtt_manager.c]"]
end

node_user(("Homeowner"))
node_r2[("Private Firmware Storage")]
node_emqx["EMQX Broker"]

node_user -->|"uses"| node_web
node_web -->|"calls"| node_api
node_web -->|"manages boards"| node_boardui
node_web -->|"views home"| node_floorplan
node_web -->|"starts planning"| node_plannerui
node_web -->|"builds rules"| node_automationui
node_web -->|"flashes boards"| node_flashui
node_web -->|"recovers boards"| node_recoveryui
node_api -.->|"routes auth"| node_auth
node_api -.->|"routes requests"| node_boardroutes
node_api -.->|"routes planning"| node_plannerapi
node_plannerui -->|"submits plan"| node_plannerapi
node_plannerapi -.->|"analyzes home"| node_planner
node_planner -->|"allocates boards"| node_allocation
node_planner -->|"checks capability"| node_capability
node_planner -.->|"reads catalog"| node_catalog
node_capability -->|"reads board data"| node_catalog
node_capability -->|"checks compatibility"| node_compat
node_capability -->|"checks pin maps"| node_validation
node_sensors -->|"checks firmware"| node_compat
node_sensors -->|"validates GPIO"| node_validation
node_sensors -->|"reads layout facts"| node_capability
node_automationui -->|"configures automations"| node_boardroutes
node_automation -->|"emits alerts"| node_notifications
node_automation -.->|"reads state"| node_database
node_automation -->|"sends commands"| node_mqtt
node_boardroutes -.->|"builds snapshots"| node_controllerconfig
node_controllerconfig -->|"reads configuration"| node_database
node_controllerconfig -->|"publishes snapshots"| node_mqtt
node_controllerconfig -->|"publishes events"| node_realtime
node_auth -->|"stores sessions"| node_database
node_auth -->|"revokes credentials"| node_realtime
node_api -.->|"persists state"| node_database
node_api -->|"stores firmware"| node_r2
node_realtime -->|"manages sessions"| node_mqtt
node_realtime -.->|"reconciles snapshots"| node_database
node_firmware -->|"runs role logic"| node_role
node_firmware -->|"initializes IO"| node_io
node_role -->|"uses messaging"| node_devicebroker
node_devicebroker -->|"publishes MQTT"| node_emqx
node_mqtt -->|"controls broker"| node_emqx
node_flashui -->|"downloads firmware"| node_r2
node_recoveryui -.->|"requests recovery"| node_boardroutes

click node_web "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/App.tsx"
click node_boardui "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/controllers/ControllerSetupModal.tsx"
click node_floorplan "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/floorplan/HomeFloorPlan.tsx"
click node_plannerui "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/planner/PlannerWizard.tsx"
click node_automationui "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/automations/VisualAutomationBuilder.tsx"
click node_flashui "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/firmware/UsbFlashWizard.tsx"
click node_recoveryui "https://github.com/sa8650/homecoreos/blob/main/apps/web/src/lib/recovery-engine.ts"
click node_api "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/index.ts"
click node_auth "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/routes/auth.ts"
click node_boardroutes "https://github.com/sa8650/homecoreos/tree/main/apps/worker/src/routes"
click node_plannerapi "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/routes/planner.ts"
click node_automation "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/automation-engine.ts"
click node_controllerconfig "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/controller-config.ts"
click node_notifications "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/notifications.ts"
click node_realtime "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/realtime.ts"
click node_database "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/db.ts"
click node_mqtt "https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/emqx.ts"
click node_planner "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/engine.ts"
click node_allocation "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/allocation.ts"
click node_capability "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/board-capability.ts"
click node_catalog "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/board-catalog-data.ts"
click node_compat "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/board-firmware-compat.ts"
click node_validation "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/board-validation.ts"
click node_sensors "https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/sensor-drivers.ts"
click node_firmware "https://github.com/sa8650/homecoreos/blob/main/firmware/main/main.c"
click node_role "https://github.com/sa8650/homecoreos/blob/main/firmware/main/role_runtime.c"
click node_io "https://github.com/sa8650/homecoreos/blob/main/firmware/main/io_manager.c"
click node_devicebroker "https://github.com/sa8650/homecoreos/blob/main/firmware/main/mqtt_manager.c"

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_web,node_boardui,node_floorplan,node_plannerui,node_automationui,node_flashui,node_recoveryui toneBlue
class node_api,node_auth,node_boardroutes,node_plannerapi,node_automation,node_controllerconfig,node_notifications,node_realtime,node_database,node_mqtt,node_r2 toneAmber
class node_planner,node_allocation,node_capability,node_catalog,node_compat,node_validation,node_sensors toneMint
class node_firmware,node_role,node_io,node_devicebroker toneRose
class node_user,node_emqx toneIndigo
```

## Components

### Web Console

- [User and Admin Console](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [Boards and Setup](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/controllers/ControllerSetupModal.tsx): `apps/web/src/components/controllers/ControllerSetupModal.tsx`
- [Home Floor Plan](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/floorplan/HomeFloorPlan.tsx): `apps/web/src/components/floorplan/HomeFloorPlan.tsx`
- [Smart Home Planner](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/planner/PlannerWizard.tsx): `apps/web/src/components/planner/PlannerWizard.tsx`
- [Automation Builder](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/automations/VisualAutomationBuilder.tsx): `apps/web/src/components/automations/VisualAutomationBuilder.tsx`
- [USB Flash Wizard](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/components/firmware/UsbFlashWizard.tsx): `apps/web/src/components/firmware/UsbFlashWizard.tsx`
- [Recovery Flow](https://github.com/sa8650/homecoreos/blob/main/apps/web/src/lib/recovery-engine.ts): `apps/web/src/lib/recovery-engine.ts`

### Worker Services

- [Worker API](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/index.ts): `apps/worker/src/index.ts`
- [Authentication](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/routes/auth.ts): `apps/worker/src/routes/auth.ts`
- [Board and Device APIs](https://github.com/sa8650/homecoreos/tree/main/apps/worker/src/routes): `apps/worker/src/routes`
- [Planner API](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/routes/planner.ts): `apps/worker/src/routes/planner.ts`
- [Automation Runtime](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/automation-engine.ts): `apps/worker/src/lib/automation-engine.ts`
- [Controller Configuration](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/controller-config.ts): `apps/worker/src/lib/controller-config.ts`
- [Notifications](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/notifications.ts): `apps/worker/src/lib/notifications.ts`
- [Realtime Sync](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/realtime.ts): `apps/worker/src/lib/realtime.ts`
- [PostgreSQL State](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/db.ts): `apps/worker/src/lib/db.ts`
- [EMQX Messaging](https://github.com/sa8650/homecoreos/blob/main/apps/worker/src/lib/emqx.ts): `apps/worker/src/lib/emqx.ts`

### Shared Domain Logic

- [Planner Engine](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/engine.ts): `packages/shared/src/planner/engine.ts`
- [Board Allocation](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/allocation.ts): `packages/shared/src/planner/allocation.ts`
- [Board Capabilities](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/planner/board-capability.ts): `packages/shared/src/planner/board-capability.ts`
- [Board Catalog](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/board-catalog-data.ts): `packages/shared/src/board-catalog-data.ts`
- [Firmware Compatibility](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/board-firmware-compat.ts): `packages/shared/src/board-firmware-compat.ts`
- [Board Validation](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/board-validation.ts): `packages/shared/src/board-validation.ts`
- [Sensor Driver Registry](https://github.com/sa8650/homecoreos/blob/main/packages/shared/src/sensor-drivers.ts): `packages/shared/src/sensor-drivers.ts`

### Device Firmware

- [ESP32 Firmware](https://github.com/sa8650/homecoreos/blob/main/firmware/main/main.c): `firmware/main/main.c`
- [Board Role Runtime](https://github.com/sa8650/homecoreos/blob/main/firmware/main/role_runtime.c): `firmware/main/role_runtime.c`
- [IO and Sensor Drivers](https://github.com/sa8650/homecoreos/blob/main/firmware/main/io_manager.c): `firmware/main/io_manager.c`
- [Device MQTT Client](https://github.com/sa8650/homecoreos/blob/main/firmware/main/mqtt_manager.c): `firmware/main/mqtt_manager.c`

### Other components

- **Homeowner**
- **Private Firmware Storage**
- **EMQX Broker**

## Connections

- Homeowner → User and Admin Console: uses (evidence: `README.md`)
- User and Admin Console → Worker API: calls (evidence: `README.md`)
- User and Admin Console → Boards and Setup: manages boards (evidence: `README.md`)
- User and Admin Console → Home Floor Plan: views home (evidence: `README.md`)
- User and Admin Console → Smart Home Planner: starts planning (evidence: `README.md`)
- User and Admin Console → Automation Builder: builds rules (evidence: `README.md`)
- User and Admin Console → USB Flash Wizard: flashes boards (evidence: `README.md`)
- User and Admin Console → Recovery Flow: recovers boards (evidence: `README.md`)
- Worker API → Authentication: routes auth
- Worker API → Board and Device APIs: routes requests
- Worker API → Planner API: routes planning
- Smart Home Planner → Planner API: submits plan (evidence: `README.md`)
- Planner API → Planner Engine: analyzes home
- Planner Engine → Board Allocation: allocates boards (evidence: `packages/shared/src/planner/engine.ts`)
- Planner Engine → Board Capabilities: checks capability (evidence: `packages/shared/src/planner/engine.ts`)
- Planner Engine → Board Catalog: reads catalog
- Board Capabilities → Board Catalog: reads board data (evidence: `packages/shared/src/planner/board-capability.ts`)
- Board Capabilities → Firmware Compatibility: checks compatibility (evidence: `packages/shared/src/planner/board-capability.ts`)
- Board Capabilities → Board Validation: checks pin maps (evidence: `packages/shared/src/planner/board-capability.ts`)
- Sensor Driver Registry → Firmware Compatibility: checks firmware (evidence: `packages/shared/src/sensor-drivers.ts`)
- Sensor Driver Registry → Board Validation: validates GPIO (evidence: `packages/shared/src/sensor-drivers.ts`)
- Sensor Driver Registry → Board Capabilities: reads layout facts (evidence: `packages/shared/src/sensor-drivers.ts`)
- Automation Builder → Board and Device APIs: configures automations (evidence: `README.md`)
- Automation Runtime → Notifications: emits alerts (evidence: `apps/worker/src/lib/automation-engine.ts`)
- Automation Runtime → PostgreSQL State: reads state (evidence: `apps/worker/src/lib/automation-engine.ts`)
- Automation Runtime → EMQX Messaging: sends commands (evidence: `apps/worker/src/lib/automation-engine.ts`)
- Board and Device APIs → Controller Configuration: builds snapshots
- Controller Configuration → PostgreSQL State: reads configuration (evidence: `apps/worker/src/lib/controller-config.ts`)
- Controller Configuration → EMQX Messaging: publishes snapshots (evidence: `apps/worker/src/lib/controller-config.ts`)
- Controller Configuration → Realtime Sync: publishes events (evidence: `apps/worker/src/lib/controller-config.ts`)
- Authentication → PostgreSQL State: stores sessions (evidence: `apps/worker/src/routes/auth.ts`)
- Authentication → Realtime Sync: revokes credentials (evidence: `apps/worker/src/routes/auth.ts`)
- Worker API → PostgreSQL State: persists state
- Worker API → Private Firmware Storage: stores firmware (evidence: `README.md`)
- Realtime Sync → EMQX Messaging: manages sessions (evidence: `apps/worker/src/lib/realtime.ts`)
- Realtime Sync → PostgreSQL State: reconciles snapshots (evidence: `apps/worker/src/lib/realtime.ts`)
- ESP32 Firmware → Board Role Runtime: runs role logic (evidence: `firmware/main/main.c`)
- ESP32 Firmware → IO and Sensor Drivers: initializes IO (evidence: `firmware/main/main.c`)
- Board Role Runtime → Device MQTT Client: uses messaging (evidence: `firmware/main/mqtt_manager.c`)
- Device MQTT Client → EMQX Broker: publishes MQTT (evidence: `README.md`)
- EMQX Messaging → EMQX Broker: controls broker
- USB Flash Wizard → Private Firmware Storage: downloads firmware (evidence: `README.md`)
- Recovery Flow → Board and Device APIs: requests recovery
