# gopesh-1157/motor-guard architecture

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

- Interactive diagram: https://gitdiagram.com/gopesh-1157/motor-guard
- Repository: https://github.com/gopesh-1157/motor-guard

## Overview

MotorGuard is a local-first industrial motor monitoring and predictive-maintenance platform. Sensor-equipped motors and simulated motors publish telemetry through MQTT; the gateway ingests readings, persists them, evaluates alert rules, and serves API and live-update capabilities to dashboard users. The dashboard supports fleet and device views, live monitoring, analytics, alerts, maintenance workflows, reporting, settings, and role-based access. Source evidence is partial: the README documents the overall topology and capabilities, while sampled backend and frontend files establish only some internal calls and rendering relationships.

Main entry points: [`frontend/src/App.tsx`](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/App.tsx) (Dashboard App), [`backend/app/main.py`](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/main.py) (Gateway Runtime), [`backend/app/api/v1/endpoints/auth.py`](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/endpoints/auth.py) (Auth Routes), [`backend/app/core/auth.py`](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/core/auth.py) (Authentication and RBAC)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Edge and Messaging"]
  node_fleet(("Motor Fleet"))
  node_simulator["Motor Simulator<br/>[simulator.py]"]
  node_broker["MQTT Broker"]
  node_mqtt_sub["MQTT Subscriber<br/>[subscriber.py]"]
end

subgraph group_backend["Gateway Services"]
  node_gateway["Gateway Runtime<br/>[main.py]"]
  node_api["REST API Routes<br/>[api.py]"]
  node_telemetry["Telemetry Ingestion"]
  node_alerts["Alert Rules<br/>[alert_service.py]"]
  node_motors["Motor Registry<br/>[motor_service.py]"]
  node_devices["Device Registry<br/>[device_service.py]"]
  node_maintenance["Maintenance Records"]
  node_mongo[("MongoDB")]
  node_websocket["Live WebSocket<br/>[websocket.py]"]
end

subgraph group_identity["Identity and Access"]
  node_auth_routes["Auth Routes<br/>[auth.py]"]
  node_auth["Authentication and RBAC<br/>[auth.py]"]
  node_security["Token Security<br/>[security.py]"]
  node_users["User Service<br/>[user_service.py]"]
end

subgraph group_dashboard["Monitoring Dashboard"]
  node_app["Dashboard App<br/>[App.tsx]"]
  node_overview["Fleet Overview<br/>[OverviewView.tsx]"]
  node_live["Live Monitoring"]
  node_device_view["Device Nodes"]
  node_alerts_view["Alerts and Dispatch<br/>[AlertsView.tsx]"]
  node_management["Motor Management"]
  node_analytics["Analytics<br/>[AnalyticsView.tsx]"]
  node_reports["Reports<br/>[ReportsView.tsx]"]
  node_settings["Settings<br/>[SettingsView.tsx]"]
  node_digital_twin["Digital Twin"]
  node_detail["Motor Detail"]
  node_telemetry_hook["Telemetry Hook<br/>[useTelemetry.ts]"]
end

node_browser(("Dashboard User"))

node_fleet -->|"publishes telemetry"| node_broker
node_simulator -->|"publishes telemetry"| node_broker
node_broker -->|"delivers messages"| node_mqtt_sub
node_mqtt_sub -.->|"forwards telemetry"| node_gateway
node_gateway -->|"ingests readings"| node_telemetry
node_gateway -->|"evaluates readings"| node_alerts
node_gateway -->|"broadcasts updates"| node_websocket
node_gateway -->|"persists data"| node_mongo
node_telemetry -.->|"stores telemetry"| node_mongo
node_alerts -.->|"stores alerts"| node_mongo
node_motors -->|"reads and updates"| node_mongo
node_devices -->|"reads and updates"| node_mongo
node_maintenance -.->|"stores records"| node_mongo
node_api -->|"registers routes"| node_auth_routes
node_auth_routes -->|"authenticates users"| node_users
node_auth_routes -->|"checks access"| node_auth
node_auth_routes -->|"creates tokens"| node_security
node_auth -->|"validates tokens"| node_security
node_auth -->|"loads users"| node_users
node_browser -->|"uses dashboard"| node_app
node_app -->|"renders view"| node_overview
node_app -->|"renders view"| node_live
node_app -->|"renders view"| node_device_view
node_app -->|"renders view"| node_alerts_view
node_app -->|"renders view"| node_management
node_app -->|"renders view"| node_analytics
node_app -->|"renders view"| node_reports
node_app -->|"renders view"| node_settings
node_app -->|"renders view"| node_digital_twin
node_app -->|"renders modal"| node_detail
node_live -.->|"uses telemetry"| node_telemetry_hook
node_telemetry_hook -.->|"receives updates"| node_websocket

