Skip to content

rudra496/EdgeBrain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

──────────────────────────────────────────────────────────────

🧠 EdgeBrain β€” AI-Powered Edge Intelligence Platform

──────────────────────────────────────────────────────────────

Autonomous real-world decision systems. 100% local. Zero paid APIs.

──────────────────────────────────────────────────────────────

Version



The most comprehensive open-source edge AI platform.

Simulate β†’ Process β†’ Decide β†’ Act β€” all locally, all free.

CI Release License Docker Pulls Python FastAPI React PostgreSQL Redis MQTT Stars Forks Issues 100% Free No Cloud Local First Privacy


Zero paid APIs Β· Zero cloud lock-in Β· Zero proprietary dependencies


🎬 Demo

# Clone & run in under 2 minutes
git clone https://github.com/rudra496/EdgeBrain.git && cd EdgeBrain
docker compose up --build -d
# Open http://localhost:3000 β€” done.

What you'll see:

  • 🌑️ Live temperature, humidity, energy, light charts
  • πŸ€– AI agents making decisions in real-time
  • 🚨 Alerts firing when anomalies are detected
  • πŸ’‘ Lights auto-on with motion, auto-off after 5 min
  • πŸŒ€ Fan activation when temperature exceeds 30Β°C
  • πŸ“Š Full agent message pipeline visualization

✨ Features

🏠 Smart Device Simulation (11 devices)
  • 3 rooms β€” Living Room (5 sensors), Bedroom (3 sensors), Server Room (3 sensors)
  • 5 sensor types β€” Temperature, Motion, Energy, Humidity, Light
  • Realistic patterns β€” circadian rhythms, Gaussian noise, mean reversion
  • Rare event simulation β€” temperature spikes (1%), energy surges (0.5%)
  • Configurable β€” base values, noise scale, spike probability per device
  • Time-aware β€” energy peaks during work hours, light follows sunrise/sunset
πŸ€– Multi-Agent AI System
  • Data Agent β€” validates ranges, stores readings, routes to decision pipeline
  • Decision Agent β€” runs all strategies, deduplicates, ranks by confidence
  • Action Agent β€” creates alerts, sends MQTT commands, updates actuator state
  • Message Bus β€” full queryable log with agent performance tracking
  • Per-agent metrics β€” average processing time, message count, error rate
🧠 AI Decision Engine (3 strategies)
  • Threshold Rules β€” configurable per device type, with hysteresis to prevent flapping
  • Anomaly Detection β€” 3 statistical methods vote: Z-Score, IQR, Gradient
    • Requires 2+ methods to agree (reduces false positives by ~70%)
  • No-Motion Timeout β€” turns off lights after configurable inactivity period
  • Plugin Architecture β€” add custom strategies via DecisionStrategy interface
    • Just implement evaluate() and name β€” that's it
πŸ“ˆ Predictive Analytics
  • Trend Prediction β€” linear regression on recent readings to forecast next value
  • Moving Averages β€” SMA and EMA for smoothing noisy sensor data
  • Anomaly Score β€” combined confidence from all detection methods
  • Forecasting β€” 10-step ahead prediction for temperature and energy
πŸ“Š Real-Time Dashboard (5 pages)
  • Dashboard β€” stats overview, live charts, event feed, recent alerts
  • Devices β€” all sensor states with room grouping, online/offline status
  • Analytics β€” historical charts, trend predictions, device comparisons
  • Agents β€” pipeline visualization, message log, strategy config, performance
  • Settings β€” system configuration, thresholds, export data, system info
πŸ”Œ Communication & Integration
  • MQTT 5.0 β€” topic-based architecture with QoS support
  • WebSocket β€” real-time bidirectional dashboard updates
  • REST API β€” 20+ endpoints with auto-generated OpenAPI docs
  • Data Export β€” CSV and JSON export for any device's readings
  • Webhook Support β€” configurable webhook for alert notifications
