# kilowatt-commando/controller-service architecture

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

- Interactive diagram: https://gitdiagram.com/kilowatt-commando/controller-service
- Repository: https://github.com/kilowatt-commando/controller-service

## Overview

##### Main Components

a. External Interfaces:
- Kafka Message Broker (show both input and output topics)
- WebSocket Interface (for push notifications)
- REST API endpoints

b. Internal Components:
- Core Controller Service
- Message Handlers Layer
- Data Management Layer
- Monitoring System
- Push Notification System

##### Component Organization

TOP LAYER:
- External Client Communications
- REST Controllers (PowerplantRestController)
- WebSocket Interface (PushNotificationController)

MIDDLE LAYER:
- Message Processing
- Kafka Consumers (PowerPlantListener)
- Kafka Producers (PowerPlantCommandSender)
- Command Handlers (PowerPlantActivityHandler)
- Status Handlers (PowerPlantStatusHandler)

BOTTOM LAYER:
- Data Management
- PowerPlantActivity Repository
- Activity Monitoring System

##### Key Interactions to Highlight

- Incoming Kafka messages from power plant status topic
- Outgoing commands through control topic
- WebSocket push notifications to clients
- REST API interactions
- Data flow between handlers and repository
- Monitoring system interactions

##### Additional Details

A notes section showing:
- Environment configurations
- Kafka topic names
- Key DTOs (PlantStatus, PowerplantCommand, etc.)

##### Monitoring and logging capabilities

Keep the abstraction level focused on the architectural components while showing the key integration points with external systems. This will help developers understand both the internal structure and how the service fits into the larger system.

This design should reflect the service's primary responsibilities of:
- Processing power plant status updates
- Sending control commands
- Monitoring plant activities
- Providing real-time updates via WebSocket
- Maintaining activity history
- Exposing REST endpoints for control operations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef external fill:#6495ED,stroke:#333,stroke-width:2px
    classDef processing fill:#98FB98,stroke:#333,stroke-width:2px
    classDef data fill:#FFD700,stroke:#333,stroke-width:2px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:2px
    
    %% External Layer
    subgraph External["External Interfaces"]
        KAFKA[("Kafka Message Broker")]:::external
        REST["REST API"]:::external
        WS["WebSocket Interface"]:::external
    end

    %% Top Layer - Controllers
    subgraph Controllers["Controller Layer"]
        RC["PowerplantRestController"]:::external
        PC["PushNotificationController"]:::external
        WSC["WebSocket Config"]:::config
    end

    %% Middle Layer - Message Processing
    subgraph Processing["Message Processing Layer"]
        KP["Kafka Producer Config"]:::config
        KC["Kafka Consumer Config"]:::config
        PL["PowerPlant Listener"]:::processing
        PCS["PowerPlant Command Sender"]:::processing
        PAH["PowerPlant Activity Handler"]:::processing
        PSH["PowerPlant Status Handler"]:::processing
        PLH["PowerPlant Logging Handler"]:::processing
    end

    %% Bottom Layer - Data Management
    subgraph Data["Data Management Layer"]
        PA["PowerPlant Activity"]:::data
        PAR["PowerPlant Activity Repository"]:::data
        PAM["PowerPlant Activity Monitor"]:::processing
        SC["Scheduling Configuration"]:::config
    end

    %% Core DTOs
    subgraph DTOs["Data Transfer Objects"]
        PS["Plant Status"]:::data
        PC_DTO["Powerplant Command"]:::data
        PST["Powerplant Status"]:::data
        PO["Powerplant Operation"]:::data
    end

    %% Relationships
    KAFKA --> PL
    PCS --> KAFKA
    PL --> PSH
    PSH --> PAH
    PAH --> PAR
    PAH --> PLH
    PAR --> PAM
    PAM --> PC
    RC --> PAH
    PAH --> PCS
    PAM --> WS
    PC --> WS

    %% Click events
    click RC "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/rest/PowerplantRestController.java"
    click PC "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/push/PushNotificationController.java"
    click WSC "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/push/WebSocketConfig.java"
    click KP "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/kafka/KafkaProducerConfig.java"
    click KC "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/kafka/KafkaConsumerConfig.java"
    click PL "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/kafka/PowerPlantListener.java"
    click PCS "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/kafka/PowerPlantCommandSender.java"
    click PAH "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/handlers/PowerPlantActivityHandler.java"
    click PSH "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/handlers/PowerPlantStatusHandler.java"
    click PLH "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/handlers/PowerPlantLoggingHandler.java"
    click PA "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/data/PowerPlantActivity.java"
    click PAR "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/data/PowerPlantActivityRepository.java"
    click PAM "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/monitor/PowerPlantActivityMonitor.java"
    click SC "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/kilowattcommando/controllerservice/monitor/SchedulingConfiguration.java"
    click PS "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/dto/PlantStatus.java"
    click PC_DTO "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/dto/PowerplantCommand.java"
    click PST "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/dto/PowerplantStatus.java"
    click PO "https://github.com/Kilowatt-Commando/controller-service/blob/main/src/main/java/dto/PowerplantOperation.java"

    %% Legend
    subgraph Legend
        L1["External Interfaces"]:::external
        L2["Processing Components"]:::processing
        L3["Data Components"]:::data
        L4["Configuration"]:::config
    end
```
