# idojhirad/generic-iot-infrastructher architecture

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

- Interactive diagram: https://gitdiagram.com/idojhirad/generic-iot-infrastructher
- Repository: https://github.com/idojhirad/generic-iot-infrastructher

## Overview

##### Project type and purpose
- This is a Java-based IoT Gateway Server with a companion WebServer UI module.
- The GatewayServer accepts HTTP requests from IoT devices (and admin UIs), dispatches them via a command pipeline (parse→factory→command), and persists data via an AdminDB. Plugins (GenericIOT.jar variants) extend device support. Separately, the WebServer module offers a JSP/servlet UI for registering companies/products and querying data.

##### File structure
- Top-level modules:
- WebServer/ – Maven webapp (JSP, servlets, CSS) for user‐facing UI
- src/ – Core GatewayServer code (Main.java, maingatewayserver/, command/, admin_dataBase/, threadpool/, WaitablePQueue)
- resource/ – Plugin jars (GenericIOT.jar variants) and META-INF
- test/ – Unit tests for DB, threadpool, queue, plugins, JSON processing
- Key architectural patterns:
- Plugin architecture (PluginMediator + DirMonitor + plugin jars)
- Command pattern (Command interface + individual command classes)
- Factory pattern (FactoryInterface, Factory)
- Thread pool + waitable priority queue for concurrency
- HTTP service layer (ConnectionService handlers)
- Build/config: WebServer/pom.xml for the servlet container

##### README for insights
- Shows JSON structure for commands
- Mentions generalized vs. company-specific commands
- Confirms command registration mechanism

