EdgeBrain uses a modular monolith architecture with clear module boundaries. This choice is deliberate:
- Modular monolith over microservices because the system is designed to run locally on a single machine. Microservices add network complexity, operational overhead, and resource costs that don't make sense for an edge platform running on one host. Each module can be extracted into a microservice later if needed β the interfaces are clean enough.
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Dashboard β
β (React + WebSocket) β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β HTTP / WS
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β FastAPI Backend β
β ββββββββββββ ββββββββββββ ββββββββββββββββββ β
β β REST API β βWebSocketβ β Event Engine β β
β ββββββ¬ββββββ ββββββ¬ββββββ βββββββββ¬βββββββββ β
β β β β β
β ββββββΌβββββββββββββΌββββββββββββββββΌβββββββββ β
β β Multi-Agent System β β
β β βββββββββββ ββββββββββββ βββββββββββββ β β
β β β Data β β Decision β β Action β β β
β β β Agent βββ Agent βββ Agent β β β
β β βββββββββββ ββββββββββββ βββββββββββββ β β
β βββββββββββββββββββββ¬ββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββΌββββββββββββββββββββββββ β
β β Decision Engine β β
β β ββββββββββββ ββββββββββββββββββββββ β β
β β β Rules β β Anomaly Detector β β β
β β β(Threshold)β β (Z-Score, CPU) β β β
β β ββββββββββββ ββββββββββββββββββββββ β β
β βββββββββββββββββββββ¬ββββββββββββββββββββββββ β
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββ
β MQTT
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββ
β MQTT Broker (Mosquitto) β
ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββ
β β
ββββββββββββΌβββββββββββ βββββββββββββΌβββββββββββ
β Device Simulator β β ESP32 (optional) β
β (11 virtual devices)β β (real hardware) β
βββββββββββββββββββββββ ββββββββββββββββββββββββ
sequenceDiagram
participant S as Sensor/Simulator
participant M as MQTT Broker
participant B as FastAPI Backend
participant DA as Data Agent
participant DEC as Decision Agent
participant AA as Action Agent
participant DB as PostgreSQL
participant A as Actuator
S->>M: device/{id}/data
M->>B: MQTT message
B->>DA: process reading
DA->>DB: store reading
DA->>DEC: evaluate
DEC->>DEC: rules + anomaly check
DEC->>AA: decision
AA->>M: device/{id}/command
AA->>DB: store alert (if needed)
M->>A: activate/deactivate
| Topic Pattern | Direction | Purpose |
|---|---|---|
device/+/data |
Device β Backend | Sensor readings |
device/+/command |
Backend β Device | Actuator commands |
-
Data Agent receives raw sensor reading
-
Validates value ranges
-
Stores in PostgreSQL
-
Passes to Decision Agent
-
Decision Agent evaluates through all registered strategies:
- ThresholdStrategy: rule-based triggers
- AnomalyDetector: z-score, IQR, gradient anomaly detection
- NoMotionStrategy: timeout-based light control
-
Returns list of Decision objects
-
Action Agent:
- Creates alerts for warning/critical decisions
- Publishes commands via MQTT
- Logs to Redis event queue
Five database tables:
sensor_readingsβ time-series sensor data (with timestamp index)device_commandsβ actuator commands sentalertsβ system alerts with severity levelsdevice_statesβ current device state cacheactuator_statesβ actuator on/off state tracking
Add new decision strategies by implementing the DecisionStrategy interface:
from app.ai.rules import DecisionStrategy, Decision
class MyStrategy(DecisionStrategy):
@property
def name(self) -> str:
return "my_strategy"
def evaluate(self, device_id, device_type, value, history):
if value > MY_THRESHOLD:
return [Decision(
action="activate",
device_id=device_id,
params={"actuator": "alarm"},
reason="Custom threshold exceeded",
confidence=0.9,
)]
return []Then register it:
from app.agents.multi_agent import agents
agents.engine.add_strategy(MyStrategy())If you need to scale beyond a single machine:
- Extract the event engine into a separate service
- Use TimescaleDB for better time-series performance
- Add a message broker (RabbitMQ) between agents
- Deploy dashboard behind Nginx with SSL
- Use Kubernetes for orchestration
The modular monolith makes each of these steps straightforward.