# higherkindness/mu-scala architecture

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

- Interactive diagram: https://gitdiagram.com/higherkindness/mu-scala
- Repository: https://github.com/higherkindness/mu-scala

## Overview

##### Main Components
- Core Library: At the center lies the mu-scala core definitions (e.g., main RPC abstractions, protocols, macro-based service implementations). This is the heart of the library.
- Server Module: Represent the gRPC server implementation, which includes components such as:
– Server configuration (from modules/config)
– gRPC server handlers and interceptors (modules/server)
– Metrics interceptors (found under modules/server/metrics)
– Health-check services (modules/health-check)
– Netty and FS2 based implementations (modules/client/netty, modules/fs2, and modules/client/cache)
– Client channel handling, caching, and configuration (modules/client/cache, modules/config)
- Metrics Module: Show integration with both Dropwizard (modules/metrics/dropwizard) and Prometheus (modules/metrics/prometheus) for metrics reporting.
- Service & Protocol Modules: This contains the service definitions, protocol implementations (Avro, Protobuf, etc.), and utilities for encoding/decoding (modules/service, modules/service/src/main, and their internal packages).
- Testing & Benchmarking: Although not part of the deployed architecture, testing modules and benchmarks ensure continuous validation and performance checks.

##### Out Relationships and Interactions
- That both client and server modules use shared configuration management (modules/config) and common utilities (internal encoders/decoders, interceptors, context propagation from modules/service and modules/testing).
- That metrics modules (Dropwizard and Prometheus) are integrated with both the client and server components as cross-cutting concerns, with interceptors feeding into metrics collection.
- Role of internal modules (e.g., modules/fs2 and modules/health-check) that provide specialized implementations, as well as the abstraction layers that allow integration of different protocols (Avro, Protobuf).

##### Architectural Patterns and Design Principles
- Modular Design: Each module encapsulates a clear aspect of the framework. Show them as discrete blocks interacting through well-defined interfaces.
- Separation of Concerns: Different modules handle client vs. server logic, configuration vs. protocol implementations, and metrics/reporting separately.
- Functional Programming: Indicate that the core library leverages purely functional paradigms (immutable data, monadic effect handling) even if not illustrated directly. This can be noted alongside the “Core” component.

##### Elements
- Clear labels for each component: “Core Library”, “Client (Netty & FS2)”, “Server (gRPC Config & Handlers)”, “Metrics (Dropwizard/Prometheus)”, “Config”, “Health-check”, etc.
- Annotations regarding key technologies and frameworks (Scala, gRPC, Avro, Protobuf, fs2, Dropwizard, Prometheus) that are central to the implementation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Library"
        Core["Core Library"]:::core
    end

    subgraph "Common"
        Config["Configuration"]:::config
    end

    subgraph "Server Module"
        SConfig["Server Config"]:::server
        GRPC["gRPC Server & Handlers"]:::server
        SMI["Server Metrics Interceptor"]:::server
        Health["Health-Check Service"]:::server
    end

    subgraph "Client Module"
        Netty["Netty-Based Client"]:::client
        FS2["FS2-Based Client"]:::client
        Cache["Client Caching"]:::client
    end

    subgraph "Metrics Module"
        Dropwizard["Dropwizard Metrics"]:::metrics
        Prometheus["Prometheus Metrics"]:::metrics
    end

    subgraph "Testing & Benchmarking"
        Bench["Benchmarks"]:::testing
        Testing["Testing Modules"]:::testing
    end

    subgraph "Documentation"
        Docs["Microsite Documentation"]:::docs
    end

    %% Core Library relationships
    Core -->|"defines"| GRPC
    Core -->|"defines"| Netty
    Core -->|"defines"| FS2

    %% Common configuration relationships
    Config -->|"configures"| SConfig
    Config -->|"configures"| Cache
    Config -->|"configures"| FS2
    Config -->|"configures"| Netty

    %% Client to Server interactions
    Netty -->|"RPCcall"| GRPC
    FS2 -->|"RPCcall"| GRPC
    Cache -->|"RPCcall"| GRPC

    %% Server Metrics integration
    SMI -->|"intercepts"| Dropwizard
    SMI -->|"intercepts"| Prometheus

    %% Health-check integration
    GRPC -->|"health"| Health

    %% Testing & Benchmarking relationships
    Testing -->|"validates"| Core
    Bench -->|"benchmarks"| Core

    %% Documentation relationships
    Docs -->|"guides"| Core

    %% Click Events
    click Core "https://github.com/higherkindness/mu-scala/tree/main/modules/service"
    click SConfig "https://github.com/higherkindness/mu-scala/blob/main/modules/config/src/main/scala/higherkindness/mu/rpc/config/server/ServerConfig.scala"
    click GRPC "https://github.com/higherkindness/mu-scala/blob/main/modules/server/src/main/scala/higherkindness/mu/rpc/server/GrpcServer.scala"
    click SMI "https://github.com/higherkindness/mu-scala/blob/main/modules/server/src/main/scala/higherkindness/mu/rpc/server/metrics/MetricsServerInterceptor.scala"
    click Health "https://github.com/higherkindness/mu-scala/blob/main/modules/health-check/src/main/scala/higherkindness/mu/rpc/healthcheck/HealthService.scala"
    click Netty "https://github.com/higherkindness/mu-scala/tree/main/modules/client/netty"
    click FS2 "https://github.com/higherkindness/mu-scala/blob/main/modules/fs2/src/main/scala/higherkindness/mu/rpc/internal/client/fs2/calls.scala"
    click Cache "https://github.com/higherkindness/mu-scala/blob/main/modules/client/cache/src/main/scala/higherkindness/mu/rpc/channel/cache/ClientCache.scala"
    click Dropwizard "https://github.com/higherkindness/mu-scala/blob/main/modules/metrics/dropwizard/src/main/scala/higherkindness/mu/rpc/dropwizard/DropWizardMetrics.scala"
    click Prometheus "https://github.com/higherkindness/mu-scala/blob/main/modules/metrics/prometheus/src/main/scala/higherkindness/mu/rpc/prometheus/PrometheusMetrics.scala"
    click Bench "https://github.com/higherkindness/mu-scala/tree/main/benchmarks"
    click Testing "https://github.com/higherkindness/mu-scala/tree/main/modules/testing"
    click Docs "https://github.com/higherkindness/mu-scala/tree/main/microsite"
    click Config "https://github.com/higherkindness/mu-scala/tree/main/modules/config"

    %% Styles
    classDef core fill:#FFEBEE,stroke:#C62828,stroke-width:2px;
    classDef config fill:#E3F2FD,stroke:#1565C0,stroke-width:2px;
    classDef server fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px;
    classDef client fill:#F3E5F5,stroke:#6A1B9A,stroke-width:2px;
    classDef metrics fill:#FFF3E0,stroke:#EF6C00,stroke-width:2px;
    classDef testing fill:#E0F7FA,stroke:#00838F,stroke-width:2px;
    classDef docs fill:#F1F8E9,stroke:#33691E,stroke-width:2px;
```