a. Main components
- Clients:
– Web Browser (interacts with WebServer UI)
– IoT Devices (HTTP clients sending JSON commands)
- WebServer Module:
– JSP pages & Servlets (RegisterCompany, GetCompany, RegisterProduct, GetProduct(s), Login)
– Talks to GatewayServer or directly to AdminDB for CRUD
- GatewayServer Core:
– HTTP Server (ConnectionService, ChannelHandler, MainHttpHandler)
– Request Processing Service (Parser → Factory → Command)
– PluginMediator (loads GenericIOT plugins via DirMonitor)
– ThreadPool + WaitablePQueue (schedules command execution)
– AdminDB (data persistence layer)
- Plugins Directory (resource/*.jar)
b. Relationships & interactions
1. IoT Device → HTTP → GatewayServer ConnectionService
2. HTTP handler delegates to RequestProcessService
3. Parser parses JSON, Factory creates appropriate Command
4. Command is submitted to ThreadPool (via WaitablePQueue)
5. Worker thread executes Command → interacts with AdminDB or PluginMediator
6. Response flows back through HTTP handler → IoT Device
7. Web Browser → HTTP → WebServer servlets → (GatewayServer or AdminDB) → returns HTML/JSON
c. Architectural patterns & design principles
- Command pattern for decoupling operations
- Factory for command instantiation
- Plugin architecture for dynamic device support
- Producer–consumer model (queue + thread pool) for concurrent request handling
d. Key technologies & libraries
- Java servlets & JSP (WebServer module)
- Custom HTTP server (ConnectionService classes)
- Java concurrency (ThreadPool, synchronized queue)
- Jar plugins (GenericIOT.jar)

##### Final advice
- Be exhaustive: capture all modules, handlers, and service layers.
- Command pipeline and plugin loading as the project’s unique aspects.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Browser["Web Browser"]:::frontend
    IoTDevices["IoT Devices"]:::frontend

    %% WebServer UI Module
    subgraph "WebServer UI Module"
        direction TB
        WS_POM["pom.xml"]:::frontend
        WS_Index["index.jsp"]:::frontend
        WS_Pages["pages/*.html"]:::frontend
        WS_CSS["css/*.css"]:::frontend
        subgraph "Servlet Controllers"
            direction TB
            RegisterCompany["RegisterCompany.java"]:::frontend
            GetProduct["GetProduct.java"]:::frontend
            WebInit["WebInitializer.java"]:::frontend
        end
    end

    %% GatewayServer Core
    subgraph "GatewayServer Core"
        direction TB
        MainApp["Main.java"]:::core

        subgraph "HTTP Server Layer"
            direction TB
            ConnSvcDir["ConnectionService Layer"]:::core
            ConnSvc["ConnectionService.java"]:::core
            ChannelHandler["ChannelHandler.java"]:::core
            MainHttpHandler["MainHttpHandler.java"]:::core
        end

        subgraph "Request Processing Layer"
            direction TB
            Parser["Parser.java"]:::core
            Factory["Factory.java"]:::core
            ReqProcSvc["RequestProcessService.java"]:::core
            CommandIF["Command.java"]:::core
        end

        subgraph "Command Implementations"
            direction TB
            CmdDir["command/*.java"]:::core
        end

        subgraph "Plugin Architecture"
            direction TB
            PluginMediator["PluginMediator.java"]:::plugin
            DirMonitor["DirMonitor.java"]:::plugin
            PluginsDir["resource/*.jar"]:::plugin
        end

        subgraph "Concurrency Layer"
            direction TB
            ThreadPool["ThreadPool.java"]:::core
            PriorityEnum["Priority.java"]:::core
            PQueue["WaitablePQueue.java"]:::core
        end

        AdminDB["AdminDB.java"]:::db
    end

    %% Flows
    IoTDevices -->|HTTP JSON| ConnSvc
    ConnSvc -->|delegates to| ReqProcSvc
    ReqProcSvc -->|parse JSON| Parser
    Parser -->|create Command| Factory
    Factory -->|instantiates| CommandIF
    CommandIF -->|submits to| ThreadPool
    ThreadPool -->|uses| PQueue
    ThreadPool -->|executes| CmdDir
    CmdDir -->|persists or plugin| AdminDB
    CmdDir -->|invokes| PluginMediator
    PluginMediator -->|monitors| DirMonitor
    PluginMediator -->|loads| PluginsDir
    ThreadPool -->|returns result| ConnSvc
    ConnSvc -->|HTTP response| IoTDevices

    Browser -->|HTTP| RegisterCompany
    RegisterCompany -->|CRUD via JDBC| AdminDB
    GetProduct -->|queries| AdminDB
    WebInit -->|initializes| WS_POM
    RegisterCompany -->|optionally calls| ConnSvc
    GetProduct -->|optionally calls| ConnSvc

    %% Click Events
    click WS_POM "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/WebServer/pom.xml"
    click WS_Index "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/WebServer/src/main/webapp/index.jsp"
    click WS_Pages "https://github.com/idojhirad/generic-iot-infrastructher/tree/main/WebServer/src/main/webapp/pages/"
    click WS_CSS "https://github.com/idojhirad/generic-iot-infrastructher/tree/main/WebServer/src/main/webapp/css/"
    click RegisterCompany "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/WebServer/src/main/webapp/servlet/RegisterCompany.java"
    click GetProduct "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/WebServer/src/main/webapp/servlet/GetProduct.java"
    click WebInit "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/WebServer/src/main/webapp/servlet/WebInitializer.java"
    click MainApp "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/Main.java"
    click ConnSvcDir "https://github.com/idojhirad/generic-iot-infrastructher/tree/main/src/maingatewayserver/connectionService/"
    click Parser "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/maingatewayserver/request_process_sevice/Parser.java"
    click Factory "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/maingatewayserver/request_process_sevice/Factory/Factory.java"
    click ReqProcSvc "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/maingatewayserver/request_process_sevice/RequestProcessService.java"
    click CommandIF "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/maingatewayserver/request_process_sevice/Command.java"
    click CmdDir "https://github.com/idojhirad/generic-iot-infrastructher/tree/main/src/command/"
    click PluginMediator "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/maingatewayserver/PluginMediator.java"
    click DirMonitor "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/maingatewayserver/DirMonitor.java"
    click PluginsDir "https://github.com/idojhirad/generic-iot-infrastructher/tree/main/resource/"
    click ThreadPool "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/threadpool/ThreadPool.java"
    click PriorityEnum "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/threadpool/Priority.java"
    click PQueue "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/WaitablePQueue/WaitablePQueue.java"
    click AdminDB "https://github.com/idojhirad/generic-iot-infrastructher/blob/main/src/admin_dataBase/AdminDB.java"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef core fill:#E6FFE6,stroke:#28A745,color:#22863A;
    classDef plugin fill:#F5E6FF,stroke:#6F42C1,color:#5A32A3;
    classDef db fill:#FFF5E6,stroke:#D73A49,color:#CB2431;
```