click node_simulator "https://github.com/gopesh-1157/motor-guard/blob/main/simulator/simulator.py"
click node_gateway "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/main.py"
click node_mqtt_sub "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/mqtt/subscriber.py"
click node_api "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/api.py"
click node_telemetry "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/telemetry_ingestion.py"
click node_alerts "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/alert_service.py"
click node_motors "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/motor_service.py"
click node_devices "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/device_service.py"
click node_maintenance "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/maintenance_service.py"
click node_websocket "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/endpoints/websocket.py"
click node_auth_routes "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/endpoints/auth.py"
click node_auth "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/core/auth.py"
click node_security "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/core/security.py"
click node_users "https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/user_service.py"
click node_app "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/App.tsx"
click node_overview "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/OverviewView.tsx"
click node_live "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/LiveMonitoringView.tsx"
click node_device_view "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/DeviceNodesView.tsx"
click node_alerts_view "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/AlertsView.tsx"
click node_management "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/MotorManagementView.tsx"
click node_analytics "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/AnalyticsView.tsx"
click node_reports "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/ReportsView.tsx"
click node_settings "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/SettingsView.tsx"
click node_digital_twin "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/MotorDigitalTwin3D.tsx"
click node_detail "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/MotorDetailModal.tsx"
click node_telemetry_hook "https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/hooks/useTelemetry.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_fleet,node_simulator,node_broker,node_mqtt_sub,node_browser toneBlue
class node_gateway,node_api,node_telemetry,node_alerts,node_motors,node_devices,node_maintenance,node_mongo,node_websocket toneAmber
class node_auth_routes,node_auth,node_security,node_users toneMint
class node_app,node_overview,node_live,node_device_view,node_alerts_view,node_management,node_analytics,node_reports,node_settings,node_digital_twin,node_detail,node_telemetry_hook toneRose
```

## Components

### Edge and Messaging

- **Motor Fleet**
- [Motor Simulator](https://github.com/gopesh-1157/motor-guard/blob/main/simulator/simulator.py): `simulator/simulator.py`
- **MQTT Broker**
- [MQTT Subscriber](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/mqtt/subscriber.py): `backend/app/mqtt/subscriber.py`

### Gateway Services

- [Gateway Runtime](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/main.py): `backend/app/main.py`
- [REST API Routes](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/api.py): `backend/app/api/v1/api.py`
- [Telemetry Ingestion](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/telemetry_ingestion.py): `backend/app/services/telemetry_ingestion.py`
- [Alert Rules](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/alert_service.py): `backend/app/services/alert_service.py`
- [Motor Registry](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/motor_service.py): `backend/app/services/motor_service.py`
- [Device Registry](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/device_service.py): `backend/app/services/device_service.py`
- [Maintenance Records](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/maintenance_service.py): `backend/app/services/maintenance_service.py`
- **MongoDB**
- [Live WebSocket](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/endpoints/websocket.py): `backend/app/api/v1/endpoints/websocket.py`

### Identity and Access

- [Auth Routes](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/api/v1/endpoints/auth.py): `backend/app/api/v1/endpoints/auth.py`
- [Authentication and RBAC](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/core/auth.py): `backend/app/core/auth.py`
- [Token Security](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [User Service](https://github.com/gopesh-1157/motor-guard/blob/main/backend/app/services/user_service.py): `backend/app/services/user_service.py`

### Monitoring Dashboard

- [Dashboard App](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Fleet Overview](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/OverviewView.tsx): `frontend/src/components/OverviewView.tsx`
- [Live Monitoring](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/LiveMonitoringView.tsx): `frontend/src/components/LiveMonitoringView.tsx`
- [Device Nodes](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/DeviceNodesView.tsx): `frontend/src/components/DeviceNodesView.tsx`
- [Alerts and Dispatch](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/AlertsView.tsx): `frontend/src/components/AlertsView.tsx`
- [Motor Management](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/MotorManagementView.tsx): `frontend/src/components/MotorManagementView.tsx`
- [Analytics](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/AnalyticsView.tsx): `frontend/src/components/AnalyticsView.tsx`
- [Reports](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/ReportsView.tsx): `frontend/src/components/ReportsView.tsx`
- [Settings](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/SettingsView.tsx): `frontend/src/components/SettingsView.tsx`
- [Digital Twin](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/MotorDigitalTwin3D.tsx): `frontend/src/components/MotorDigitalTwin3D.tsx`
- [Motor Detail](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/components/MotorDetailModal.tsx): `frontend/src/components/MotorDetailModal.tsx`
- [Telemetry Hook](https://github.com/gopesh-1157/motor-guard/blob/main/frontend/src/hooks/useTelemetry.ts): `frontend/src/hooks/useTelemetry.ts`

### Other components

- **Dashboard User**

## Connections

- Motor Fleet → MQTT Broker: publishes telemetry (evidence: `README.md`)
- Motor Simulator → MQTT Broker: publishes telemetry (evidence: `README.md`)
- MQTT Broker → MQTT Subscriber: delivers messages (evidence: `README.md`)
- MQTT Subscriber → Gateway Runtime: forwards telemetry (evidence: `backend/app/main.py`)
- Gateway Runtime → Telemetry Ingestion: ingests readings (evidence: `backend/app/main.py`)
- Gateway Runtime → Alert Rules: evaluates readings (evidence: `backend/app/main.py`)
- Gateway Runtime → Live WebSocket: broadcasts updates (evidence: `backend/app/main.py`)
- Gateway Runtime → MongoDB: persists data (evidence: `README.md`)
- Telemetry Ingestion → MongoDB: stores telemetry
- Alert Rules → MongoDB: stores alerts
- Motor Registry → MongoDB: reads and updates (evidence: `backend/app/services/motor_service.py`)
- Device Registry → MongoDB: reads and updates (evidence: `backend/app/services/device_service.py`)
- Maintenance Records → MongoDB: stores records
- REST API Routes → Auth Routes: registers routes (evidence: `backend/app/api/v1/api.py`)
- Auth Routes → User Service: authenticates users (evidence: `backend/app/api/v1/endpoints/auth.py`)
- Auth Routes → Authentication and RBAC: checks access (evidence: `backend/app/api/v1/endpoints/auth.py`)
- Auth Routes → Token Security: creates tokens (evidence: `backend/app/api/v1/endpoints/auth.py`)
- Authentication and RBAC → Token Security: validates tokens (evidence: `backend/app/core/auth.py`)
- Authentication and RBAC → User Service: loads users (evidence: `backend/app/core/auth.py`)
- Dashboard User → Dashboard App: uses dashboard (evidence: `README.md`)
- Dashboard App → Fleet Overview: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Live Monitoring: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Device Nodes: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Alerts and Dispatch: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Motor Management: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Analytics: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Reports: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Settings: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Digital Twin: renders view (evidence: `frontend/src/App.tsx`)
- Dashboard App → Motor Detail: renders modal (evidence: `frontend/src/App.tsx`)
- Live Monitoring → Telemetry Hook: uses telemetry
- Telemetry Hook → Live WebSocket: receives updates
