# cmhehe176/aiot-platform-server architecture

> Architecture diagram of the GitHub repository cmhehe176/aiot-platform-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cmhehe176/aiot-platform-server
- Repository: https://github.com/cmhehe176/aiot-platform-server

## Overview

##### Project type and purpose
- This is a monolithic backend server built with NestJS (“AIot Platform Server”) that exposes REST and WebSocket APIs, integrates with a PostgreSQL database, RabbitMQ for asynchronous messaging, Zabbix for device polling/monitoring, handles email/storage, and runs in Docker Compose.

##### File structure
- Top level: Docker configs (`Dockerfile`, `compose.yml`), CI workflows, env examples.
- `src/` splits into:
- `common/`: shared decorators, constants, utils
- `database/`: TypeORM data source, entities, migrations, seeders
- `feature/`: one module per domain concept (auth, device, sensor, message, notification, email, socket, storage, rabbit-mq, etc.)
- `app.*`: NestJS root module, controller, service
- `main.ts`: bootstrap
- Config files for Nest CLI, TypeScript, ESLint, Prettier.

##### Insights from the README
- Requires Docker Compose to stand up: server, PostgreSQL, Zabbix, Adminer.
- Scripts to sync DB (`yarn migration`), seed, and run in dev/prod.
- Exposes HTTP on port 3000, Zabbix UI on 8081, Adminer on 8080.

##### Detail level
- Migrations/seeders as part of build/deploy workflow.
- CI pipelines (build.yml, deploy.yml) at the edge to illustrate automation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Clients["Clients (Web/Mobile IoT apps)"]:::ext

    %% Docker Compose Network
    subgraph "Docker Compose Network"
        direction TB
        API["NestJS API Server"]:::api
        Postgres[(PostgreSQL\n5432)]:::db
        RabbitMQ[(RabbitMQ\n5672)]:::mq
        Zabbix["Zabbix Server & UI\n8081"]:::ext
        Adminer["Adminer\n8080"]:::ext
    end

    %% NestJS API internals
    subgraph "NestJS API Server"
        direction TB
        subgraph "Bootstrap & Root"
            direction TB
            Main["main.ts"]:::api
            AppModule["app.module.ts"]:::api
            AppController["app.controller.ts"]:::api
            AppService["app.service.ts"]:::api
        end
        subgraph "Common Utilities"
            direction TB
            Roles["roles.constant.ts"]:::api
            Decorators["decorators/*"]:::api
            Util["util.ts"]:::api
            Types["type.ts"]:::api
        end
        subgraph "Database Layer"
            direction TB
            DBModule["database.module.ts"]:::api
            DataSource["data-source.ts"]:::api
            Entities["entities/*"]:::api
            Migrations["migrations/*"]:::api
            SeederConfig["seeder-config.ts"]:::api
            Seeds["seeds/*"]:::api
        end
        subgraph "Feature Modules"
            direction TB
            AuthModule["auth.module.ts"]:::api
            DashboardModule["dashboard.module.ts"]:::api
            DeviceModule["device.module.ts"]:::api
            SensorModule["sensor.module.ts"]:::api
            ProjectModule["project.module.ts"]:::api
            ObjectModule["object.module.ts"]:::api
            MessageModule["message.module.ts"]:::api
            NotificationModule["notification.module.ts"]:::api
            EmailModule["email.module.ts"]:::api
            StorageModule["storage.module.ts"]:::api
            SupportModule["support.module.ts"]:::api
            RabbitModule["rabbit-mq.module.ts"]:::api
            SocketModule["socket.module.ts"]:::api
            UserModule["user.module.ts"]:::api
        end
    end

    %% External flows
    Clients -->|"HTTP/REST\nport 3000"| API
    Clients -->|"WebSocket\nport 3000"| API
    API -->|"TypeORM"| Postgres
    API -->|"publish/consume"| RabbitMQ
    API -->|"SMTP/Third-party"| EmailService["Email Service"]:::ext
    Zabbix ---|polls devices| API
    Zabbix -->|writes metrics| Postgres
    Adminer -->|DB GUI| Postgres

    %% Click Events
    click Main "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/main.ts"
    click AppModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/app.module.ts"
    click AppController "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/app.controller.ts"
    click AppService "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/app.service.ts"
    click Roles "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/common/constants/roles.constant.ts"
    click Decorators "https://github.com/cmhehe176/aiot-platform-server/tree/main/src/common/decorators"
    click Util "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/common/util.ts"
    click Types "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/common/type.ts"
    click DBModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/database/database.module.ts"
    click DataSource "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/database/data-source.ts"
    click Entities "https://github.com/cmhehe176/aiot-platform-server/tree/main/src/database/entities"
    click Migrations "https://github.com/cmhehe176/aiot-platform-server/tree/main/src/database/migrations"
    click SeederConfig "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/database/seeder-config.ts"
    click Seeds "https://github.com/cmhehe176/aiot-platform-server/tree/main/src/database/seeds"
    click AuthModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/auth/auth.module.ts"
    click DashboardModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/dashboard/dashboard.module.ts"
    click DeviceModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/device/device.module.ts"
    click SensorModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/sensor/sensor.module.ts"
    click ProjectModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/project/project.module.ts"
    click ObjectModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/object/object.module.ts"
    click MessageModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/message/message.module.ts"
    click NotificationModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/notification/notification.module.ts"
    click EmailModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/email/email.module.ts"
    click StorageModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/storage/storage.module.ts"
    click SupportModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/support/support.module.ts"
    click RabbitModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/rabbit-mq/rabbit-mq.module.ts"
    click SocketModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/socket/socket.module.ts"
    click UserModule "https://github.com/cmhehe176/aiot-platform-server/blob/main/src/feature/user/user.module.ts"

    %% Styles
    classDef api fill:#D0E6A5,stroke:#333,stroke-width:1px
    classDef db fill:#FCF4A3,stroke:#333,stroke-width:1px
    classDef mq fill:#FF8C94,stroke:#333,stroke-width:1px
    classDef ext fill:#A0CED9,stroke:#333,stroke-width:1px
```
