# superlinear-insights/api_logger architecture

> Architecture diagram of the GitHub repository superlinear-insights/api_logger, 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/superlinear-insights/api_logger
- Repository: https://github.com/superlinear-insights/api_logger

## Overview

- Gem Integration in Rails – Represent how the gem is plugged into a Rails app using the Railtie (lib/api_logger/railtie.rb). This component is responsible for integrating the API Logger’s functionality (e.g., auto injection of middleware) into the Rails stack.
- Configuration – Illustrate the configuration setup (lib/api_logger/configuration.rb) which uses the ApiLogger.configure block. Include configuration options like table_name, enabled flag, use_middleware, exclude_routes, and allowed_hosts.
- Generators & Installation – Include the generator component (lib/generators/api_logger/install/install_generator.rb and accompanying templates) that helps install the necessary files and instructions into a Rails project.
- Database / API Log Model – Since logging entries are persisted in the database (as described in the README), note a component representing the ApiLog table/model. This shows where and how the logs (with fields for endpoint, request_params, response_body, etc.) are stored.
- Maintenance Tasks – Represent the rake tasks (lib/tasks/api_logger_tasks.rake) to perform cleanup (e.g., log purging based on age).

##### Relationships and Data Flow
- How configuration settings dictate what should be logged or excluded, influencing the behavior of middleware and manual logging methods.
- A side note showing that manual logging calls (via ApiLogger.log) interact with the same logging backend.

##### Architectural Patterns and Integration Points
- “Zero Configuration” and “Convention over Configuration” design principles that allow Rails developers to adopt this gem with little setup.
- Integration point via Railtie that makes the gem’s middleware automatically available in the Rails middleware stack.
- Role of generators as an extension point to seamlessly inject installation templates and tasks.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Rails Application Layer
    subgraph "Rails Application"
        A("Rails Application"):::app
        R("HTTP Request (Net::HTTP)"):::external
    end

    %% Gem Integration Components
    subgraph "Gem Integration"
        RT("Rails Integration (Railtie)"):::integration
        G("Generators & Installation"):::generator
    end

    %% Core Functionality
    subgraph "Core Functionality"
        M("Automatic Request Logging Middleware"):::middleware
        C("Logging Configuration"):::config
        ML("Manual Logging (ApiLogger.log)"):::middleware
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        D("Database/API Log Storage"):::database
    end

    %% Maintenance Tasks
    subgraph "Maintenance"
        T("Maintenance Rake Task"):::task
    end

    %% Connections
    A -->|"initiates"| R
    R -->|"intercepted_by"| M
    RT -->|"injects"| M
    C -->|"configures"| M
    M -->|"storesLogTo"| D
    C -->|"guides"| D
    A -->|"triggers"| ML
    ML -->|"logsTo"| D
    G -->|"installs"| RT
    G -->|"installs"| C
    G -->|"installs"| D
    T -->|"cleansUp"| D

    %% Technology/Principle Notations
    A ---|"Rails"| RT
    M ---|"Net.HTTP"| R

    %% Click Events
    click RT "https://github.com/superlinear-insights/api_logger/blob/main/lib/api_logger/railtie.rb"
    click M "https://github.com/superlinear-insights/api_logger/blob/main/lib/api_logger/middleware.rb"
    click C "https://github.com/superlinear-insights/api_logger/blob/main/lib/api_logger/configuration.rb"
    click G "https://github.com/superlinear-insights/api_logger/blob/main/lib/generators/api_logger/install/install_generator.rb"
    click G "https://github.com/superlinear-insights/api_logger/tree/main/lib/generators/api_logger/install/templates"
    click D "https://github.com/superlinear-insights/api_logger/blob/main/lib/generators/api_logger/install/templates/create_api_logs.rb.tt"
    click T "https://github.com/superlinear-insights/api_logger/blob/main/lib/tasks/api_logger_tasks.rake"

    %% Styles
    classDef app fill:#bbf,stroke:#333,stroke-width:2px;
    classDef external fill:#ddf,stroke:#333,stroke-width:2px;
    classDef integration fill:#fdd,stroke:#333,stroke-width:2px;
    classDef middleware fill:#dfd,stroke:#333,stroke-width:2px;
    classDef config fill:#ffd,stroke:#333,stroke-width:2px;
    classDef generator fill:#f9d,stroke:#333,stroke-width:2px;
    classDef database fill:#dff,stroke:#333,stroke-width:2px;
    classDef task fill:#fdd,stroke:#333,stroke-width:2px;
```
