# hugofurther/cabane-control architecture

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

- Interactive diagram: https://gitdiagram.com/hugofurther/cabane-control
- Repository: https://github.com/hugofurther/cabane-control

## Overview

Cabane Control provides browser-based monitoring and remote operation for a maple-syrup pumping system, alongside physical controls and networked station controllers. The main workflow is an operator signing in, viewing live station and alarm state, then handing off control and changing switches; the backend coordinates commands and status over UDP and streams updates to the browser. Separate capabilities include administration, messaging and notes, weather, drainage/shutdown automation, and isolated simulation. The README documents hardware behavior and capabilities not fully represented in the sampled source; those links are shown only where the tree or excerpts support them.

Main entry points: [`Code/Server/cabane-control/server.js`](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/server.js) (HTTP and socket server), [`Code/Server/cabane-control/routes.js`](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes.js) (API route registry), [`Code/Server/cabane-control/services/simulation_service.js`](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/simulation_service.js) (Isolated station simulator), [`Code/Server/cabane-control/db.js`](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/db.js) (SQLite database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web Interface"]
  node_app["Control dashboard<br/>[App.jsx]"]
  node_socketctx["Live state context<br/>[SocketContext.jsx]"]
  node_stationcards["Station controls<br/>[StationCard.jsx]"]
  node_authpage["Sign-in UI<br/>[AuthPage.jsx]"]
end

subgraph group_backend["Backend Services"]
  node_server["HTTP and socket server<br/>[server.js]"]
  node_routes["API route registry<br/>[routes.js]"]
  node_email["Email delivery<br/>[email_service.js]"]
  node_db[("SQLite database<br/>[db.js]")]
end

subgraph group_accounts["Accounts &amp; Collaboration"]
  node_authroutes["Authentication routes<br/>[auth.js]"]
  node_authmw["Token authorization<br/>[auth.js]"]
  node_messaging["Messaging routes<br/>[messaging.js]"]
  node_notes["Notes routes<br/>[notes.js]"]
  node_admin["Administration routes<br/>[admin.js]"]
end

subgraph group_control["Station Control"]
  node_logic["Control and failsafe logic<br/>[logic_engine.js]"]
  node_udp["UDP controller bridge<br/>[udp_service.js]"]
end

subgraph group_ops["Operations"]
  node_automation["Drainage automation"]
  node_automationroutes["Automation routes<br/>[automation.js]"]
  node_simulation["Isolated station simulator"]
  node_simroutes["Simulation routes<br/>[simulation.js]"]
  node_weather["Weather service<br/>[weather_service.js]"]
end

node_operator(("Farm operator"))
node_browser(("Browser client"))
node_controllers{{"Physical controllers"}}
node_weatherprovider{{"Weather provider"}}

node_operator -->|"operates"| node_browser
node_browser -->|"uses"| node_app
node_app -->|"presents sign-in"| node_authpage
node_app -->|"presents controls"| node_stationcards
node_app -->|"uses live state"| node_socketctx
node_socketctx -->|"HTTP and Socket.IO"| node_server
node_server -->|"mounts API"| node_routes
node_server -->|"initializes"| node_logic
node_server -->|"initializes"| node_udp
node_server -->|"initializes"| node_weather
node_server -->|"initializes"| node_simulation
node_routes -->|"dispatches"| node_authroutes
node_routes -->|"dispatches"| node_messaging
node_routes -->|"dispatches"| node_notes
node_routes -->|"dispatches"| node_admin
node_routes -->|"dispatches"| node_automationroutes
node_routes -->|"dispatches"| node_simroutes
node_authroutes -->|"checks tokens"| node_authmw
node_authroutes -->|"reads and writes"| node_db
node_authroutes -->|"sends verification"| node_email
node_messaging -->|"reads and writes"| node_db
node_notes -->|"reads and writes"| node_db
node_admin -->|"reads and writes"| node_db
node_logic -->|"sends commands"| node_udp
node_udp -->|"UDP packets"| node_controllers
node_controllers -->|"feedback packets"| node_udp
node_logic -->|"emits state"| node_server
node_automationroutes -->|"dispatches"| node_automation
node_automation -->|"toggles real switches"| node_logic
node_automation -.->|"toggles simulated switches"| node_simulation
node_simroutes -->|"dispatches"| node_simulation
node_simulation -->|"stores configuration"| node_db
node_simulation -->|"emits simulation status"| node_server
node_weather -.->|"fetches weather"| node_weatherprovider
node_weather -->|"emits weather updates"| node_server
node_server -->|"streams state"| node_browser

click node_app "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/App.jsx"
click node_socketctx "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/contexts/SocketContext.jsx"
click node_stationcards "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/components/StationCard.jsx"
click node_authpage "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/components/AuthPage.jsx"
click node_server "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/server.js"
click node_routes "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes.js"
click node_authroutes "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/auth.js"
click node_authmw "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/middleware/auth.js"
click node_messaging "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/messaging.js"
click node_notes "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/notes.js"
click node_admin "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/admin.js"
click node_email "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/email_service.js"
click node_db "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/db.js"
click node_logic "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/logic_engine.js"
click node_udp "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/udp_service.js"
click node_automation "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/automation_service.js"
click node_automationroutes "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/automation.js"
click node_simulation "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/simulation_service.js"
click node_simroutes "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/simulation.js"
click node_weather "https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/weather_service.js"

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,node_socketctx,node_stationcards,node_authpage,node_browser toneBlue
class node_server,node_routes,node_email,node_db toneAmber
class node_authroutes,node_authmw,node_messaging,node_notes,node_admin toneMint
class node_logic,node_udp toneRose
class node_automation,node_automationroutes,node_simulation,node_simroutes,node_weather,node_operator,node_controllers,node_weatherprovider toneIndigo
```

## Components

### Web Interface

- [Control dashboard](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/App.jsx): `Code/Server/frontend/cabane-ui/src/App.jsx`
- [Live state context](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/contexts/SocketContext.jsx): `Code/Server/frontend/cabane-ui/src/contexts/SocketContext.jsx`
- [Station controls](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/components/StationCard.jsx): `Code/Server/frontend/cabane-ui/src/components/StationCard.jsx`
- [Sign-in UI](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/frontend/cabane-ui/src/components/AuthPage.jsx): `Code/Server/frontend/cabane-ui/src/components/AuthPage.jsx`

### Backend Services

- [HTTP and socket server](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/server.js): `Code/Server/cabane-control/server.js`
- [API route registry](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes.js): `Code/Server/cabane-control/routes.js`
- [Email delivery](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/email_service.js): `Code/Server/cabane-control/services/email_service.js`
- [SQLite database](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/db.js): `Code/Server/cabane-control/db.js`

### Accounts & Collaboration

- [Authentication routes](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/auth.js): `Code/Server/cabane-control/routes_split/auth.js`
- [Token authorization](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/middleware/auth.js): `Code/Server/cabane-control/middleware/auth.js`
- [Messaging routes](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/messaging.js): `Code/Server/cabane-control/routes_split/messaging.js`
- [Notes routes](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/notes.js): `Code/Server/cabane-control/routes_split/notes.js`
- [Administration routes](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/admin.js): `Code/Server/cabane-control/routes_split/admin.js`

### Station Control

- [Control and failsafe logic](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/logic_engine.js): `Code/Server/cabane-control/services/logic_engine.js`
- [UDP controller bridge](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/udp_service.js): `Code/Server/cabane-control/services/udp_service.js`

### Operations

- [Drainage automation](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/automation_service.js): `Code/Server/cabane-control/services/automation_service.js`
- [Automation routes](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/automation.js): `Code/Server/cabane-control/routes_split/automation.js`
- [Isolated station simulator](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/simulation_service.js): `Code/Server/cabane-control/services/simulation_service.js`
- [Simulation routes](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/routes_split/simulation.js): `Code/Server/cabane-control/routes_split/simulation.js`
- [Weather service](https://github.com/hugofurther/cabane-control/blob/main/Code/Server/cabane-control/services/weather_service.js): `Code/Server/cabane-control/services/weather_service.js`

### Other components

- **Farm operator**
- **Browser client**
- **Physical controllers**
- **Weather provider**

## Connections

- Farm operator → Browser client: operates
- Browser client → Control dashboard: uses
- Control dashboard → Sign-in UI: presents sign-in
- Control dashboard → Station controls: presents controls
- Control dashboard → Live state context: uses live state
- Live state context → HTTP and socket server: HTTP and Socket.IO
- HTTP and socket server → API route registry: mounts API
- HTTP and socket server → Control and failsafe logic: initializes
- HTTP and socket server → UDP controller bridge: initializes
- HTTP and socket server → Weather service: initializes
- HTTP and socket server → Isolated station simulator: initializes
- API route registry → Authentication routes: dispatches
- API route registry → Messaging routes: dispatches
- API route registry → Notes routes: dispatches
- API route registry → Administration routes: dispatches
- API route registry → Automation routes: dispatches
- API route registry → Simulation routes: dispatches
- Authentication routes → Token authorization: checks tokens
- Authentication routes → SQLite database: reads and writes
- Authentication routes → Email delivery: sends verification
- Messaging routes → SQLite database: reads and writes
- Notes routes → SQLite database: reads and writes
- Administration routes → SQLite database: reads and writes
- Control and failsafe logic → UDP controller bridge: sends commands
- UDP controller bridge → Physical controllers: UDP packets
- Physical controllers → UDP controller bridge: feedback packets
- Control and failsafe logic → HTTP and socket server: emits state
- Automation routes → Drainage automation: dispatches
- Drainage automation → Control and failsafe logic: toggles real switches
- Drainage automation → Isolated station simulator: toggles simulated switches
- Simulation routes → Isolated station simulator: dispatches
- Isolated station simulator → SQLite database: stores configuration
- Isolated station simulator → HTTP and socket server: emits simulation status
- Weather service → Weather provider: fetches weather
- Weather service → HTTP and socket server: emits weather updates
- HTTP and socket server → Browser client: streams state
