# jesterjz/crm-project-test architecture

> Architecture diagram of the GitHub repository jesterjz/crm-project-test, 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/jesterjz/crm-project-test
- Repository: https://github.com/jesterjz/crm-project-test

## Overview

##### Main Components
a. Container Infrastructure:
- Laradock Containers – Highlight the key containers being used:
- Nginx (web server, serving the application through the public/index.php entry point)
- MySQL (database server storing application data; note the detailed migrations and seeding)
- PHP Workspace (hosts the Laravel application and CLI tasks)
- Elasticsearch (for indexing contacts as seen in the “import:contacts” command and ElasticsearchServiceProvider)
- phpMyAdmin (for database management)
- Docker Compose – Illustrate that these containers communicate on a single Docker network.
b. Laravel Backend Application:
- HTTP Layer:
- Controllers: Under backend/app/Http/Controllers/Api (the REST API endpoints for Authentication, Contacts, Opportunities, etc.)
- Middleware: Illustrate typical request handling (authentication, CSRF, etc.)
- Routes: Defined in backend/routes/api.php and web.php
- Business Logic Layer:
- Services: Such as ContactService (located in backend/app/Services) which encapsulate business logic.
- Traits: ElasticsearchTrait, Searchable for reusing behavior.
- Data Access Layer:
- Models: Representing entities like Contact, Opportunity, Task, etc.
- Migrations/Seeders: In backend/database, defining and populating the database schema.
- Console Commands:
- Custom artisan commands (like ImportContactsToElasticsearch) handling specialized tasks.
- Configuration:
- Config files (backend/config) and environment setups which define external integrations and global settings.
c. Supporting Components:
- Frontend Assets: Even though it is minimal (resources/js and resources/css), it’s part of the application.
- Docker Integration: .env.laradock, crm.conf and related configuration files used to wire the application to local domains and container settings.

##### Relationships and Interactions
- The Nginx container acts as a reverse proxy, routing incoming HTTP requests to the PHP container where the Laravel app logic resides.
- The Laravel backend processes the request using its MVC architecture:
- Controllers receive requests, interact with Services and Models, and then return responses.
- Database interactions occur via MySQL, orchestrated in Laravel’s Eloquent models and migrations.
- Data indexing and search functionalities are managed through Elasticsearch, as noted by the custom import command and corresponding service providers.
- docker-compose ties these separate containers together, maintaining network connectivity so that the application can seamlessly interact with MySQL, Elasticsearch, and even phpMyAdmin (for administrative tasks).

##### Architectural Patterns and Key Principles
- MVC Pattern: Emphasize the separation between Models (data), Views (currently simple Blade views), and Controllers (API endpoints).
- Service Layer Pattern: With services such as ContactService handling business logic independently.
- Containerization: Using Docker (via Laradock) to isolate different infrastructure components, making deployment and development consistent.
- Configuration Management: Environment specific settings (.env files and config files) manage sensitive and operational parameters.
- Dependency Management: Use of Composer for PHP dependencies and npm for frontend assets.
- Integration Points: Notably, the integration with Elasticsearch for search functionality and phpMyAdmin for database administration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client"]:::client

    %% Docker Compose & Config Node
    DC["Docker Compose & Config"]:::docker

    %% Container Infrastructure Subgraph
    subgraph "Docker Containers"
        Nginx["Nginx (Docker Container)"]:::docker
        PHPW["PHP Workspace (Laravel)"]:::docker
        MySQL["MySQL Database"]:::docker
        ES["Elasticsearch"]:::docker
        phpMyAdmin["phpMyAdmin"]:::docker
    end

    %% Laravel Application Internal Architecture
    subgraph "Laravel Application Architecture"
        %% HTTP Layer
        subgraph "HTTP Layer"
            Controllers["Controllers (backend/app/Http/Controllers/Api)"]:::laravel
            Middleware["Middleware (backend/app/Http/Middleware)"]:::laravel
            Routes["Routes (backend/routes/api.php & web.php)"]:::laravel
        end
        %% Business Logic & Services
        subgraph "Business Logic & Services"
            Services["ContactService (backend/app/Services)"]:::laravel
            Traits["Traits (ElasticsearchTrait, Searchable)"]:::laravel
        end
        %% Data Access Layer
        subgraph "Data Access Layer"
            Models["Models (backend/app/Models)"]:::laravel
            DBSetup["Migrations & Seeders (backend/database)"]:::laravel
        end
        %% Console Commands
        subgraph "Console Commands"
            Console["ImportContactsToElasticsearch (backend/app/Console/Commands)"]:::laravel
        end
        %% Frontend Assets
        subgraph "Frontend Assets"
            Assets["Assets (backend/resources/css & backend/resources/js)"]:::laravel
        end
    end

    %% Connections and Data Flows
    Client -->|"HTTP_Request"| Nginx
    DC --> Nginx
    DC --> PHPW
    DC --> MySQL
    DC --> ES
    DC --> phpMyAdmin

    Nginx -->|"forwards"| PHPW
    PHPW -->|"dispatches"| Controllers
    Controllers -->|"calls"| Services
    Controllers -->|"accesses"| Middleware
    Controllers -->|"routes via"| Routes
    Services -->|"queries/indexes"| ES
    Controllers -->|"DB operations"| Models
    Models -->|"reads/writes"| MySQL
    DBSetup -->|"configures"| MySQL
    phpMyAdmin -->|"manages"| MySQL
    Console -->|"runs indexing"| ES

    %% Class styles
    classDef docker fill:#aee1f9,stroke:#035,stroke-width:2px;
    classDef laravel fill:#c7f0bd,stroke:#076,stroke-width:2px;
    classDef client fill:#f9e1a9,stroke:#d67,stroke-width:2px;

    %% Click Events
    click DC "https://github.com/jesterjz/crm-project-test/blob/main/.env.laradock"
    click Nginx "https://github.com/jesterjz/crm-project-test/blob/main/crm.conf"
    click Nginx "https://github.com/jesterjz/crm-project-test/blob/main/backend/public/index.php"
    click PHPW "https://github.com/jesterjz/crm-project-test/tree/main/backend"
    click MySQL "https://github.com/jesterjz/crm-project-test/tree/main/backend/database/migrations"
    click ES "https://github.com/jesterjz/crm-project-test/blob/main/backend/config/elasticsearch.php"
    click Controllers "https://github.com/jesterjz/crm-project-test/tree/main/backend/app/Http/Controllers/Api"
    click Middleware "https://github.com/jesterjz/crm-project-test/tree/main/backend/app/Http/Middleware"
    click Routes "https://github.com/jesterjz/crm-project-test/blob/main/backend/routes/api.php"
    click Services "https://github.com/jesterjz/crm-project-test/blob/main/backend/app/Services/ContactService.php"
    click Traits "https://github.com/jesterjz/crm-project-test/blob/main/backend/app/Traits/ElasticsearchTrait.php"
    click Models "https://github.com/jesterjz/crm-project-test/tree/main/backend/app/Models"
    click DBSetup "https://github.com/jesterjz/crm-project-test/tree/main/backend/database/seeders"
    click Console "https://github.com/jesterjz/crm-project-test/blob/main/backend/app/Console/Commands/ImportContactsToElasticsearch.php"
    click Assets "https://github.com/jesterjz/crm-project-test/tree/main/backend/resources/js"
```
