# astrohuntsman/huntsman-dome architecture

> Architecture diagram of the GitHub repository astrohuntsman/huntsman-dome, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/astrohuntsman/huntsman-dome
- Repository: https://github.com/astrohuntsman/huntsman-dome

## Overview

##### Main Components

a) Client Layer:
- TheSkyX Application (astronomical software)
- X2Dome Driver Interface

b) Communication Layer:
- gRPC Framework
- Protocol Buffers (protobuf) definitions

c) Control Layer:
- Python gRPC Server (on Raspberry Pi)
- Hardware Control Components

d) Hardware Layer:
- Dome Rotation Motor
- Encoder
- AutomationHAT (optional)
- GPIO Interfaces

- [TheSkyX Application Layer]
- ↓
- [C++ X2Dome Driver Layer]
- ↓
- [gRPC Communication Layer]
- ↓
- [Python Control Layer]
- ↓
- [Hardware Interface Layer]

##### Component Relationships

- Command flow from TheSkyX → X2Dome Driver → gRPC → Python Server → Hardware
- Status/feedback flow in the reverse direction
- Bidirectional communication between components where applicable

##### Important Details

a) Software Components:
- TheSkyX with X2 standard integration
- C++ X2Dome driver component
- Python gRPC server component
- GPIO control interfaces

b) Communication Protocols:
- gRPC channels between C++ and Python components
- Hardware communication protocols (GPIO)

c) Configuration Elements:
- dome_controller_config.yml
- Protocol Buffer definitions (hx2dome.proto)

##### Technical Details to Highlight

- gRPC service definitions
- Hardware abstraction layers
- Configuration management
- Logging system integration
- Testing/simulation capabilities

##### Implementation Notes

- Main application components
- Supporting libraries (gpiozero, smbus, sn3218)
- Configuration files
- Generated code components

##### Hardware abstraction and simulation capabilities

This system design should clearly illustrate how commands flow from the astronomical software through various layers to control the physical dome, and how status information flows back up through the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        TheSkyX["TheSkyX Application"]:::ui
        X2Driver["X2Dome Driver Interface"]:::driver
        click X2Driver "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-TheSkyX-driver/src/x2dome.cpp"
        MainEntry["Driver Entry Point"]:::driver
        click MainEntry "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-TheSkyX-driver/src/main.cpp"
        DriverInterface["Driver Interface Definitions"]:::driver
        click DriverInterface "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-TheSkyX-driver/src/licensedinterfaces/domedriverinterface.h"
    end

    subgraph Communication["Communication Layer"]
        Proto["Protocol Buffers Definition"]:::proto
        click Proto "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-TheSkyX-driver/hx2dome.proto"
        CppGRPC["C++ gRPC Generated Code"]:::grpc
        click CppGRPC "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-TheSkyX-driver/src/hx2dome.grpc.pb.cpp"
        PyGRPC["Python gRPC Generated Code"]:::grpc
        click PyGRPC "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-server/hx2dome_pb2.py"
    end

    subgraph Control["Control Layer"]
        GRPCServer["Python gRPC Server"]:::server
        click GRPCServer "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-server/huntsman_dome_server.py"
        Config["System Configuration"]:::config
        click Config "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/gRPC-server/dome_controller_config.yml"
        HWControl["Hardware Control Component"]:::control
        click HWControl "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/dome_control.py"
        Logger["Logging System"]:::util
        click Logger "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/logging.py"
        Testing["Testing Components"]:::util
        click Testing "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/domehunter/tests/test_domehunter.py"
        Example["Example Implementation"]:::util
        click Example "https://github.com/AstroHuntsman/huntsman-dome/blob/develop/examples/dome_control_example.ipynb"
    end

    subgraph Hardware["Hardware Layer"]
        Motor["Dome Rotation Motor"]:::hw
        Encoder["Position Encoder"]:::hw
        GPIO["GPIO Interfaces"]:::hw
        AutoHAT["AutomationHAT"]:::hw
    end

    %% Relationships
    TheSkyX --> X2Driver
    X2Driver --> MainEntry
    X2Driver --> DriverInterface
    X2Driver --> CppGRPC
    Proto --> |Generates| CppGRPC
    Proto --> |Generates| PyGRPC
    CppGRPC <--> |gRPC| PyGRPC
    PyGRPC --> GRPCServer
    GRPCServer --> HWControl
    Config --> GRPCServer
    Logger --> GRPCServer
    HWControl --> Motor
    HWControl --> Encoder
    HWControl --> GPIO
    HWControl --> AutoHAT
    Testing --> HWControl
    Example --> HWControl

    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef driver fill:#2ecc71,stroke:#27ae60,color:white
    classDef proto fill:#f1c40f,stroke:#f39c12,color:black
    classDef grpc fill:#e67e22,stroke:#d35400,color:white
    classDef server fill:#9b59b6,stroke:#8e44ad,color:white
    classDef control fill:#1abc9c,stroke:#16a085,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef util fill:#34495e,stroke:#2c3e50,color:white
    classDef hw fill:#e74c3c,stroke:#c0392b,color:white
```
