# lmarcho/azbow-home-connect-crm architecture

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

- Interactive diagram: https://gitdiagram.com/lmarcho/azbow-home-connect-crm
- Repository: https://github.com/lmarcho/azbow-home-connect-crm

## Overview

##### Main Components
- API Gateway & HTTP Layer: At the “public/index.php” level that kicks off the Laravel Application.
- Controllers: Found in “app/Http/Controllers” (e.g., AuthController, LeadController, ReservationController, PropertyController) to handle incoming requests.
- Middleware: In “app/Http/Middleware” (e.g., Authenticate, VerifyCsrfToken, RoleMiddleware) for processing authentication, authorization, and request conditioning.
- Models: Under “app/Models” (Lead, LeadStatusLog, Property, Reservation, User) representing the business entities.
- Database & Migrations: Managed via “database/migrations” and “database/seeders” to define and initialize the database structure.
- Authentication: Utilizes Laravel Sanctum for token-based user authentication.
- Routing: Routes defined in “routes/api.php”, “routes/web.php”, etc., to map endpoints to controllers.
- Testing: Unit and feature tests under “tests” ensure API behavior and business logic.

##### Relationships & Data Flow
- Clients (such as Postman, mobile apps, or other frontend interfaces) make HTTP requests.
- Requests hit the entry point in “public/index.php” and flow through the Laravel HTTP kernel, passing various middleware (authentication, role check, CSRF protection, etc.).
- Depending on the endpoint, a controller (for example, LeadController for lead-related actions) is invoked.
- Controllers interact with Models, which reflect the database’s state (MySQL) and invoke business logic.
- The responses are then sent back to the client.
- Alongside, authentication endpoints (register and login) issue tokens to secure further requests.

##### Architectural Patterns and Design Principles
- MVC Pattern: Controllers handle incoming requests, Models represent data, and views are used minimally (mostly for API documentation provided in views and via Postman URL).
- RESTful API Design: Each resource (leads, reservations, properties) follows distinct CRUD endpoints. Emphasize separation of concerns.
- Middleware and Service Providers: Separate cross-cutting concerns such as authentication and logging.
- Environment Based Configuration: Settings are controlled with environment files (.env) and override defaults via config files.

##### Detail the Technologies, Frameworks, and Libraries
- Language and Framework: Laravel 10 with PHP (version 8.2+).
- Database: MySQL (configured via “config/database.php” and migrations).
- Authentication: Laravel Sanctum for API token handling.
- Tools: Composer for dependency management, PHPUnit for testing, and Postman collection for API testing.
- Frontend Assets: Although minimal, resources such as “resources/js/app.js” and “resources/css/app.css” exist.

- Clear Labels: Each component—API Gateway, Controllers, Middleware, Models, Database—should be clearly labeled.
- From the Client to the API Gateway.
- From the API Gateway through Middleware to Controllers.
- From Controllers to Models and then to the Database, as well as back.
- Token-based requests through third-party authentication.
- Web entry points (e.g., circle for index.php).
- Controllers and Middleware (rectangles with rounded corners).

##### Capturing Essential Architectural Elements
- Provide detail without overcomplicating: Ensure every component that processes or transforms data in the system is represented.
- Role separation (Admin vs. Sales Agent) where applicable, especially in the Middleware and Controller interactions.
- Dependency paths: For example, how authentication endpoints give back tokens used in header validations by RoleMiddleware, which then gate access to controllers.
- Configuration and integration points (e.g., config files, environment variables, and external dependencies such as the MySQL database).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        C("Clients"):::client
    end

    %% API Layer
    subgraph "API Layer"
        A("API Gateway"):::api
        subgraph "Routing"
            R1("API Routes"):::routing
            R2("Web Routes"):::routing
        end
        S("Sanctum Config"):::auth
        MW("Middleware"):::middleware
        CT("Controllers"):::controller
    end

    %% Business/Model Layer
    subgraph "Business/Model Layer"
        MD("Models"):::model
    end

    %% Data Layer
    subgraph "Data Layer"
        DB("MySQL Database"):::database
    end

    %% Testing Layer
    subgraph "Testing"
        TS("Tests"):::testing
    end

    %% Flow Connections
    C -->|"HTTP_Request"| A
    A -->|"Map_Routes"| R1
    R1 -->|"Map_Routes"| R2
    R2 -->|"Pass_Request"| MW
    S -->|"Auth_Config"| MW
    MW -->|"Invoke"| CT
    CT -->|"Business_Logic"| MD
    MD -->|"Data_Operations"| DB
    DB -->|"Return_Data"| MD
    MD -->|"Return_Data"| CT
    CT -->|"Prepare_Response"| MW
    MW -->|"Response_Pipeline"| R2
    R2 -->|"Response_Map"| R1
    R1 -->|"Convey_Response"| A
    A -->|"HTTP_Response"| C

    TS -->|"Test_Controllers"| CT
    TS -->|"Test_Models"| MD

    %% Click Events
    click A "https://github.com/lmarcho/azbow-home-connect-crm/blob/main/public/index.php"
    click CT "https://github.com/lmarcho/azbow-home-connect-crm/tree/main/app/Http/Controllers/"
    click MW "https://github.com/lmarcho/azbow-home-connect-crm/tree/main/app/Http/Middleware/"
    click MD "https://github.com/lmarcho/azbow-home-connect-crm/tree/main/app/Models/"
    click DB "https://github.com/lmarcho/azbow-home-connect-crm/tree/main/database/migrations/"
    click S "https://github.com/lmarcho/azbow-home-connect-crm/blob/main/config/sanctum.php"
    click R1 "https://github.com/lmarcho/azbow-home-connect-crm/blob/main/routes/api.php"
    click R2 "https://github.com/lmarcho/azbow-home-connect-crm/blob/main/routes/web.php"
    click TS "https://github.com/lmarcho/azbow-home-connect-crm/tree/main/tests/"

    %% Styles
    classDef client fill:#ffcccc,stroke:#900,stroke-width:2px;
    classDef api fill:#ccffcc,stroke:#090,stroke-width:2px;
    classDef routing fill:#ccccff,stroke:#006,stroke-width:2px;
    classDef auth fill:#d9e8c6,stroke:#597,stroke-width:2px;
    classDef middleware fill:#ffffcc,stroke:#996,stroke-width:2px;
    classDef controller fill:#ffcc99,stroke:#963,stroke-width:2px;
    classDef model fill:#cce5ff,stroke:#369,stroke-width:2px;
    classDef database fill:#e5ccff,stroke:#639,stroke-width:2px;
    classDef testing fill:#d9d9d9,stroke:#777,stroke-width:2px;
```
