# mrpunyapal/basic-crud architecture

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

- Interactive diagram: https://gitdiagram.com/mrpunyapal/basic-crud
- Repository: https://github.com/mrpunyapal/basic-crud

## Overview

##### Project Type and Purpose
- The project is a Laravel-based full-stack CRUD application that demonstrates best practices for building and testing CRUD functionalities.
- Its purpose is to show different actions (create, update, delete, toggle featured) applied to posts, as well as support multiple languages and a separation between API and web controllers.
- The README and file tree indicate a strong emphasis on testing, code quality (Pint, Rector, PHPStan), and deployment practices (local development and Docker/Sail support).

##### Break Down the File Structure into Architectural Components
- Frontend / Presentation Layer:
- Resources & Public: Look at resources/views (Blade templates for posts and general layout), resources/js and resources/css (for client-side interactivity and styling) and public folder (static assets and the entry point via public/index.php).
- HTTP and Routing Layer:
- Routes: files in the routes folder (api.php, web.php, console.php). These define how the requests are routed.
- Controllers: In app/Http/Controllers – separate controllers for API (e.g., Api/PostController) and web (e.g., PostController, FeaturedPostController, LocaleController) which handle incoming requests and responses.
- Middleware: e.g., app/Http/Middleware/SetLocale to manage locale settings.
- Application / Business Logic Layer:
- Actions: In app/Actions/Posts, there are dedicated classes for business operations such as CreatePostAction, DeletePostAction, UpdatePostAction, TogglePostFeatureAction.
- Requests: In app/Http/Requests, the StorePostRequest and UpdatePostRequest define request data validations.
- Builders and Enums: For instance, the PostBuilder and enums (e.g., FeaturedStatus, PostSortColumnsEnum) encapsulate domain-specific logic.
- Domain & Data Layer:
- Models: Under app/Models, these include Post, Category, and User representing the core entities.
- Database: Migrations, seeders, and factories under the database directory to structure and seed the database.
- Infrastructure and Support:
- Providers: app/Providers/AppServiceProvider and related config files under the config folder (including caching, sessions, mail, logging, etc.).
- Support classes & Traits: e.g., FileUploaderFromUrl, QueryResolver, Settings and the trait HasFileFromUrl for utility functions.
- Testing and Quality Assurance:
- Unit and Feature Tests: Under tests/ directory, tests cover both HTTP controllers and internal business logic in Actions.
- Tools and Configurations: Composer scripts, PHPStan for static analysis, Rector for automated refactoring, and Laravel Sail (with docker-compose.yml) for containerized development.

##### Relationships and Data Flow
- Browser client reaching public/index.php and rendering Blade templates.
- Data flow from client-side JavaScript and forms to HTTP Routes.
- HTTP Layer Connection:
- That HTTP requests pass through middleware (e.g., SetLocale) before reaching controllers.
- Application Layer Interaction:
- Domain Layer and Persistence:
- Models (e.g., Post, Category, User) as nodes that interact with the database.
- Migrations, seeders, and factories as tools to set up and maintain the database schema.
- Infrastructure and Support:
- Testing Environment:
- A separate portion or annotation that covers the testing stack (PHPUnit, Pest tests) verifying that the system design is well separated and robust.

