# wvx-qa-sonar-org/test-crm architecture

> Architecture diagram of the GitHub repository wvx-qa-sonar-org/test-crm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wvx-qa-sonar-org/test-crm
- Repository: https://github.com/wvx-qa-sonar-org/test-crm

## Overview

##### Main Components
- Frontend:
- Located in the "src" directory (with Vue.js components, router, store, assets, and services).
- Includes components for authentication (Login, Register), dashboard (Dashboard), ticket management (CreateTicket, TicketDetail, TicketsList) and a shared layout (Header, Sidebar).
- The entry point 'src/main.js' initializes the Vue application and the 'src/router/index.js' handles routes.
- The "public" directory provides static assets like the index.html page.
- Backend:
- Found in the "backend" directory, which contains an "api" folder for the PHP endpoints and a "src" folder for backend core PHP logic (e.g., Database.php).
- It utilizes Composer for dependency management (composer.json/lock files) and includes API files for user authentication and resource management (clients, tickets).
- Database:
- A MongoDB instance is used, with its initialization script in mongo-init.js and Docker configuration provided by docker-compose.yml.
- Integration and Deployment:
- The frontend accesses API endpoints via a URL defined in the .env file.
- The Docker setup (docker-compose.yml) assists with starting MongoDB, while the README explains how MongoDB Express UI may be used to monitor the database.

##### Relationships and Interactions
- The Vue.js frontend communicates with the backend API (hosted, for example, at http://localhost:8001) using RESTful calls.
- On successful authentication (handled by endpoints such as /api/login in the PHP backend), the frontend will access further endpoints for clients and tickets.
- The PHP backend interacts with MongoDB for data persistence, with the connection details set up via environment variables in the backend’s .env file.
- Docker is used to run MongoDB in a container, with instructions provided for verifying the connection via MongoDB Compass or Mongo Express.

##### Architectural Patterns and Design Principles
- The project demonstrates a clear separation of concerns, with the frontend and backend acting as distinct services communicating over HTTP.
- The Vue.js application follows an MVC-like structure with clear separation between components (views), services (controllers making API calls), and state management (store).
- The PHP backend organizes its API endpoints and business logic separately for ease of testing, maintenance, and potential scaling.
- Secure authentication is implemented using JWT, with configuration details provided in the .env files. CORS headers are set to allow frontend integration during development.

##### Relevant Technologies and Libraries
- Frontend: Vue.js 2, Vue Router, Vuex (state management), and possibly Axios (within services/api.js) for HTTP requests.
- Backend: PHP, Composer-managed libraries, and MongoDB PHP extension to interact with the database.
- Database: MongoDB, with initialization managed via Docker (docker-compose.yml) and scripts like mongo-init.js.
- Development Tools: Node.js, npm, PHP’s built-in server for testing, and unit testing tools for both frontend ("npm run test:unit") and backend (PHPUnit).

##### Elements
- Use clear, descriptive labels for each component (e.g., “Vue.js Frontend”, “PHP API (backend)”, “MongoDB Container”).
- From the frontend to the backend API endpoints (e.g., API calls for Login, Clients, Tickets).
- Between backend and MongoDB to indicate CRUD operations.

##### Detailed Breakdown for the Principal Software Engineer
- Separate the system into three main blocks: Frontend, Backend, and Database.
- Expand each block with key sub-components:
- Under “Frontend”: highlight Vue components categorized by authentication, dashboard, and ticketing.
- Under “Backend”: explicitly list API endpoints (such as /api/login, /api/clients, /api/tickets) and supporting files (e.g., Database.php for MongoDB operations).
- Under “Database”: denote that MongoDB is hosted in a Docker container, and optionally note Mongo Express as an interface.
- You show configuration dependencies:
- .env files where API URLs and secrets are defined.
- Inclusion of Docker for MongoDB and that both the frontend and backend have distinct installation and running commands.
- Development vs. Production differences:
- Mention that the development setup includes CORS headers and Docker-based database management, while production deployment would require secure configurations (HTTPS, production JWT secret, serving static front-end files, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Vue CRM Frontend"
      FE_main["Entry (main.js)"]:::frontend
      FE_router["Router (index.js)"]:::frontend
      FE_app["App Component (App.vue)"]:::frontend
      
      subgraph "Components"
        subgraph "Authentication"
          FE_login["Login"]:::frontend
          FE_register["Register"]:::frontend
        end
        subgraph "Dashboard"
          FE_dashboard["Dashboard"]:::frontend
        end
        subgraph "Ticket Management"
          FE_createTicket["Create Ticket"]:::frontend
          FE_ticketDetail["Ticket Detail"]:::frontend
          FE_ticketsList["Tickets List"]:::frontend
        end
        subgraph "Shared Layout"
          FE_header["Header"]:::frontend
          FE_sidebar["Sidebar"]:::frontend
        end
        FE_static["Static Assets (index.html)"]:::frontend
      end
    end

    %% Backend Subgraph
    subgraph "PHP API Server"
      subgraph "API Endpoints"
        BE_api["API Directory"]:::backend
      end
      subgraph "Core Logic & Dependencies"
        BE_db["Database Connection (Database.php)"]:::backend
        BE_composer_json["Composer.json"]:::backend
        BE_composer_lock["Composer.lock"]:::backend
      end
    end

    %% Database Subgraph
    subgraph "MongoDB Container"
      DB_mongo["MongoDB"]:::database
      DB_init["Mongo Init Script"]:::database
      DB_docker["Docker Setup"]:::database
    end

    %% Connections between Frontend, Backend, and Database
    FE_app -->|"callsAPI"| BE_api
    BE_api -->|"CRUDoperations"| DB_mongo
    BE_db -->|"connectsTo"| DB_mongo

    %% Internal Frontend Flow
    FE_main --> FE_router
    FE_router --> FE_app
    FE_app --> FE_login
    FE_app --> FE_register
    FE_app --> FE_dashboard
    FE_app --> FE_createTicket
    FE_app --> FE_ticketDetail
    FE_app --> FE_ticketsList
    FE_app --> FE_header
    FE_app --> FE_sidebar
    FE_app --> FE_static

    %% Click Events - Frontend
    click FE_main "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/main.js"
    click FE_router "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/router/index.js"
    click FE_app "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/App.vue"
    click FE_login "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/auth/Login.vue"
    click FE_register "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/auth/Register.vue"
    click FE_dashboard "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/dashboard/Dashboard.vue"
    click FE_createTicket "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/tickets/CreateTicket.vue"
    click FE_ticketDetail "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/tickets/TicketDetail.vue"
    click FE_ticketsList "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/tickets/TicketsList.vue"
    click FE_header "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/layout/Header.vue"
    click FE_sidebar "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/src/components/layout/Sidebar.vue"
    click FE_static "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/public/index.html"

    %% Click Events - Backend
    click BE_api "https://github.com/wvx-qa-sonar-org/test-crm/tree/main/backend/api"
    click BE_db "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/backend/src/Database.php"
    click BE_composer_json "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/backend/composer.json"
    click BE_composer_lock "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/backend/composer.lock"

    %% Click Events - Database & Docker
    click DB_init "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/mongo-init.js"
    click DB_docker "https://github.com/wvx-qa-sonar-org/test-crm/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef database fill:#FFFACD,stroke:#FFA500,stroke-width:2px;
```
