# ana52070/web_onvif_modbus architecture

> Architecture diagram of the GitHub repository ana52070/web_onvif_modbus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ana52070/web_onvif_modbus
- Repository: https://github.com/ana52070/web_onvif_modbus

## Overview

##### Project type and purpose
- From the file tree and README (“# 测试”), this appears to be an embedded/networked device application written in C.
- It bundles four main functional modules—Command, ModbusTCP, Onvif and Webserver—plus a central `main.c` that ties them together.
- Purpose: expose and manage hardware/devices (IP camera via ONVIF, industrial I/O via ModbusTCP, local OS commands) through a built-in HTTP server and CLI scripts.

##### File structure
- Top-level modules:
- Command/Code: low-level OS command wrapper (`Command.c/.h`)
- ModbusTCP/Code: ModbusTCP master stack (`modbusTcp_master.c/.h`)
- Onvif/Code: ONVIF/PTZ camera control (`camera_manager.c`, `myptz.c`)
- Webserver/Code & Webserver/HTML & Webserver/Config: embedded HTTP server, JSON configs, HTML UI
- Build system: Makefile + Makefile.inc compile each module into `.o` files, link with `main.c`.
- Shell scripts (under Command/Sh) for device reboot or test.
- Config files in JSON for IP sets (ipset.json) and tracking settings (track.json).

- Web UI (Browser)
- Embedded HTTP Server
- Application Core (`main.c`)
- Command Module
- ModbusTCP Module
- Onvif/PTZ Module
- Shell‐script Layer
- Configuration Store (JSON files)
- External Devices: IP Camera, Modbus Devices, OS

- Browser → HTTP Server: HTTP requests (login, reboot, track, ipset)
- HTTP Server → Application Core: API calls or HTML template rendering
- Application Core ↔ Modules:
– ↔ Onvif Module: PTZ commands, status polling
– ↔ ModbusTCP Module: read/write registers
– ↔ Command Module → Shell scripts → OS commands
- Modules → External Devices:
– Onvif → IP Camera via ONVIF protocol
– ModbusTCP → PLCs/sensors via Modbus/TCP
– Shell scripts → Linux `reboot`, diagnostics

c. Architectural patterns & principles:
- Layered architecture: Presentation (Web UI), Application Core, Module abstractions, External layer
- Modular separation: each protocol/feature in its own codebase for testability
- Config-driven behavior: JSON files decouple runtime settings
- Build pipeline: flat Makefile with per-module compilation

d. Key technologies/frameworks:
- C language modules, Makefile build
- ONVIF open standard (SOAP/HTTP)
- Modbus/TCP (industrial protocol)
- Embedded HTTP (custom HTML templates + JSON config)
- Shell scripting for system commands

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Web UI<br/>(Browser)"]:::frontend
        HTTP["Embedded HTTP Server"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        Core["Application Core<br/>(main.c)"]:::logic
        Build["Build System<br/>(Makefile, Makefile.inc)"]:::build
    end

    %% Module Layer
    subgraph "Module Layer"
        Cmd["Command Module"]:::logic
        Shell["Shell-script Layer"]:::logic
        Modbus["ModbusTCP Module"]:::logic
        Onvif["Onvif/PTZ Module"]:::logic
        Websrv["Webserver Module"]:::logic
    end

    %% Configuration Store
    subgraph "Configuration Store"
        JSON1["ipset.json"]:::config
        JSON2["track.json"]:::config
    end

    %% External Devices
    subgraph "External Devices"
        Cam["IP Camera"]:::external
        PLC["Modbus Devices"]:::external
        OS["Linux OS"]:::external
    end

    %% Documentation
    subgraph "Documentation"
        Doc["README.md"]:::build
    end

    %% Connections
    Browser -->|"HTTP GET/POST"| HTTP
    HTTP -->|"API Calls"| Core
    HTTP -->|"Serves HTML"| Websrv
    Websrv -->|"Renders Templates"| HTTP
    Core -->|"Invokes"| Cmd
    Core -->|"Invokes"| Modbus
    Core -->|"Invokes"| Onvif
    Core -->|"Invokes"| Shell
    Cmd -->|"Spawns"| Shell
    Shell -->|"Executes Scripts"| OS
    Modbus -->|"Modbus/TCP"| PLC
    Onvif -->|"ONVIF Protocol"| Cam
    JSON1 -->|"Config Read"| Websrv
    JSON2 -->|"Config Read"| Websrv
    JSON1 -->|"Config Read"| Core
    JSON2 -->|"Config Read"| Core
    Build --> Core
    Build --> Cmd
    Build --> Modbus
    Build --> Onvif
    Build --> Websrv
    Doc --> Build

    %% Click Events
    click Core "https://github.com/ana52070/web_onvif_modbus/blob/main/main.c"
    click Build "https://github.com/ana52070/web_onvif_modbus/tree/main/Makefile"
    click Build "https://github.com/ana52070/web_onvif_modbus/blob/main/Makefile.inc"
    click Cmd "https://github.com/ana52070/web_onvif_modbus/blob/main/Command/Code/Command.c"
    click Cmd "https://github.com/ana52070/web_onvif_modbus/blob/main/Command/Code/Command.h"
    click Shell "https://github.com/ana52070/web_onvif_modbus/blob/main/Command/Sh/reboot.sh"
    click Shell "https://github.com/ana52070/web_onvif_modbus/blob/main/Command/Sh/test_helloworld.sh"
    click Modbus "https://github.com/ana52070/web_onvif_modbus/blob/main/ModbusTCP/Code/modbusTcp_master.c"
    click Modbus "https://github.com/ana52070/web_onvif_modbus/blob/main/ModbusTCP/Code/modbusTcp_master.h"
    click Onvif "https://github.com/ana52070/web_onvif_modbus/blob/main/Onvif/Code/camera_manager.c"
    click Onvif "https://github.com/ana52070/web_onvif_modbus/blob/main/Onvif/Code/camera_manager.h"
    click Onvif "https://github.com/ana52070/web_onvif_modbus/blob/main/Onvif/Code/myptz.c"
    click Onvif "https://github.com/ana52070/web_onvif_modbus/blob/main/Onvif/Code/myptz.h"
    click Onvif "https://github.com/ana52070/web_onvif_modbus/blob/main/Onvif/Code/camera_config.h"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Code/html_base.c"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Code/html_base.h"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Code/html_main.c"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Code/html_main.h"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Code/html_tool.c"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Code/html_tool.h"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/HTML/login.html"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/HTML/reboot.html"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/HTML/ipset.html"
    click Websrv "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/HTML/track.html"
    click JSON1 "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Config/ipset.json"
    click JSON2 "https://github.com/ana52070/web_onvif_modbus/blob/main/Webserver/Config/track.json"
    click Doc "https://github.com/ana52070/web_onvif_modbus/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef build fill:#D3D3D3,stroke:#333,stroke-width:1px
```