πŸ—οΈ Production Infrastructure
  • Docker Compose β€” 6 services, health checks, restart policies, volumes
  • PostgreSQL β€” composite indexes, JSONB fields, time-series optimized
  • Redis β€” event queuing, pub/sub, alert cache, live telemetry
  • GitHub Actions β€” CI (tests + lint) + Release (Docker + Git tag)
  • Makefile β€” one-command operations: make dev, make test, make release
πŸ”§ Optional Hardware
  • ESP32 firmware β€” Arduino C++ with WiFi + MQTT
  • DHT11 β€” temperature & humidity sensor
  • PIR β€” passive infrared motion sensor
  • LED + Buzzer β€” actuator control
  • Configurable β€” just edit WiFi + MQTT credentials

⚑ Quick Start

Prerequisites

Install & Run

git clone https://github.com/rudra496/EdgeBrain.git
cd EdgeBrain
docker compose up --build -d

Or use Make

make setup        # Clone (if not already), build, and start
make dev          # Start in development mode
make test         # Run test suite
make logs         # Tail all service logs
make stop         # Stop all services
make clean        # Stop + remove volumes

Access Points

Service URL Description
πŸ–₯️ Dashboard http://localhost:3000 React real-time dashboard
πŸ“‘ Swagger API http://localhost:8000/docs Interactive API explorer
πŸ“– ReDoc http://localhost:8000/redoc Alternative API docs
❀️ Health http://localhost:8000/api/v1/health System health check
🐝 MQTT localhost:1883 Mosquitto broker
πŸ“‘ MQTT/WS localhost:9001 MQTT over WebSocket

Verify Everything

# Health check
curl -s http://localhost:8000/api/v1/health | python3 -m json.tool

# System statistics
curl -s http://localhost:8000/api/v1/stats | python3 -m json.tool

# Device list
curl -s http://localhost:8000/api/v1/devices | python3 -m json.tool

# Recent alerts
curl -s http://localhost:8000/api/v1/alerts | python3 -m json.tool

# Agent performance
curl -s http://localhost:8000/api/v1/agents/stats | python3 -m json.tool

πŸ—οΈ Architecture

graph TB
    subgraph Edge["πŸ”Œ Edge Layer"]
        S1["🌑️ Temp β€” Room 1"]
        S2["πŸƒ Motion β€” Room 1"]
        S3["⚑ Energy β€” Room 1"]
        S4["πŸ’§ Humidity β€” Room 1"]
        S5["β˜€οΈ Light β€” Room 1"]
        S6["🌑️ Temp β€” Room 2"]
        S7["πŸƒ Motion β€” Room 2"]
        S8["⚑ Energy β€” Room 2"]
        S9["🌑️ Temp β€” Server Room"]
        S10["πŸ’§ Humidity β€” Server Room"]
        S11["⚑ Energy β€” Server Room"]
        ESP["πŸ“‘ ESP32 β€” Optional"]
    end

    subgraph Comms["πŸ“‘ Communication Layer"]
        MQTT["Mosquitto MQTT 5.0"]
    end

    subgraph BE["🧠 Backend (FastAPI)"]
        API["REST + WebSocket API"]
        PIPE["Data Pipeline"]
        EVT["Event Engine"]
        EXEC["Execution Engine"]
        PRED["Prediction Engine"]
    end

    subgraph AI["πŸ€– AI / Decision Engine"]
        DA["Data Agent"]
        DEC["Decision Agent"]
        AA["Action Agent"]
        RULE["Rule Engine<br/>+ Hysteresis"]
        ANOM["Anomaly Detector<br/>Z-Score Β· IQR Β· Gradient"]
        PREDAI["Predictor<br/>Linear Regression"]
        PLUG["Plugin System"]
    end

    subgraph Data["πŸ’Ύ Data Layer"]
        PG[("PostgreSQL 16")]
        REDIS[("Redis 7")]
    end

    subgraph FE["πŸ–₯️ Frontend"]
        DASH["React Dashboard<br/>5 Pages Β· WebSocket"]
    end

    S1 & S2 & S3 & S4 & S5 & S6 & S7 & S8 & S9 & S10 & S11 & ESP -->|"device/+/data"| MQTT
    MQTT -->|"subscribe"| PIPE
    PIPE -->|"store"| PG
    PIPE -->|"route"| DA
    DA -->|"validate"| DEC
    RULE & ANOM & PREDAI --> DEC
    PLUG --> DEC
    DEC -->|"decisions"| AA
    AA -->|"alerts"| EVT
    AA -->|"commands"| EXEC
    EVT --> REDIS
    REDIS -->|"broadcast"| DASH
    EXEC -->|"device/+/command"| MQTT
    MQTT -->|"actuate"| S1 & S2 & S3
    API <-->|"HTTP/WS"| DASH
    API --> PG
    API --> REDIS