##### Architectural Patterns and Technologies
- Employ the MVC pattern inherent in Laravel:
- Model: Represents your domain entities.
- View: Defined by Blade templates and public resources.
- Controller/Actions: Handling business logic and HTTP requests.
- Separation of concerns, from request handling and validations (Requests, Middleware) to business operations (Actions) and data integrity (Models & Migrations).
- Important technologies:
- PHP (Laravel Framework)
- JavaScript (with Vite for front-end asset compilation)
- Testing frameworks and static analysis tools (PHPUnit, Pest, PHPStan, Rector)
- Docker/Sail for containerized development

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level User
    U["User"]:::user

    %% Frontend / Presentation Layer
    subgraph "Frontend / Presentation Layer"
        FT1["Blade Templates"]:::frontend
        FT2["Client-side Assets (JS)"]:::frontend
        FT3["Client-side Assets (CSS)"]:::frontend
        FT4["Public Entry (index.php)"]:::frontend
        FT5["Public Theme Assets"]:::frontend
    end

    %% HTTP and Routing Layer
    subgraph "HTTP and Routing Layer"
        subgraph "Routes"
            R_api["api.php"]:::http
            R_web["web.php"]:::http
            R_console["console.php"]:::http
        end
        MW["Middleware (SetLocale)"]:::http
        subgraph "Controllers"
            APIC["API: PostController"]:::http
            WEBC1["Web: PostController"]:::http
            WEBC2["FeaturedPostController"]:::http
            WEBC3["LocaleController"]:::http
        end
    end

    %% Application / Business Logic Layer
    subgraph "Application / Business Logic Layer"
        subgraph "Actions"
            A1["CreatePostAction"]:::bizlogic
            A2["UpdatePostAction"]:::bizlogic
            A3["DeletePostAction"]:::bizlogic
            A4["TogglePostFeatureAction"]:::bizlogic
        end
        subgraph "Request Validations"
            RV1["StorePostRequest"]:::bizlogic
            RV2["UpdatePostRequest"]:::bizlogic
        end
        subgraph "Builders & Enums"
            B1["PostBuilder"]:::bizlogic
            E1["FeaturedStatus"]:::bizlogic
            E2["PostSortColumnsEnum"]:::bizlogic
        end
    end

    %% Domain & Data Layer
    subgraph "Domain & Data Layer"
        subgraph "Models"
            M1["Post"]:::domain
            M2["Category"]:::domain
            M3["User"]:::domain
        end
        subgraph "Database"
            DB1["Migrations"]:::domain
            DB2["Factories"]:::domain
            DB3["Seeders"]:::domain
        end
    end

    %% Infrastructure and Support
    subgraph "Infrastructure & Support"
        SP["Service Providers"]:::infra
        CF["Configurations"]:::infra
        SU1["FileUploaderFromUrl"]:::infra
        SU2["QueryResolver"]:::infra
        SU3["Settings"]:::infra
        TR["Traits: HasFileFromUrl"]:::infra
    end

    %% Testing and Quality Assurance
    subgraph "Testing & QA"
        FTST["Feature Tests"]:::testing
        CTST["HTTP Controllers Tests"]:::testing
        UTST["Unit Tests"]:::testing
        TOOL["Quality Tools (phpunit.xml, phpstan.neon, pint.json, rector.php, Pest)"]:::testing
    end

    %% Data Flow Connections
    U -->|"request"| FT4
    FT4 -->|"routes"| R_api
    FT4 -->|"routes"| R_web
    FT4 -->|"routes"| R_console
    R_api --> MW
    R_web --> MW
    R_console --> MW
    MW --> APIC
    MW --> WEBC1
    MW --> WEBC2
    MW --> WEBC3

    %% Controllers call Business Logic actions (illustrative mapping)
    APIC -->|"create"| A1
    WEBC1 -->|"update"| A2
    WEBC2 -->|"delete"| A3
    WEBC3 -->|"toggle"| A4

    %% Actions trigger validations and use builders/enums
    A1 --> RV1
    A2 --> RV2
    A1 --> B1
    A2 --> B1
    A3 --> B1
    A4 --> B1
    B1 --> E1
    B1 --> E2

    %% Business Logic interacts with Domain models
    B1 --> M1
    B1 --> M2
    B1 --> M3
    M1 --> DB1
    M1 --> DB2
    M1 --> DB3

    %% Infrastructure supports various layers (bootstrap & utilities)
    SP --- APIC
    SP --- WEBC1
    SP --- WEBC2
    SP --- WEBC3
    CF --- SP
    SU1 --- SP
    SU2 --- SP
    SU3 --- SP
    TR --- SU1

    %% Testing touches Controllers and Business Logic
    APIC --- FTST
    WEBC1 --- CTST
    A1 --- UTST
    B1 --- TOOL

    %% Click Events for Frontend / Presentation Layer
    click FT1 "https://github.com/mrpunyapal/basic-crud/tree/main/resources/views"
    click FT2 "https://github.com/mrpunyapal/basic-crud/tree/main/resources/js"
    click FT3 "https://github.com/mrpunyapal/basic-crud/tree/main/resources/css"
    click FT4 "https://github.com/mrpunyapal/basic-crud/blob/main/public/index.php"
    click FT5 "https://github.com/mrpunyapal/basic-crud/tree/main/public/theme"

    %% Click Events for HTTP and Routing Layer
    click R_api "https://github.com/mrpunyapal/basic-crud/blob/main/routes/api.php"
    click R_web "https://github.com/mrpunyapal/basic-crud/blob/main/routes/web.php"
    click R_console "https://github.com/mrpunyapal/basic-crud/blob/main/routes/console.php"
    click MW "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Middleware/SetLocale.php"
    click APIC "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Controllers/Api/PostController.php"
    click WEBC1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Controllers/PostController.php"
    click WEBC2 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Controllers/FeaturedPostController.php"
    click WEBC3 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Controllers/LocaleController.php"

    %% Click Events for Application / Business Logic Layer
    click A1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Actions/Posts/CreatePostAction.php"
    click A2 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Actions/Posts/UpdatePostAction.php"
    click A3 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Actions/Posts/DeletePostAction.php"
    click A4 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Actions/Posts/TogglePostFeatureAction.php"
    click RV1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Requests/StorePostRequest.php"
    click RV2 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Http/Requests/UpdatePostRequest.php"
    click B1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Builders/PostBuilder.php"
    click E1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Enums/FeaturedStatus.php"
    click E2 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Enums/PostSortColumnsEnum.php"

    %% Click Events for Domain & Data Layer
    click M1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Models/Post.php"
    click M2 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Models/Category.php"
    click M3 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Models/User.php"
    click DB1 "https://github.com/mrpunyapal/basic-crud/tree/main/database/migrations"
    click DB2 "https://github.com/mrpunyapal/basic-crud/tree/main/database/factories"
    click DB3 "https://github.com/mrpunyapal/basic-crud/tree/main/database/seeders"

    %% Click Events for Infrastructure and Support
    click SP "https://github.com/mrpunyapal/basic-crud/blob/main/app/Providers/AppServiceProvider.php"
    click CF "https://github.com/mrpunyapal/basic-crud/tree/main/config/"
    click SU1 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Support/FileUploaderFromUrl.php"
    click SU2 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Support/QueryResolver.php"
    click SU3 "https://github.com/mrpunyapal/basic-crud/blob/main/app/Support/Settings.php"
    click TR "https://github.com/mrpunyapal/basic-crud/blob/main/app/Traits/HasFileFromUrl.php"

    %% Click Events for Testing and Quality Assurance
    click FTST "https://github.com/mrpunyapal/basic-crud/tree/main/tests/Feature"
    click CTST "https://github.com/mrpunyapal/basic-crud/tree/main/tests/Feature/Http/Controllers"
    click UTST "https://github.com/mrpunyapal/basic-crud/tree/main/tests/Unit"
    click TOOL "https://github.com/mrpunyapal/basic-crud/blob/main/phpunit.xml"

    %% Styles
    classDef user fill:#ffeb3b,stroke:#333,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef http fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef bizlogic fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    classDef domain fill:#FADBD8,stroke:#922B21,stroke-width:2px;
    classDef infra fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef testing fill:#F5CBA7,stroke:#A04000,stroke-width:2px;
```
