# minhngoc2512/laravel-helpers architecture

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

- Interactive diagram: https://gitdiagram.com/minhngoc2512/laravel-helpers
- Repository: https://github.com/minhngoc2512/laravel-helpers

## Overview

##### Main Components
- Service Provider: Represented by HelperServiceProvider (in src/providers). It is registered in the Laravel app to bind services and configuration.
- Configuration: Through config/helper.php, which contains settings for pagination, backup, deploy, and logging. This component affects how the package behaves.
- Helpers: The classes in the src directory (e.g., Helper.php, RequestHelper.php, StringHelper.php) and utility traits (SingletonTrait) that provide common functionality.
- Middleware: In src/middleware (e.g., FilterRequestForApi, LogQueryForApi). These are added to the Laravel API group to filter and log requests.
- Commands: Under src/command (such as AutoDeployMultiServer and BackupDatabase). These are invoked via Artisan commands in Laravel for automated deployment or database backup.
- Eloquent Integration: The package extends Eloquent via the BaseModel and BaseModelMongoDB in src/eloquent. These are used to register and enhance Model behavior when combined with provided API-based querying.
- Exceptions: Classes in src/exceptions (Handler and SendLog) which work to log or handle exceptions (for instance, sending logs to Slack).
- Jobs: Jobs like SendMessageToSlack in src/jobs, used to queue log notifications and integrate with external services like Slack.
- Additional Components: Other utilities such as “casts” (PathCast.php) which might transform data types.

##### Out Component Relationships and Interactions
- The Service Provider loads configuration settings from config/helper.php and binds helper classes and middleware.
- The Helpers (e.g., Helper.php, RequestHelper.php) become the central point of processing API parameters, retrieving fields, and applying filters. Connect “Middleware” with “Helpers” to show that they work in tandem.
- The Extended Eloquent Models (BaseModel) and the additional relationship declarations in models help process query conditions, sorting, full-text search capabilities, and parameterized requests. Show a connection between “Eloquent Models” and “Helpers” (as they call BaseApiRequest) as well as “Middleware” and “Jobs.”

##### Architectural Patterns and Design Principles
- Modularity: Each folder (commands, helpers, middleware, exceptions, jobs, etc.) represents a modular slice that addresses a specific responsibility.
- Dependency Injection and Service Provider: The integration via the Service Provider shows adherence to Laravel’s dependency injection and service container principles.
- Extensibility: The pattern for extending Eloquent Models and using traits (SingletonTrait) makes this package easily extendable.
- Separation of Concerns: Distinct components for configuration, request filtering, logging, and background processing are clearly separated.

##### Relevant Technologies and Frameworks
- Laravel Framework: The package is specifically built for Laravel.
- Composer: Package management (composer.json).
- Artisan: Command line interface for running tasks.
- PHP: The core language used.
- External Services: Slack integration for logging (via Jobs and config settings).
- System Commands: Usage of system commands (mysqldump, zip) in the backup command.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Laravel Application"):::laravel

    subgraph "Laravel Integration"
        B("Service Provider - HelperServiceProvider"):::integration
        C("Configuration - helper.php"):::integration
    end

    subgraph "Middleware Layer"
        E("Middleware - FilterRequestForApi"):::middleware
        F("Middleware - LogQueryForApi"):::middleware
    end

    subgraph "Business Logic"
        D("Helpers - Helper, RequestHelper, StringHelper, SingletonTrait"):::business
        I("Eloquent Extension - BaseModel"):::business
        J("Eloquent Extension - BaseModelMongoDB"):::business
        N("Utility - PathCast"):::business
    end

    subgraph "Operational Tools"
        G("Command - AutoDeployMultiServer"):::operations
        H("Command - BackupDatabase"):::operations
        M("Job - SendMessageToSlack"):::operations
    end

    subgraph "Exception Handling"
        K("Exception Handler - Handler"):::exceptions
        L("Exception Logger - SendLog"):::exceptions
    end

    S("Slack (External)"):::external

    A -->|"loads"| B
    B -->|"loads_config"| C
    B -->|"binds_helpers"| D
    B -->|"registers_middleware"| E
    B -->|"registers_middleware"| F
    E -->|"processes_API"| D
    F -->|"logs_API"| D
    D -->|"integrates"| I
    D -->|"integrates"| J
    D -->|"utilizes"| N
    G -->|"uses_config"| C
    H -->|"uses_config"| C
    K -->|"handles_exceptions"| L
    L -->|"triggers_job"| M
    M -->|"notifies"| S

    click B "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/providers/HelperServiceProvider.php"
    click C "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/config/helper.php"
    click D "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/Helper.php"
    click E "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/middleware/FilterRequestForApi.php"
    click F "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/middleware/LogQueryForApi.php"
    click G "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/command/AutoDeployMultiServer.php"
    click H "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/command/BackupDatabase.php"
    click I "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/eloquent/BaseModel.php"
    click J "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/eloquent/BaseModelMongoDB.php"
    click K "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/exceptions/Handler.php"
    click L "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/exceptions/SendLog.php"
    click M "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/jobs/SendMessageToSlack.php"
    click N "https://github.com/minhngoc2512/laravel-helpers/blob/master/src/casts/PathCast.php"

    classDef laravel fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef integration fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef middleware fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef business fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef operations fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
    classDef exceptions fill:#f9e6ff,stroke:#9933cc,stroke-width:2px;
    classDef external fill:#e6e6e6,stroke:#666666,stroke-width:2px;
```