Loading

Decision Pipeline

sequenceDiagram
    participant S as Sensor
    participant M as MQTT
    participant DA as Data Agent
    participant DB as PostgreSQL
    participant DEC as Decision Agent
    participant AA as Action Agent
    participant A as Alert/Redis
    participant CMD as MQTT Command
    participant ACT as Actuator

    S->>M: device/room-1/data {temp: 35Β°C}
    M->>DA: route message
    DA->>DA: validate range
    DA->>DB: store reading
    DA->>DEC: evaluate(device, type, value)
    DEC->>DEC: ThresholdStrategy β†’ fan ON
    DEC->>DEC: AnomalyDetector β†’ normal
    DEC->>DEC: deduplicate + rank
    DEC->>AA: [Decision: activate fan]
    AA->>A: push alert to Redis
    AA->>CMD: device/room-1-actuator-fan/command
    CMD->>ACT: activate fan
    A-->>Dashboard: WebSocket broadcast
Loading

πŸ“ Project Structure

EdgeBrain/
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE/
β”‚   β”‚   β”œβ”€β”€ bug_report.yml          # Structured bug reports
β”‚   β”‚   └── feature_request.yml     # Structured feature requests
β”‚   └── PULL_REQUEST_TEMPLATE.md    # PR checklist
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ routes.py           # 20+ REST endpoints + WebSocket
β”‚   β”‚   β”‚   └── schemas.py          # Pydantic request/response models
β”‚   β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”‚   β”œβ”€β”€ config.py           # Settings with env vars
β”‚   β”‚   β”‚   β”œβ”€β”€ database.py         # SQLAlchemy engine + sessions
β”‚   β”‚   β”‚   β”œβ”€β”€ mqtt_client.py      # Thread-safe MQTT with reconnect
β”‚   β”‚   β”‚   └── events.py           # Redis queue + pub/sub
β”‚   β”‚   β”œβ”€β”€ ai/
β”‚   β”‚   β”‚   β”œβ”€β”€ rules.py            # Rule engine + hysteresis + plugin
β”‚   β”‚   β”‚   β”œβ”€β”€ anomaly.py          # Z-Score + IQR + Gradient detection
β”‚   β”‚   β”‚   └── prediction.py       # Linear regression + forecasting
β”‚   β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”‚   └── multi_agent.py      # Data β†’ Decision β†’ Action pipeline
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── models.py           # 5 SQLAlchemy models + indexes
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ ingestion.py        # Data validation + storage
β”‚   β”‚   β”‚   └── execution.py        # Commands + alerts + actuator state
β”‚   β”‚   └── main.py                 # FastAPI app + lifespan
β”‚   β”œβ”€β”€ tests/
β”‚   β”‚   β”œβ”€β”€ test_ai.py              # 20+ AI engine tests
β”‚   β”‚   └── test_api.py             # API endpoint tests
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.js                  # Main app + 5-page router
β”‚   β”‚   β”œβ”€β”€ App.css                 # Complete dark theme design system
β”‚   β”‚   └── index.js                # React entry point
β”‚   β”œβ”€β”€ public/index.html
β”‚   β”œβ”€β”€ package.json
β”‚   └── Dockerfile
β”‚
β”œβ”€β”€ device-simulator/
β”‚   └── simulator.py                # 11 devices, 3 rooms, realistic data
β”‚
β”œβ”€β”€ esp32-firmware/
β”‚   β”œβ”€β”€ main/main.ino               # ESP32 Arduino firmware
β”‚   └── README.md                   # Hardware setup guide
β”‚
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ init.sql                    # Database schema + indexes
β”‚   └── mosquitto.conf              # MQTT broker config
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ ARCHITECTURE.md             # Detailed system design
β”‚   β”œβ”€β”€ SETUP.md                    # Setup with/without Docker
β”‚   └── ROADMAP.md                  # Development roadmap
β”‚
β”œβ”€β”€ Makefile                        # Convenience commands
β”œβ”€β”€ docker-compose.yml              # 6-service orchestration
β”œβ”€β”€ LICENSE                         # MIT
β”œβ”€β”€ CODE_OF_CONDUCT.md              # CoC
β”œβ”€β”€ CONTRIBUTING.md                 # Contribution guide
└── README.md                       # This file

