How busy-cloud/iot works
Main Components
• Entry Point/Application Bootstrap: The cmd directory (cmd/main.go) serves as the launching point of the application. Additionally, files like app/boot.go and internal/boot.go indicate the initialization routines.
• Business Modules / Domain Logic:
– Product Module: Contains the product model logic (files like product/config.go, product/model.go, product/product.go, and product_api.go). This module handles the "thing model" as specified in the README.
– Device Module: Found in the device directory and further supported by internal/device.go and device_api.go. It likely concerns interfacing with and managing IoT devices.
– Project Module: Manages projects using files such as project/project.go and project-related API files.
– Space Module: Handles grouping or configuration of “spaces” with files like space/space.go and space-api.go.
– Alarm Module: Located in the alarm directory, handling alarms via alarm.go and alarm_api.go.
– Protocol Module and Protocols: The protocol directory (protocol.go, store.go) and the protocols directory (modbus.json, etc.) deal with protocol definitions and implementations. This might include communication standards like Modbus.
• Utility and Calculation Modules:
– Bin and Calc: The bin and calc directories hold utility functions (e.g., checksum, hex conversion, a language processor in calc/lang.go) that support other modules.
• Internal Services:
– The internal directory contains shared services such as MQTT handling (internal/mqtt.go) and validation logic (internal/validator.go), providing infrastructural support.
• UI/Templates:
– Menus and Pages: The menus (with JSON files) and pages directories (pages/iot with numerous JSON configuration files) represent UI configuration, likely used by a frontend or a web manager for the IoT system.
Relationships and Interactions
• The Entry Point (cmd/main.go) initializes the application, then routes requests/commands to various business modules.
• API Layers: Many modules have corresponding API implementations (e.g., alarm_api.go, device_api.go, project-api.go, product_api.go) that expose functionality to clients or other services.
• Communication: Modules like internal/mqtt.go suggest asynchronous or message-based communication, especially for device telemetry or control.
• Dependency and Utility Layers: The utility functions in bin/ and calc/ serve supporting roles for various components. Likewise, boot routines (both in app and internal) indicate setup dependencies.
• Configurations for UI: The JSON files in pages/iot/ and menus provide configurations for the user interfaces, linking the backend logic with the frontend presentation.
Architectural Patterns and Principles
• Modular Design: Each domain (product, device, project, space, alarm, protocol) is encapsulated into its own directory with both core logic and API endpoints.
• Separation of Concerns: API files are distinct from core business logic, and there is a clear division between frontend-related configuration (menus/pages) and backend services.
• Reusable Internal Services: The internal folder provides foundational support (bootstrapping, MQTT, validation) that underpins multiple components.
• Integrated Utility Components: The bin and calc modules are dedicated to common operations like data conversion or language processing.
• Monolithic Architecture: Although the project is broken down into subcomponents, it is all bundled together rather than split into independent microservices.
Final Summary
– Entry Point: cmd/main.go, boot routines (app/boot.go, internal/boot.go)
– Business Modules: Product, Device, Project, Space, Alarm, Protocol(s)
– Internal/Infrastructural Services: MQTT, Validator, Utility Modules (bin, calc)
– Presentation/UI: JSON configuration in menus and pages
– Integration: Interactions among modules via APIs and internal calls