# simonbuehler/sunandmoon_backend architecture

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

- Interactive diagram: https://gitdiagram.com/simonbuehler/sunandmoon_backend
- Repository: https://github.com/simonbuehler/sunandmoon_backend

## Overview

##### Main Components

a) Frontend Layer:
- Located in the `/src` directory
- Contains React components (ConfigEditor, QueryEditor)
- Handles user interface and configuration
- Plugin registration and type definitions

b) Backend Layer:
- Located in the `/pkg` directory
- Contains the core data source implementation
- Models for settings and data structures
- Handles astronomical calculations using Suncalc library

c) External Dependencies:
- Grafana Platform
- Suncalc Go Library
- Frontend dependencies (React, etc.)

**[Grafana UI] --> [Plugin Frontend Components]**
- ConfigEditor
- QueryEditor
- Type Definitions

**[Plugin Backend]**
- Data Source Implementation
- Settings Management
- Astronomical Calculations

**[Suncalc Library] --> [Plugin Backend]**
**[Grafana Backend] <--> [Plugin Backend]**

##### Important Relationships to Highlight

- Configuration flow from ConfigEditor to backend settings
- Query flow from QueryEditor through the backend to calculations
- Demonstrate integration points with Grafana platform

##### Technical Details

- TypeScript/React frontend architecture
- Go backend implementation
- Plugin initialization and lifecycle
- Data flow for different types of astronomical calculations

##### Deployment Context

- How the plugin integrates within Grafana's plugin system
- Configuration management (provisioning)
- Demonstrate how public dashboard support is achieved

- Backend calculation handling
- Public dashboard support
- Astronomical data processing pipeline
- Configuration management for geographical coordinates

This architecture should be represented in a way that emphasizes the plugin's main selling point: moving calculations to the backend for public dashboard compatibility while maintaining all the astronomical calculation capabilities of the original frontend-only version.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend Layer"
        GrafanaUI["Grafana UI"]
        ConfigEditor["Config Editor"]:::frontend
        QueryEditor["Query Editor"]:::frontend
        TypeDefs["Type Definitions"]:::frontend
        PluginReg["Plugin Registration"]:::frontend
        DataSourceIF["Data Source Interface"]:::frontend
    end

    subgraph "Backend Layer"
        MainEntry["Main Plugin Entry"]:::backend
        DataSourceImpl["Data Source Implementation"]:::backend
        SettingsMgmt["Settings Management"]:::backend
        DataModels["Data Models"]:::backend
    end

    subgraph "External Dependencies"
        GrafanaBackend["Grafana Backend"]:::external
        SuncalcLib["Suncalc Library"]:::external
    end

    subgraph "Configuration"
        PluginConfig["Plugin Configuration"]:::config
        DeployConfig["Deployment Configuration"]:::config
        DockerSetup["Docker Setup"]:::config
        EnvSetup["Environment Setup"]:::config
    end

    subgraph "Build & Testing"
        FrontendTests["Frontend Tests"]:::testing
        BackendTests["Backend Tests"]:::testing
        BuildConfig["Build Configuration"]:::testing
        CIPipeline["CI/CD Pipeline"]:::testing
    end

    GrafanaUI --> ConfigEditor
    GrafanaUI --> QueryEditor
    ConfigEditor --> DataSourceIF
    QueryEditor --> DataSourceIF
    DataSourceIF --> MainEntry
    TypeDefs --> DataSourceIF
    PluginReg --> DataSourceIF

    MainEntry --> DataSourceImpl
    DataSourceImpl --> SettingsMgmt
    DataSourceImpl --> DataModels
    SuncalcLib --> DataSourceImpl
    GrafanaBackend <--> DataSourceImpl

    PluginConfig --> MainEntry
    DeployConfig --> MainEntry
    DockerSetup --> EnvSetup
    EnvSetup --> MainEntry

    FrontendTests --> ConfigEditor
    FrontendTests --> QueryEditor
    BackendTests --> DataSourceImpl
    BuildConfig --> PluginReg
    CIPipeline --> BuildConfig

    %% Click events for component mapping
    click ConfigEditor "https://github.com/simonbuehler/sunandmoon_backend/blob/master/src/components/ConfigEditor.tsx"
    click QueryEditor "https://github.com/simonbuehler/sunandmoon_backend/blob/master/src/components/QueryEditor.tsx"
    click PluginReg "https://github.com/simonbuehler/sunandmoon_backend/blob/master/src/module.ts"
    click TypeDefs "https://github.com/simonbuehler/sunandmoon_backend/blob/master/src/types.ts"
    click DataSourceIF "https://github.com/simonbuehler/sunandmoon_backend/blob/master/src/datasource.ts"
    click MainEntry "https://github.com/simonbuehler/sunandmoon_backend/blob/master/pkg/main.go"
    click DataSourceImpl "https://github.com/simonbuehler/sunandmoon_backend/blob/master/pkg/plugin/datasource.go"
    click SettingsMgmt "https://github.com/simonbuehler/sunandmoon_backend/blob/master/pkg/models/settings.go"
    click DataModels "https://github.com/simonbuehler/sunandmoon_backend/blob/master/pkg/models/models.go"
    click PluginConfig "https://github.com/simonbuehler/sunandmoon_backend/blob/master/src/plugin.json"
    click DeployConfig "https://github.com/simonbuehler/sunandmoon_backend/blob/master/provisioning/datasources/datasources.yml"
    click DockerSetup "https://github.com/simonbuehler/sunandmoon_backend/tree/master/.config/Dockerfile"
    click EnvSetup "https://github.com/simonbuehler/sunandmoon_backend/blob/master/.config/entrypoint.sh"
    click BackendTests "https://github.com/simonbuehler/sunandmoon_backend/blob/master/pkg/plugin/datasource_test.go"
    click BuildConfig "https://github.com/simonbuehler/sunandmoon_backend/blob/master/webpack.config.ts"
    click CIPipeline "https://github.com/simonbuehler/sunandmoon_backend/blob/master/.github/workflows/ci.yml"

    %% Styling
    classDef frontend fill:#3572A5,color:white
    classDef backend fill:#00ADD8,color:white
    classDef external fill:#FFA500,color:black
    classDef config fill:#808080,color:white
    classDef testing fill:#98FF98,color:black

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        External["External Dependency"]:::external
        Config["Configuration"]:::config
        Testing["Testing & Build"]:::testing
    end
```
