# h-mdm/hmdm-server architecture

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

- Interactive diagram: https://gitdiagram.com/h-mdm/hmdm-server
- Repository: https://github.com/h-mdm/hmdm-server

## Overview

##### Principal Components
- Core Server Application: Represented by the “server” module—it contains the main entry point (HMDMApplication.java), the REST resource controllers (all the endpoints under /rest/resource and JSON models), the web app static files (AngularJS-based UI in server/src/main/webapp/app) and web.xml configuration.
- Common Library: The “common” module holds shared functionality including authentication (local and JWT hints in “auth”), event handling, persistence (DAO and mappers), utilities and Guice modules for dependency injection. This core library provides foundational services for all modules.
- Security & JWT Module: The “jwt” module clearly implements JWT-based security (with filters and token provider classes) so include this as a specialized security component that integrates with the core authentication in “common.”
- Notification Module: The “notification” module implements push and MQTT-based notifications (e.g., classes like MqttEnvelope, PushSender, and the corresponding Guice modules) which are used to trigger device notifications.
- REST API & Web UI: The REST API endpoints within “server” provide the interface for mobile apps and the web panel. Also highlight the front-end components (AngularJS controllers, views, and assets under webapp) that the administrators interact with.
- Installation & External Configuration: Represent supplementary components such as installation scripts, Liquibase configuration (across common, notification, plugins, and server directories), and external SQL scripts. The installer scripts (hmdm_install.sh, init-plugin.sh) and liquibase changelogs are key elements of deployment and configuration.

##### Relationships and Interactions
- The core “common” layer underpins all modules including authentication, event processing, data persistence, and utility services. All service and persistence modules in “server”, “jwt”, and “notification” (and those within plugins) are built on top of these common libraries.
- The JWT module is tightly coupled to the authentication flow, intercepting API requests via filters and providing tokens.
- The Notification module dispatches alerts and push messages, using MQTT and REST interfaces for delivery.
- The Plugin modules integrate with the core system to provide extended features (audit logs, device information, device logs, messaging, push notifications, etc.). They are dynamically loaded/configured using Guice modules and Liquibase migration scripts.
- Data persistence is managed by various DAO and Mapper classes that interact with a central database (which you may represent as a backend repository) via SQL configuration and connection pooling (configured in Liquibase modules).

##### Architectural Patterns and Design Principles
- Plugin and Extensibility: Highlight the plugin architecture (each plugin as an independent module that conforms to a common Plugin interface) that allows custom functionality to be added without modifying the core.
- RESTful API: Illustrate that the front-end and mobile apps communicate via standardized REST endpoints.
- Security Layer: Clearly mark out the security layer (JWT filtering, authentication) that protects the API endpoints.
- Data Persistence: Represent a dedicated data access layer (DAO and domain objects) that interacts with the underlying database.

##### Technologies, Frameworks, and External Services
- Java as the programming language with Maven for build management.
- Apache Tomcat (as implied by the “server” directory and web.xml configuration) for servlet container deployment.
- Guice is used for dependency injection.
- Liquibase for managing database changes via changelog files.
- Web technologies include AngularJS-based client-side components.
- MQTT (and possibly other push notification protocols) for handling device notifications.
- JWT for stateless security mechanisms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Admin Client / Mobile App"]:::external

    subgraph "Core Server Application"
        C["HMDM Application (Entry)"]:::server
        D["Web Assets"]:::server
        B["REST API & Web UI"]:::web
    end

    E["Common Library"]:::common
    F["Security & JWT Module"]:::security
    G["Notification Module"]:::notification

    subgraph "Plugin Architecture"
        H1["Audit Plugin"]:::plugin
        H2["DeviceInfo Plugin"]:::plugin
        H3["DeviceLog Plugin"]:::plugin
        H4["Messaging Plugin"]:::plugin
        H5["Push Plugin"]:::plugin
        H6["Xtra Plugin"]:::plugin
        H7["Platform Plugin"]:::plugin
    end

    I["Database"]:::external
    J["MQTT Broker"]:::external
    K["Installation & Config"]:::install

    %% Relationships
    A -->|"calls"| B
    B -->|"handled_by"| C
    C -->|"utilizes"| E
    F -->|"integrates_with"| C
    G -->|"notifies"| C
    G -->|"communicates_with"| J
    H1 -->|"plugs_into"| C
    H2 -->|"plugs_into"| C
    H3 -->|"plugs_into"| C
    H4 -->|"plugs_into"| C
    H5 -->|"plugs_into"| C
    H6 -->|"plugs_into"| C
    H7 -->|"plugs_into"| C
    E -->|"data_access"| I
    F -->|"uses"| E
    G -->|"uses"| E
    K -->|"deploys_to"| C
    K -->|"updates"| E

    %% Click Events
    click C "https://github.com/h-mdm/hmdm-server/blob/master/server/src/main/java/com/hmdm/HMDMApplication.java"
    click D "https://github.com/h-mdm/hmdm-server/tree/master/server/src/main/webapp/app"
    click B "https://github.com/h-mdm/hmdm-server/tree/master/server/src/main/java/com/hmdm/rest/resource"
    click E "https://github.com/h-mdm/hmdm-server/tree/master/common/src/main/java/com/hmdm/auth"
    click F "https://github.com/h-mdm/hmdm-server/blob/master/jwt/src/main/java/com/hmdm/security/jwt/JWTFilter.java"
    click G "https://github.com/h-mdm/hmdm-server/blob/master/notification/src/main/java/com/hmdm/notification/PushSender.java"
    click H1 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/audit"
    click H2 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/deviceinfo"
    click H3 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/devicelog"
    click H4 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/messaging"
    click H5 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/push"
    click H6 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/xtra"
    click H7 "https://github.com/h-mdm/hmdm-server/tree/master/plugins/platform"
    click K "https://github.com/h-mdm/hmdm-server/tree/master/install"

    %% Styles
    classDef server fill:#AED6F1,stroke:#000,stroke-width:1px;
    classDef common fill:#F9E79F,stroke:#000,stroke-width:1px;
    classDef security fill:#F5B7B1,stroke:#000,stroke-width:1px;
    classDef notification fill:#A9DFBF,stroke:#000,stroke-width:1px;
    classDef plugin fill:#D2B4DE,stroke:#000,stroke-width:1px;
    classDef web fill:#FAD7A0,stroke:#000,stroke-width:1px;
    classDef external fill:#F5CBA7,stroke:#000,stroke-width:1px;
    classDef install fill:#D5F5E3,stroke:#000,stroke-width:1px;
```
