# sprorowski/clean-architecture-laravel architecture

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

- Interactive diagram: https://gitdiagram.com/sprorowski/clean-architecture-laravel
- Repository: https://github.com/sprorowski/clean-architecture-laravel

## Overview

##### Main Architecture Overview

a. Domain Layer (Core)
b. Application Layer
c. Infrastructure Layer
d. Presenter Layer (Framework)

##### Detailed Component Breakdown

For each layer, include the following components:

Domain Layer:
- User Entity (User.php)
- Users Repository Interface (Users.php)
- Domain Exceptions

Application Layer:
- Command/Query buses
- Use Cases:
- User Creation
- User Login
- User Loading

Infrastructure Layer:
- Database implementations (EloquentUsers)
- External service integrations

Presenter Layer:
- HTTP Controllers
- Console Commands
- Middleware
- Route definitions
- Service Providers

##### Flow Representation

a. External Request Flow:
**HTTP Request → Presenter → Application → Domain → Infrastructure → Database**

b. Response Flow:
**Database → Infrastructure → Domain → Application → Presenter → HTTP Response**

##### Component Relationships

- Controllers and their corresponding Command/Query handlers
- Command/Query handlers and Domain entities
- Repository interfaces and their implementations

##### Specific Implementation Details

- Laravel-specific components (Eloquent, Middleware, Providers)
- Custom implementations (Commands, Queries, Handlers)
- Database layer (MySQL/PostgreSQL)

##### Additional Elements

Sections for:
- Authentication flow
- API versioning (v1)
- Testing architecture
- Service provider bindings

##### The relationship between concrete implementations and their interfaces

Key Guidelines:

##### Notes about important architectural decisions

Special Considerations:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "External Layer"
        Client(("Client"))
        DB[(Database)]
    end

    subgraph "Presenter Layer"
        direction TB
        Controllers["HTTP Controllers"]:::presenter
        Routes["API Routes"]:::presenter
        Middleware["Middleware"]:::presenter
        Providers["Service Providers"]:::presenter
        ExHandler["Exception Handler"]:::presenter
        ConsoleKernel["Console Kernel"]:::presenter
    end

    subgraph "Infrastructure Layer"
        direction TB
        EloquentUsers["Eloquent Users"]:::infra
        UserModel["User Model"]:::infra
    end

    subgraph "Application Layer"
        direction TB
        CommandBus["Command Bus"]:::application
        QueryBus["Query Bus"]:::application
        
        subgraph "Use Cases"
            direction TB
            CreateUser["Create User Command/Handler"]:::application
            LoginUser["Login User Command/Handler"]:::application
            LoadUser["Load User Query/Handler"]:::application
        end
    end

    subgraph "Domain Layer"
        direction TB
        UserEntity["User Entity"]:::domain
        UserRepo["Users Repository Interface"]:::domain
        DomainExceptions["Domain Exceptions"]:::domain
    end

    %% External Flow
    Client --> Controllers
    Controllers --> CommandBus & QueryBus
    CommandBus --> CreateUser & LoginUser
    QueryBus --> LoadUser
    CreateUser & LoginUser & LoadUser --> UserEntity
    UserEntity --> UserRepo
    UserRepo --> EloquentUsers
    EloquentUsers --> UserModel
    UserModel --> DB

    %% Component Relationships
    Controllers --> Routes
    Controllers --> Middleware
    Providers --> UserRepo
    EloquentUsers --> UserRepo

    %% Click Events
    click UserEntity "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Domain/User/User.php"
    click UserRepo "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Domain/User/Users.php"
    click DomainExceptions "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Domain/DomainException.php"
    click CommandBus "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Application/Command.php"
    click QueryBus "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Application/Query.php"
    click CreateUser "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Application/User/Create/CreateUserCommand.php"
    click LoginUser "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Application/User/Login/LoginUserCommand.php"
    click LoadUser "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Application/User/Load/LoadUserQuery.php"
    click EloquentUsers "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Infrastructure/Database/EloquentUsers.php"
    click UserModel "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Infrastructure/Database/Models/UserModel.php"
    click Controllers "https://github.com/Sprorowski/clean-architecture-laravel/tree/main/app/Presenter/Http/User"
    click Middleware "https://github.com/Sprorowski/clean-architecture-laravel/tree/main/app/Presenter/Http/Middleware"
    click Routes "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Presenter/Http/Routes/v1/user.php"
    click Providers "https://github.com/Sprorowski/clean-architecture-laravel/tree/main/app/Presenter/Providers"
    click ConsoleKernel "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Presenter/Console/Kernel.php"
    click ExHandler "https://github.com/Sprorowski/clean-architecture-laravel/blob/main/app/Presenter/Exceptions/Handler.php"

    %% Styling
    classDef domain fill:#ffcdd2,stroke:#c62828
    classDef application fill:#bbdefb,stroke:#1976d2
    classDef infra fill:#c8e6c9,stroke:#388e3c
    classDef presenter fill:#fff9c4,stroke:#f9a825

    %% Legend
    subgraph Legend
        DomainLegend["Domain Layer"]:::domain
        ApplicationLegend["Application Layer"]:::application
        InfraLegend["Infrastructure Layer"]:::infra
        PresenterLegend["Presenter Layer"]:::presenter
    end
```
