# krishna99-tech/thingsnxtplatform architecture

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

- Interactive diagram: https://gitdiagram.com/krishna99-tech/thingsnxtplatform
- Repository: https://github.com/krishna99-tech/thingsnxtplatform

## Overview

ThingsNXT is a Python IoT backend for user, device, telemetry, dashboard, and administration workflows. A client reaches the FastAPI application through its gateway, authenticates, and uses device APIs to manage devices and submit telemetry; device routes apply rules, persist updates, and support live delivery. MQTT provides a device-facing bridge, while Kafka provides an authenticated telemetry feed. The source excerpts and index support the main routing and integration structure, but several modules were not sampled; their placement is shown without asserting unverified call paths.

Main entry points: [`device_routes.py`](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/device_routes.py) (Device and telemetry APIs), [`api_gateway.py`](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/api_gateway.py) (API gateway), [`db.py`](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/db.py) (MongoDB), [`websocket_routes.py`](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/websocket_routes.py) (WebSocket API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_app["FastAPI app<br/>[main.py]"]
  node_gateway["API gateway<br/>[api_gateway.py]"]
end

subgraph group_identity["Identity and administration"]
  node_auth["Authentication<br/>[auth_routes.py]"]
  node_admin["Administration<br/>[admin_routes.py]"]
  node_app_config["App configuration"]
end

subgraph group_iot["IoT domain"]
  node_devices["Device and telemetry APIs<br/>[device_routes.py]"]
  node_rules["Access rules<br/>[rules_engine.py]"]
  node_algorithms["IoT algorithms<br/>[iot_algorithms.py]"]
  node_domain_models["Domain models<br/>[models.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_realtime["Live integrations"]
  node_mqtt["MQTT bridge<br/>[mqtt_service.py]"]
  node_kafka_routes["Kafka API"]
  node_kafka["Kafka service<br/>[kafka_service.py]"]
  node_kafka_feed["Kafka live feed"]
  node_websocket_routes["WebSocket API"]
  node_websocket_manager["WebSocket manager"]
  node_events["Event routes<br/>[events.py]"]
  node_event_manager["SSE event manager<br/>[event_manager.py]"]
end

subgraph group_storage["Persistence"]
  node_database[("MongoDB<br/>[db.py]")]
end

node_client(("API clients"))
node_external_mqtt(("MQTT broker"))
node_external_kafka(("Kafka broker"))

node_client -.->|"sends requests"| node_app
node_app -->|"mounts routes"| node_gateway
node_app -->|"mounts routes"| node_admin
node_gateway -->|"registers routes"| node_auth
node_gateway -->|"registers routes"| node_devices
node_gateway -->|"registers routes"| node_websocket_routes
node_gateway -->|"registers routes"| node_events
node_gateway -->|"registers routes"| node_kafka_routes
node_auth -->|"reads and writes"| node_database
node_admin -->|"reads and writes"| node_database
node_app_config -.->|"uses database"| node_database
node_devices -->|"reads and writes"| node_database
node_devices -->|"checks access"| node_rules
node_devices -->|"broadcasts updates"| node_websocket_manager
node_devices -.->|"uses bridge"| node_mqtt
node_devices -.->|"publishes telemetry"| node_kafka
node_devices -.->|"uses algorithms"| node_algorithms
node_devices -.->|"uses models"| node_domain_models
node_devices -.->|"uses schemas"| node_schemas
node_mqtt -->|"publishes and subscribes"| node_external_mqtt
node_mqtt -->|"forwards telemetry"| node_devices
node_kafka_routes -->|"requires authentication"| node_auth
node_kafka_routes -->|"requests feed and stats"| node_kafka
node_kafka -->|"produces and consumes"| node_external_kafka
node_kafka -->|"broadcasts records"| node_kafka_feed
node_websocket_routes -.->|"validates tokens"| node_auth
node_websocket_routes -->|"checks users"| node_database
node_websocket_routes -->|"registers connections"| node_websocket_manager
node_events -.->|"uses event stream"| node_event_manager

click node_app "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/main.py"
click node_gateway "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/api_gateway.py"
click node_auth "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/auth_routes.py"
click node_admin "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/admin_routes.py"
click node_app_config "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/app_config_routes.py"
click node_devices "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/device_routes.py"
click node_rules "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/rules_engine.py"
click node_algorithms "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/iot_algorithms.py"
click node_domain_models "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/models.py"
click node_schemas "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/schemas.py"
click node_mqtt "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/mqtt_service.py"
click node_kafka_routes "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/integrations_kafka_routes.py"
click node_kafka "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/kafka_service.py"
click node_kafka_feed "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/kafka_feed_manager.py"
click node_websocket_routes "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/websocket_routes.py"
click node_websocket_manager "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/websocket_manager.py"
click node_events "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/events.py"
click node_event_manager "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/event_manager.py"
click node_database "https://github.com/krishna99-tech/thingsnxtplatform/blob/main/db.py"

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_gateway,node_client toneBlue
class node_auth,node_admin,node_app_config toneAmber
class node_devices,node_rules,node_algorithms,node_domain_models,node_schemas toneMint
class node_mqtt,node_kafka_routes,node_kafka,node_kafka_feed,node_websocket_routes,node_websocket_manager,node_events,node_event_manager toneRose
class node_database,node_external_mqtt,node_external_kafka toneIndigo
```

## Components

### API entry

- [FastAPI app](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/main.py): `main.py`
- [API gateway](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/api_gateway.py): `api_gateway.py`

### Identity and administration

- [Authentication](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/auth_routes.py): `auth_routes.py`
- [Administration](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/admin_routes.py): `admin_routes.py`
- [App configuration](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/app_config_routes.py): `app_config_routes.py`

### IoT domain

- [Device and telemetry APIs](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/device_routes.py): `device_routes.py`
- [Access rules](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/rules_engine.py): `rules_engine.py`
- [IoT algorithms](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/iot_algorithms.py): `iot_algorithms.py`
- [Domain models](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/models.py): `models.py`
- [Request schemas](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/schemas.py): `schemas.py`

### Live integrations

- [MQTT bridge](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/mqtt_service.py): `mqtt_service.py`
- [Kafka API](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/integrations_kafka_routes.py): `integrations_kafka_routes.py`
- [Kafka service](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/kafka_service.py): `kafka_service.py`
- [Kafka live feed](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/kafka_feed_manager.py): `kafka_feed_manager.py`
- [WebSocket API](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/websocket_routes.py): `websocket_routes.py`
- [WebSocket manager](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/websocket_manager.py): `websocket_manager.py`
- [Event routes](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/events.py): `events.py`
- [SSE event manager](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/event_manager.py): `event_manager.py`

### Persistence

- [MongoDB](https://github.com/krishna99-tech/thingsnxtplatform/blob/main/db.py): `db.py`

### Other components

- **API clients**
- **MQTT broker**
- **Kafka broker**

## Connections

- API clients → FastAPI app: sends requests
- FastAPI app → API gateway: mounts routes (evidence: `main.py`)
- FastAPI app → Administration: mounts routes (evidence: `main.py`)
- API gateway → Authentication: registers routes (evidence: `api_gateway.py`)
- API gateway → Device and telemetry APIs: registers routes (evidence: `api_gateway.py`)
- API gateway → WebSocket API: registers routes (evidence: `api_gateway.py`)
- API gateway → Event routes: registers routes (evidence: `api_gateway.py`)
- API gateway → Kafka API: registers routes (evidence: `api_gateway.py`)
- Authentication → MongoDB: reads and writes (evidence: `auth_routes.py`)
- Administration → MongoDB: reads and writes (evidence: `admin_routes.py`)
- App configuration → MongoDB: uses database (evidence: `app_config_routes.py`)
- Device and telemetry APIs → MongoDB: reads and writes (evidence: `device_routes.py`)
- Device and telemetry APIs → Access rules: checks access (evidence: `device_routes.py`)
- Device and telemetry APIs → WebSocket manager: broadcasts updates (evidence: `device_routes.py`)
- Device and telemetry APIs → MQTT bridge: uses bridge (evidence: `device_routes.py`)
- Device and telemetry APIs → Kafka service: publishes telemetry (evidence: `device_routes.py`)
- Device and telemetry APIs → IoT algorithms: uses algorithms (evidence: `device_routes.py`)
- Device and telemetry APIs → Domain models: uses models (evidence: `device_routes.py`)
- Device and telemetry APIs → Request schemas: uses schemas
- MQTT bridge → MQTT broker: publishes and subscribes (evidence: `mqtt_service.py`)
- MQTT bridge → Device and telemetry APIs: forwards telemetry (evidence: `mqtt_service.py`)
- Kafka API → Authentication: requires authentication (evidence: `integrations_kafka_routes.py`)
- Kafka API → Kafka service: requests feed and stats (evidence: `integrations_kafka_routes.py`)
- Kafka service → Kafka broker: produces and consumes (evidence: `kafka_service.py`)
- Kafka service → Kafka live feed: broadcasts records (evidence: `kafka_service.py`)
- WebSocket API → Authentication: validates tokens
- WebSocket API → MongoDB: checks users (evidence: `websocket_routes.py`)
- WebSocket API → WebSocket manager: registers connections (evidence: `websocket_routes.py`)
- Event routes → SSE event manager: uses event stream
