# riandyrn/otelchi architecture

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

- Interactive diagram: https://gitdiagram.com/riandyrn/otelchi
- Repository: https://github.com/riandyrn/otelchi

## Overview

##### Primary System Components
- Middleware/Instrumentation Library: This is the core of the project – middleware.go and related metric files provide the instrumentation logic.
- OpenTelemetry Integration: Highlight how the library captures and sends traces and metrics. Include components that relate to the OpenTelemetry Collector or backend (even if these are external).
- go-chi Router Integration: Indicate how otelchi ties into go-chi for handling HTTP requests.
- Example Applications: Represent both “basic” and “multi-services” examples to show real-world integration. In multi-services, separate components for front-end and back-end services, plus utilities (healthcheck, metrics, tracer) should be illustrated.
- Build, Test, and CI/CD: Note the existence of workflows (.github/workflows) and test directories that validate the functionality. This reflects continuous integration and quality assurance processes.
- Configuration and Versioning: Show auxiliary components like config.go and version/version.go that support configuration and versioning for the library.

##### Relationships and Interactions
- How HTTP requests flow from the go-chi router into the middleware where the instrumentation hooks (tracing and metrics) are activated.
- In the multi-services case, show services (front-svc and back-svc) communicating possibly over defined interfaces (REST APIs), with instrumentation applied to both.

##### Architectural Patterns and Design Principles
- Layered or modular design: Separate your instrumentation logic from the business logic of the application. Even though this project is a library, understanding its modularity is key.
- Middleware pattern: Clearly represent how the middleware intercepts HTTP requests/responses, applying OpenTelemetry instrumentation.
- Dependency inversion: Highlight how this library is built to easily be injected into any go-chi application.

##### Technologies and Frameworks
- Go as the programming language (evidenced by go.mod, go.sum, and main.go files).
- The go-chi router (as the integration point for handling HTTP requests).
- OpenTelemetry for both traces and metrics instrumentation.
- Docker and docker-compose in the examples for containerization and orchestration.
- Continuous integration tools associated with workflows in .github/workflows.

##### Final Touches
- Reference the actual file structure and README descriptions where appropriate to back up each component you’ve drawn.
- Ease of integration: The middleware is designed as a drop-in component for any go-chi-based service, which is a critical selling point of otelchi.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["HTTP Request"]:::core
    B["go-chi Router"]:::core
    C["otelchi Middleware"]:::core
    A -->|"inbound"| B
    B -->|"handles"| C

    D["Tracing Module"]:::core
    E["Metrics Module"]:::core
    C -->|"captures"| D
    C -->|"captures"| E

    F["External Monitoring: OpenTelemetry Collector"]:::external
    G["External Monitoring: Prometheus"]:::external
    D -->|"sends_traces"| F
    E -->|"sends_metrics"| G

    H["Configuration Module"]:::config
    I["Version Management"]:::config
    H -->|"configures"| C
    H -->|"configures"| E
    I -->|"version_info"| C

    subgraph "Example Applications"
        J["Basic Example Application"]:::example
        subgraph "Multi-Service Example"
            K["Multi-Service – Front-End"]:::example
            L["Multi-Service – Back-End"]:::example
            M["Multi-Service Utils"]:::example
        end
    end
    C -->|"integrated_in"| J
    C -->|"integrated_in"| K
    C -->|"integrated_in"| L
    K -->|"calls_API"| L

    N["CI/CD Workflows (.github/workflows)"]:::ci
    O["Test Suite (test/)"]:::ci
    N -->|"validate"| C
    O -->|"tests"| C

    classDef core fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef external fill:#A9DFBF,stroke:#229954,stroke-width:2px;
    classDef example fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef ci fill:#F5B7B1,stroke:#CB4335,stroke-width:2px;
    classDef config fill:#D2B4DE,stroke:#884EA0,stroke-width:2px;

    click C "https://github.com/riandyrn/otelchi/blob/master/middleware.go"
    click E "https://github.com/riandyrn/otelchi/tree/master/metric/"
    click H "https://github.com/riandyrn/otelchi/blob/master/config.go"
    click J "https://github.com/riandyrn/otelchi/tree/master/examples/basic/"
    click K "https://github.com/riandyrn/otelchi/tree/master/examples/multi-services/front-svc/"
    click L "https://github.com/riandyrn/otelchi/tree/master/examples/multi-services/back-svc/"
    click M "https://github.com/riandyrn/otelchi/tree/master/examples/multi-services/utils/"
    click N "https://github.com/riandyrn/otelchi/tree/master/.github/workflows/"
    click O "https://github.com/riandyrn/otelchi/tree/master/test/"
    click I "https://github.com/riandyrn/otelchi/blob/master/version/version.go"
```