πŸ”Œ Custom Strategies

from app.ai.rules import DecisionStrategy, Decision

class MyCustomStrategy(DecisionStrategy):
    """Example: Alert when humidity exceeds threshold."""

    @property
    def name(self) -> str:
        return "humidity_alert"

    def evaluate(self, device_id, device_type, value, history):
        if device_type != "humidity":
            return []

        if value > 80:
            return [Decision(
                action="activate",
                device_id=device_id,
                params={"actuator": "alarm"},
                reason=f"High humidity: {value:.1f}%",
                confidence=0.85,
                severity="warning",
                source=self.name,
            )]
        return []

# Register:
from app.agents.multi_agent import agents
agents.engine.add_strategy(MyCustomStrategy())

πŸ› οΈ Tech Stack

Layer Technology Version Purpose
Backend Python 3.11+ Runtime
Framework FastAPI 0.110 Async REST + WebSocket
Database PostgreSQL 16 Time-series storage
Cache Redis 7.2 Queue, pub/sub, cache
Messaging Mosquitto 2.0 MQTT broker
AI/Math NumPy + SciPy 1.26 / 1.12 Anomaly detection, prediction
Frontend React 18.3 Dashboard UI
Charts Recharts 2.12 Real-time visualizations
Icons Lucide 0.344 Icon library
Infra Docker Compose 2.x Local orchestration
Hardware ESP32 Arduino Optional real sensors

πŸ“– Documentation

Document Description
Architecture System design, data flow, plugin system
Setup Guide Docker + native setup instructions
Roadmap Future plans and milestones
Contributing How to contribute code
API Reference Interactive Swagger (when running)

πŸš€ Release Strategy

Releases are versioned using Semantic Versioning:

  • v1.x.x β€” Current stable. Core features complete.
  • v2.x.x β€” Planned: distributed edge, TimescaleDB, Grafana.
  • v3.x.x β€” Planned: plugin marketplace, multi-tenant.

See Releases for changelog.


🀝 Contributing

We ❀️ contributions! See CONTRIBUTING.md.

# Fork, branch, code, PR
git clone https://github.com/rudra496/EdgeBrain.git
cd EdgeBrain
make dev      # Start development environment
make test     # Run tests
# Make changes, then open PR

Contributors

Thanks to all contributors! Your PRs make EdgeBrain better.

Contributors


πŸ“„ License

MIT β€” free for personal and commercial use.


⭐ Star History

Star History Chart

EdgeBrain β€” Intelligence at the edge, not the cloud.

Built with πŸ”§ by Rudra

About

🧠 AI-Powered Edge Intelligence Platform β€” Autonomous real-world decision systems. 100% local. Zero paid APIs.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors