# omaralalwi/lexi-translate architecture

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

- Interactive diagram: https://gitdiagram.com/omaralalwi/lexi-translate
- Repository: https://github.com/omaralalwi/lexi-translate

## Overview

##### Main components
- Configuration & Setup: Represent the configuration file (located in the “config” directory) which developers can publish and customize. Also include the migration files under “database/migrations” that set up the translations table(s) for persistent storage.
- Core Business Logic: Include the core classes and files from the “src” directory. Highlight the primary classes like LexiTranslate, its Facade, and the Service Provider. Also capture supporting parts such as helper functions (src/helpers.php) and Enums.
- Translation Model and Traits: Emphasize the Translation model along with traits (LexiTranslatable, HasCache, HasLocale) that enable translation features on models. This component represents how translations are attached to the application's business entities.
- Testing Suite: Acknowledge the “tests” folder which supports both feature and unit tests, helping maintain system reliability.

##### Relationships and interactions
- Service Provider Role: Show that the LexiTranslateServiceProvider registers the package with Laravel. It loads configurations, publishes migrations, and registers its middleware.
- Facade and Helper Functions: Indicate how the LexiTranslateFacade abstracts core functionalities, allowing simpler calls from the application.

##### Architectural patterns and design principles
- Service Provider Pattern: Illustrates the integration into the Laravel ecosystem.
- Facade Pattern: Simplifies the API consumption for end-users.
- Trait-Based Composition: Enables reusability of behaviors (caching, locale management, translatable properties) without deep inheritance hierarchies.
- Model Relationships: Use of polymorphic (morph) relationships to link translations dynamically to various models.
- Caching Strategy: Automatically refreshing the cache upon updates using the traits in the Translation model.

##### Relevant technologies and frameworks
- Laravel: The underlying framework; show its integration with the service provider, middleware, and Eloquent ORM.
- PHP & Composer: The package manager (composer.json) and PHP language are central to the project.
- Database: Laravel migrations (MySQL, PostgreSQL, etc.) for setting up the translation tables.
- Middleware components: For API and web locale switching, highlighting the strategic flow of request handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Laravel Application
    LA["Laravel Application"]:::laravel

    %% Configuration & Setup
    subgraph "Configuration & Setup"
        CF["Config File"]:::config
        subgraph "Migrations"
            M1["Migration: create_translations_table"]:::config
            M2["Migration: create_lexi_translate_posts_table"]:::config
        end
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        LT["LexiTranslate Core"]:::core
        FAC["LexiTranslate Facade"]:::core
        SP["Service Provider"]:::core
        HF["Helper Functions"]:::core
        LE["Language Enum"]:::core
    end

    %% Translation Model & Traits
    subgraph "Translation Model & Traits"
        TM["Translation Model"]:::model
        LTT["LexiTranslatable Trait"]:::model
        HCT["HasCache Trait"]:::model
        HLT["HasLocale Trait"]:::model
        EM["Eloquent Model (with LexiTranslatable)"]:::model
    end

    %% Locale Middleware
    subgraph "Locale Middleware"
        WL["WebLocalized Middleware"]:::middleware
        AL["ApiLocalized Middleware"]:::middleware
    end

    %% Testing Suite
    subgraph "Testing Suite"
        TEST["Tests Suite"]:::testing
    end

    %% Relationships
    CF -->|"loadsConfig"| SP
    SP -->|"publishes"| M1
    SP -->|"publishes"| M2
    LT -->|"abstracts"| FAC
    FAC -->|"calls"| HF
    LE -->|"definesLocale"| TM
    LTT -->|"enables"| EM
    EM -->|"morphsTo"| TM
    HCT -->|"composes"| TM
    HLT -->|"composes"| TM
    SP -->|"registers"| WL
    SP -->|"registers"| AL
    LA -->|"handles"| WL
    LA -->|"handles"| AL
    LA -->|"integrates"| SP
    TEST -->|"tests"| SP
    TEST -->|"tests"| TM
    TEST -->|"tests"| WL

    %% Styling classes
    classDef config fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef core fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef middleware fill:#FADBD8,stroke:#922B21,stroke-width:2px;
    classDef testing fill:#F5CBA7,stroke:#6E2C00,stroke-width:2px;
    classDef laravel fill:#D7BDE2,stroke:#512E5F,stroke-width:2px;

    %% Click Events
    click CF "https://github.com/omaralalwi/lexi-translate/blob/master/config/config.php"
    click M1 "https://github.com/omaralalwi/lexi-translate/blob/master/database/migrations/2023_07_10_002012_create_translations_table.php"
    click M2 "https://github.com/omaralalwi/lexi-translate/blob/master/database/migrations/2024_10_18_000000_create_lexi_translate_posts_table.php"
    click LT "https://github.com/omaralalwi/lexi-translate/blob/master/src/LexiTranslate.php"
    click FAC "https://github.com/omaralalwi/lexi-translate/blob/master/src/LexiTranslateFacade.php"
    click SP "https://github.com/omaralalwi/lexi-translate/blob/master/src/LexiTranslateServiceProvider.php"
    click HF "https://github.com/omaralalwi/lexi-translate/blob/master/src/helpers.php"
    click LE "https://github.com/omaralalwi/lexi-translate/blob/master/src/Enums/Language.php"
    click TM "https://github.com/omaralalwi/lexi-translate/blob/master/src/Models/Translation.php"
    click LTT "https://github.com/omaralalwi/lexi-translate/blob/master/src/Traits/LexiTranslatable.php"
    click HCT "https://github.com/omaralalwi/lexi-translate/blob/master/src/Traits/HasCache.php"
    click HLT "https://github.com/omaralalwi/lexi-translate/blob/master/src/Traits/HasLocale.php"
    click WL "https://github.com/omaralalwi/lexi-translate/blob/master/src/Middleware/WebLocalized.php"
    click AL "https://github.com/omaralalwi/lexi-translate/blob/master/src/Middleware/ApiLocalized.php"
    click TEST "https://github.com/omaralalwi/lexi-translate/tree/master/tests"
```
