# ronei-kunkel/larawater architecture

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

- Interactive diagram: https://gitdiagram.com/ronei-kunkel/larawater
- Repository: https://github.com/ronei-kunkel/larawater

## Overview

##### Project type and purpose
- Larawater is a backend‑driven, API‑first web application built with Laravel, implementing Clean Architecture and Domain‑Driven Design.
- Its purpose is to track and manage how many times a user drinks water, exposing endpoints for registration, authentication, recording drink events, and serving documentation via Swagger.

##### File structure
- Laravel core (app/, bootstrap/, config/, public/, resources/, routes/, storage/) provides the HTTP framework, middleware, routing, models, views and static assets.
- src/ holds the Clean‑Architecture modules:
- Common/ – shared types (Email, Password), exceptions, middleware (AuthMiddleware), services (Env, File, JWT).
- Module/Register, Module/Auth, Module/Drink – each follows the pattern:
– Application/Action – use‑case classes (e.g., UserRegister, UserAuth, UserDrink).
– Domain/Entity & Domain/Exception – business entities and domain‑specific errors.
– Infra/Controller – HTTP adapters exposing the use‑cases.
– Infra/Repository – data‑access adapters.
- Documentation – a module to expose documentation versions via HTTP controllers and pages.
- composer.json, package.json, vite.config.js: build tools, front‑end asset compilation.
- database/migrations, factories, seeders: persistence layer.
- public/swagger: static Swagger UI assets.

##### README
- Confirms a DDD + Clean Architecture approach.
- Core features: user registration, authentication, water‑drinking event logging, documentation management.

