# busy-cloud/boat architecture

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

- Interactive diagram: https://gitdiagram.com/busy-cloud/boat
- Repository: https://github.com/busy-cloud/boat

## Overview

##### Project Type and Purpose
- This is a Go-based backend application with a modular architecture that acts as a launcher (or orchestrator) for various services/features.
- There is also a separate “webui” directory containing Angular code, indicating that this is a full-stack solution with a clear separation between the backend (written in Go) and the frontend user interface (built with Angular).

##### File Structure
- The project is divided into several top-level directories that suggest different functional areas:
- api & apis: These likely hold the HTTP API endpoints (perhaps with some redundancy for versioning or segregation of API logic).
- app, boot, broker, cron, curd, db, log, menu, mqtt, page, plugin, pool, service, smart, store, and time: Each of these directories has files with “boot.go”, “config.go”, “setting.go” etc. This indicates that each component is self-contained with its own initialization routines and configurations.
- internal: Contains internal integration components (e.g., integrating broker or MQTT messaging).
- lib: Contains various utility libraries used across the project.
- web: Contains the backend web engine configuration and middleware (like HTTPS, JWT, etc.).
- webui: Contains all the Angular project files, representing the frontend client.
- The presence of a “cmd/main.go” file indicates the project’s entry point.
- There is a “go.mod” file confirming Go modules usage and a “build.sh” indicating scripted build processes.

##### Key Components and Architectural Patterns
- API Layer: The “api” and “apis” directories host various endpoint handlers for functionalities such as login, logout, system info, password, settings, etc.
- Application Bootstrapping: The “app” and “boot” modules, along with numerous “boot.go” files scattered across directories, suggest that each component is initialized as part of the startup process.
- Message/Communication Mechanism: The “broker”, “mqtt”, and “internal” directories point toward asynchronous communication or messaging capabilities.
- Database Access: The “db” directory, with configuration and models, indicates ORM and data management components.
- CRUD Operations: The “curd” directory (possibly a slight misspelling of CRUD) abstracts common operations such as create, update, list, delete.
- Web Handling: The “web” directory clearly manages HTTP server settings, JWT authentication, MIME types, etc.
- Utility Libraries: The “lib” directory supports shared functions such as caching, file operations, and data structure handling.
- Additional Features: Components such as “cron” (scheduled tasks), “plugin” (extensibility through plugins), “menu”, and “smart” indicate customizable or dynamic behavior.

a. Main Components to Include:
- Frontend (webui): Represent the Angular-based user interface.
- Backend API Layer:
– HTTP API endpoints (from directories “api” and “apis”).
– Web server component (from “web”).
- Service/Business Logic Layer:
– Application modules (from “app”, “broker”, “cron”, “plugin”, etc.).
– Messaging components (from “mqtt”, “broker”, and “internal”).
- Database Layer: Show the “db” component which manages data interactions.
- Utility Layer: Group the “lib”, “log”, and “exception” handling modules.

b. Relationships and Interactions:
- How the API layer routes requests to the relevant business logic handlers in modules like “apis”, “menu”, or “smart”.
- Data flows between the business logic components and the Database (“db”).
- Interactions between the backend components – for example, the broker component communicating with the MQTT system for asynchronous messaging.
- “cron” tasks component as either scheduled workers or background processes that interact with parts of the system.

c. Highlighting Architectural Patterns:
- Modularity: Each major feature (e.g., authentication, settings, messaging) is encapsulated in its own directory with boot and config files.
- Separation of Concerns: Distinct separation between API, application services, and infrastructure (e.g., DB, logging, lib utilities).
- Extensibility: The existence of “plugin” and “plugins” directories suggests a design that supports modular extensions.
- Clear Frontend/Backend Separation: With Angular in “webui” and Go backends managing the server-side logic.

d. Relevant Technologies and Frameworks:
- Go Language: Underpins most of the backend services.
- Angular: Powers the frontend user interface.
- Web Engine: Likely using a framework like Gin (as “gin_bridge.go” implies in the broker folder) for HTTP handling.
- Possibly MQTT for messaging and XORM for database interactions (suggested by the “db/xorm.go” file).

