# spatie/laravel-http-logger architecture

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

- Interactive diagram: https://gitdiagram.com/spatie/laravel-http-logger
- Repository: https://github.com/spatie/laravel-http-logger

## Overview

##### Main Components

a. Request Flow Layer:
- HTTP Request Entry Point
- Laravel Middleware Pipeline
- HTTP Logger Middleware (central component)

b. Core Components:
- LogProfile Interface/Implementation
- LogWriter Interface/Implementation
- Sanitizer Component
- Service Provider

c. Configuration:
- Config Management
- Environment Variables

##### Component Relationships

**[HTTP Request] → [Laravel Middleware Pipeline]**
- ↓
- [HTTP Logger Middleware]
- ↙              ↘
- [LogProfile]                [LogWriter]
- (shouldLogRequest)          (logRequest)
- ↓                         ↓
- [Logic Layer]              [Sanitizer]
- ↓
- [Laravel Logger]
- ↓
- [Log Storage]

##### Important Elements to Highlight

a. Request Processing Flow:
- How requests pass through the middleware
- Decision point where LogProfile determines if logging occurs
- Sanitization process for sensitive data

b. Configuration Integration:
- How environment variables influence the system
- Config file integration points

c. Extension Points:
- Interfaces (LogProfile, LogWriter) as extension points
- Custom implementation possibilities

##### Additional Details

- Notes about supported HTTP methods (POST, PUT, PATCH, DELETE)
- Configuration options (enabled/disabled state)
- Header sanitization process
- Log channel configuration

##### Implementation Details

- Relationship between HttpLoggerServiceProvider and Laravel's service container
- Where custom implementations can be injected
- Log message format and structure

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Request["Request Flow Layer"]
        direction TB
        HTTP[HTTP Request]
        MP[Laravel Middleware Pipeline]
        HLM[HTTP Logger Middleware]:::middleware
    end

    subgraph Core["Core Components"]
        direction TB
        LP[LogProfile Interface]:::interface
        LW[LogWriter Interface]:::interface
        SAN[Sanitizer]:::security
        SP[Service Provider]:::service
    end

    subgraph Implementation["Implementation Layer"]
        direction TB
        DLW[Default Log Writer]:::implementation
        LNGR[Log Non-Get Requests Profile]:::implementation
    end

    subgraph Config["Configuration Layer"]
        direction TB
        CM[Config Management]:::config
        ENV[Environment Variables]:::config
    end

    subgraph Storage["Storage Layer"]
        direction TB
        LL[Laravel Logger]
        LS[Log Storage]
    end

    %% Connections
    HTTP --> MP
    MP --> HLM
    HLM --> LP
    HLM --> LW
    LP --> LNGR
    LW --> DLW
    DLW --> SAN
    SAN --> LL
    LL --> LS
    SP --> HLM
    CM --> SP
    ENV --> SP

    %% Click Events
    click HLM "https://github.com/spatie/laravel-http-logger/blob/main/src/Middlewares/HttpLogger.php"
    click LP "https://github.com/spatie/laravel-http-logger/blob/main/src/LogProfile.php"
    click LW "https://github.com/spatie/laravel-http-logger/blob/main/src/LogWriter.php"
    click SAN "https://github.com/spatie/laravel-http-logger/blob/main/src/Sanitizer.php"
    click SP "https://github.com/spatie/laravel-http-logger/blob/main/src/HttpLoggerServiceProvider.php"
    click DLW "https://github.com/spatie/laravel-http-logger/blob/main/src/DefaultLogWriter.php"
    click LNGR "https://github.com/spatie/laravel-http-logger/blob/main/src/LogNonGetRequests.php"
    click CM "https://github.com/spatie/laravel-http-logger/blob/main/config/http-logger.php"

    %% Styling
    classDef interface fill:#90EE90
    classDef implementation fill:#FFFFE0
    classDef middleware fill:#87CEEB
    classDef security fill:#FFB6C1
    classDef service fill:#DDA0DD
    classDef config fill:#D3D3D3

    %% Legend
    subgraph Legend
        direction TB
        I[Interface]:::interface
        M[Middleware]:::middleware
        IM[Implementation]:::implementation
        SE[Security]:::security
        S[Service]:::service
        C[Configuration]:::config
    end
```