##### Essential details
- Environment config (.env), caching and file storage as auxiliary components.
- Custom Common/Infra/Middleware and Common/Infra/Service adapters as cross‑cutting concerns.
- Don’t omit the Postman collection or Swagger UI – show them as alternative API consumers for testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        ClientSPA["Web SPA / Mobile App"]:::external
        Postman["Postman Collection"]:::external
        SwaggerUI["Swagger UI"]:::external
    end

    %% HTTP Layer
    subgraph "Laravel HTTP Layer"
        RoutesAPI["routes/api.php"]:::presentation
        RoutesWeb["routes/web.php"]:::presentation
        Kernel["Kernel (app/Http/Kernel.php)"]:::presentation
        ControllerBase["Base Controller (app/Http/Controllers/Controller.php)"]:::presentation
        AuthMiddleware["AuthMiddleware"]:::presentation
    end

    %% Controllers
    subgraph "Presentation Layer (Controllers)" 
        URController["UserRegisterController"]:::presentation
        UAController["UserAuthController"]:::presentation
        UDController["UserDrinkController"]:::presentation
        DocShowController["ShowDocumentationController"]:::presentation
        DocRawController["RawDocumentationController"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        UserRegister["UserRegister"]:::application
        UserAuth["UserAuth"]:::application
        UserDrink["UserDrink"]:::application
        ListDocs["ListDocumentationVersions"]:::application
        ShowDocs["ShowDocumentation"]:::application
        RawDocs["RawDocumentation"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        UserEntityRegister["User Entity"]:::domain
        DrinkEntity["DrinkEvent Entity"]:::domain
        EmailVO["Email Value Object"]:::domain
        PasswordVO["Password Value Object"]:::domain
        DomainExceptions["Domain Exceptions"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        subgraph Repositories
            RegRepo["UserRegisterRepository"]:::infra
            AuthRepo["UserAuthRepository"]:::infra
            DrinkRepo["UserDrinkRepository"]:::infra
        end
        subgraph Services
            EnvService["EnvService"]:::infra
            FileService["FileService"]:::infra
            JWTService["JWTService"]:::infra
            PasswordService["PasswordService"]:::infra
        end
    end

    %% Storage & DB
    subgraph "Storage & DB"
        Database[(Relational DB)]:::storage
        FileStorage[(Filesystem)]:::storage
        Cache[(Cache/Session)]:::storage
    end

    %% Connections
    ClientSPA -->|calls REST API| RoutesAPI
    Postman -->|calls REST API| RoutesAPI
    ClientSPA -->|web routes| RoutesWeb
    ClientSPA -->|view docs| SwaggerUI

    RoutesAPI -->|for protected endpoints| AuthMiddleware
    RoutesAPI --> URController
    RoutesAPI --> UAController
    RoutesAPI --> UDController
    RoutesWeb --> DocShowController
    RoutesWeb --> DocRawController

    AuthMiddleware -->|validates JWT| JWTService

    URController -->|"calls"| UserRegister
    UAController -->|"calls"| UserAuth
    UDController -->|"calls"| UserDrink
    DocShowController -->|"calls"| ShowDocs
    DocRawController -->|"calls"| RawDocs
    ShowDocs -->|"lists"| ListDocs
    ListDocs -->|"reads files"| FileService

    UserRegister -->|uses| UserEntityRegister
    UserRegister -->|uses| EmailVO
    UserRegister -->|uses| PasswordVO
    UserRegister -->|handles errors| DomainExceptions
    UserAuth -->|uses| UserEntityRegister
    UserAuth -->|uses| PasswordVO
    UserAuth -->|handles errors| DomainExceptions
    UserDrink -->|uses| DrinkEntity
    UserDrink -->|handles errors| DomainExceptions

    UserRegister -->|persists| RegRepo
    UserAuth -->|persists| AuthRepo
    UserDrink -->|persists| DrinkRepo

    RegRepo -->|writes| Database
    AuthRepo -->|writes| Database
    DrinkRepo -->|writes| Database

    FileService -->|reads/writes| FileStorage
    Cache -->|stores sessions| AuthMiddleware
    EnvService -->|provides config| JWTService
    PasswordService -->|validates/hashes| PasswordVO

    %% Click Events
    click ClientSPA "https://github.com/ronei-kunkel/larawater/tree/production/N/A"
    click Postman "https://github.com/ronei-kunkel/larawater/tree/production/collection/"
    click SwaggerUI "https://github.com/ronei-kunkel/larawater/tree/production/public/swagger"

    click RoutesAPI "https://github.com/ronei-kunkel/larawater/blob/production/routes/api.php"
    click RoutesWeb "https://github.com/ronei-kunkel/larawater/blob/production/routes/web.php"
    click Kernel "https://github.com/ronei-kunkel/larawater/blob/production/app/Http/Kernel.php"
    click ControllerBase "https://github.com/ronei-kunkel/larawater/blob/production/app/Http/Controllers/Controller.php"
    click AuthMiddleware "https://github.com/ronei-kunkel/larawater/blob/production/src/Common/Infra/Middleware/AuthMiddleware.php"

    click URController "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Register/Infra/Controller/UserRegisterController.php"
    click UserRegister "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Register/Application/Action/UserRegister.php"
    click RegRepo "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Register/Infra/Repository/UserRegisterRepository.php"
    click UserEntityRegister "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Register/Domain/Entity/User.php"

    click UAController "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Auth/Infra/Controller/UserAuthController.php"
    click UserAuth "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Auth/Application/Action/UserAuth.php"
    click AuthRepo "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Auth/Infra/Repository/UserAuthRepository.php"
    click PasswordService "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Auth/Application/Service/PasswordService.php"

    click UDController "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Drink/Infra/Controller/UserDrinkController.php"
    click UserDrink "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Drink/Application/Action/UserDrink.php"
    click DrinkRepo "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Drink/Infra/Repository/UserDrinkRepository.php"
    click DrinkEntity "https://github.com/ronei-kunkel/larawater/blob/production/src/Module/Drink/Domain/Entity/User.php"

    click EnvService "https://github.com/ronei-kunkel/larawater/blob/production/src/Common/Infra/Service/EnvService.php"
    click FileService "https://github.com/ronei-kunkel/larawater/blob/production/src/Common/Infra/Service/FileService.php"
    click JWTService "https://github.com/ronei-kunkel/larawater/blob/production/src/Common/Infra/Service/JWTService.php"
    click EmailVO "https://github.com/ronei-kunkel/larawater/blob/production/src/Common/Domain/Type/Email.php"
    click PasswordVO "https://github.com/ronei-kunkel/larawater/blob/production/src/Common/Domain/Type/Password.php"

    %% Styles
    classDef presentation fill:#E3F2FD,stroke:#90CAF9
    classDef application fill:#E8F5E9,stroke:#A5D6A7
    classDef domain fill:#FFF3E0,stroke:#FFCC80
    classDef infra fill:#F3E5F5,stroke:#CE93D8
    classDef external fill:#FFEBEE,stroke:#EF9A9A
    classDef storage fill:#ECEFF1,stroke:#B0BEC5
```