##### Instructing the Principal Software Engineer – What
– Frontend vs. backend components.
– Synchronous APIs vs. asynchronous messaging.
– Core services vs. utility libraries.
- Configuration and Bootstrapping: Add annotations or separate sections that represent how and when each component is initialized (hinted by the many “boot.go” files).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Frontend_UI("Frontend UI")
    end

    %% Backend Initialization
    subgraph "Backend Initialization"
        App_Boot("Application Bootstrapping")
    end

    %% Web Layer
    subgraph "Web Layer"
        Web_Server("Web Server")
        API_API("API (api)")
        APIS("APIs (apis)")
    end

    %% Service Layer
    subgraph "Service Layer"
        Service_Layer("Service/Business Logic")
        CURD("CRUD Operations")
        Menu("Menu Management")
        Smart("Smart Components")
        Page("Page Management")
        Pool("Resource Pool")
        Store("Asset/Storage")
        Time("Time Utilities")
    end

    %% Messaging Layer
    subgraph "Messaging Layer"
        Broker("Messaging Broker")
        MQTT("MQTT Messenger")
        Internal_Msg("Internal Messaging")
    end

    %% Utility & Support
    subgraph "Utility & Support"
        Utility("Utility & Logging")
        Cron("Scheduled Tasks")
        Plugin("Plugin System")
        DB("Database")
    end

    %% Connections
    Frontend_UI -->|"REST/APIs"| Web_Server
    Web_Server -->|"routes"| API_API
    Web_Server -->|"routes"| APIS
    App_Boot -->|"initializes"| Web_Server
    App_Boot -->|"initializes"| Service_Layer
    API_API -->|"calls"| Service_Layer
    APIS -->|"calls"| Service_Layer
    Service_Layer -->|"performs"| CURD
    Service_Layer -->|"manages"| Menu
    Service_Layer -->|"controls"| Smart
    Service_Layer -->|"handles"| Page
    Service_Layer -->|"allocates"| Pool
    Service_Layer -->|"stores"| Store
    Service_Layer -->|"utilizes"| Time
    Service_Layer -->|"logs_utils"| Utility
    Service_Layer -->|"queries"| DB
    Service_Layer -->|"communicates"| Broker
    Service_Layer -->|"communicates"| MQTT
    Service_Layer -->|"communicates"| Internal_Msg
    Service_Layer -->|"schedules"| Cron
    Service_Layer -->|"extends"| Plugin
    Broker --- MQTT

    %% Click Events
    click Frontend_UI "https://github.com/busy-cloud/boat/tree/main/webui"
    click Web_Server "https://github.com/busy-cloud/boat/blob/main/web/engine.go"
    click API_API "https://github.com/busy-cloud/boat/blob/main/api/api.go"
    click APIS "https://github.com/busy-cloud/boat/blob/main/apis/api.go"
    click App_Boot "https://github.com/busy-cloud/boat/blob/main/cmd/main.go"
    click Service_Layer "https://github.com/busy-cloud/boat/blob/main/service/service.go"
    click CURD "https://github.com/busy-cloud/boat/blob/main/curd/create.go"
    click Menu "https://github.com/busy-cloud/boat/blob/main/menu/boot.go"
    click Smart "https://github.com/busy-cloud/boat/blob/main/smart/chart.go"
    click Page "https://github.com/busy-cloud/boat/blob/main/page/api.go"
    click Pool "https://github.com/busy-cloud/boat/blob/main/pool/boot.go"
    click Store "https://github.com/busy-cloud/boat/blob/main/store/dir.go"
    click Time "https://github.com/busy-cloud/boat/blob/main/time/quick.go"
    click Broker "https://github.com/busy-cloud/boat/blob/main/broker/boot.go"
    click MQTT "https://github.com/busy-cloud/boat/blob/main/mqtt/boot.go"
    click Internal_Msg "https://github.com/busy-cloud/boat/blob/main/internal/broker.go"
    click Utility "https://github.com/busy-cloud/boat/blob/main/lib/cache.go"
    click Cron "https://github.com/busy-cloud/boat/blob/main/cron/boot.go"
    click Plugin "https://github.com/busy-cloud/boat/blob/main/plugin/boot.go"
    click DB "https://github.com/busy-cloud/boat/blob/main/db/boot.go"

    %% Styles
    classDef frontend fill:#ffdddd,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#ddffdd,stroke:#009933,stroke-width:2px;
    classDef service fill:#ddeeff,stroke:#0033cc,stroke-width:2px;
    classDef messaging fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
    classDef scheduled fill:#e6ccff,stroke:#9933cc,stroke-width:2px;
    classDef plugin fill:#e6f5d0,stroke:#669966,stroke-width:2px;
    classDef db fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef utility fill:#eeeeee,stroke:#999999,stroke-width:2px;

    class Frontend_UI frontend;
    class App_Boot,Web_Server,API_API,APIS backend;
    class Service_Layer,CURD,Menu,Smart,Page,Pool,Store,Time service;
    class Broker,MQTT,Internal_Msg messaging;
    class Cron scheduled;
    class Plugin plugin;
    class DB db;
    class Utility utility;
```
