# aaadityapal/connect architecture

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

- Interactive diagram: https://gitdiagram.com/aaadityapal/connect
- Repository: https://github.com/aaadityapal/connect

## Overview

##### Main Components
- Frontend/UI Layer: Capture pages like login.php, dashboards (admin_dashboard.php, employee_dashboard.php, manager_dash.php, etc.), and various HTML/CSS/JS resources (found under assets, css, js, modal_contents, etc.). Identify the templates and static assets that render the views.
- Backend/API Layer: Represent the core PHP scripts and API endpoints. The file tree shows many PHP scripts that handle user authentication (login.php, logout.php, auth_check.php), customer and sales data management (add_announcement.php, add_employee.php, add_project.php, etc.), and extensive API sub-folders (like api/, which contains endpoints for project/task management, file uploads, chat, etc.). Include also the business logic functions and utility functions (like functions.php and includes/).
- Database: Show the MySQL/MariaDB data store, with key tables such as users, customers, sales, tasks, documents, roles, and permissions (as outlined in the README and supported by SQL files in the file tree). Also note that SQL files are available for schema definitions and triggers.
- External Dependencies & Libraries: Include Composer (vendor/), and Node.js dependencies (package.json, package-lock.json) plus 3rd-party libraries like Bootstrap, jQuery, and TCPDF for PDF generation.
- File Storage: Represent the uploads directories for documents, profile images, and project files which are used for document management within the CRM.
- Web Server & Environment: Represent Apache/Nginx (with .htaccess in several folders) and environment configuration (.env, config files) that manage DB and server settings.

##### Relationships and Interactions
- The frontend communicates with the backend through form submissions, AJAX calls (handled by various ajax_handlers/ and assets/api/ endpoints), and through API endpoints (under api/).
- The backend interacts with the database for all CRUD operations (user management, customer data, sales, tasks, etc.) using configuration scripts found in config/, includes/ and api/config/.
- There is also file handling for uploads, document viewing (e.g., view_document.php, download.php), and chat functionality (websocket/ChatServer.php, chat-popup).

##### Key Architectural Patterns and Design Principles
- Layered Architecture: Separation between the presentation (HTML/CSS/JS), business logic (PHP scripts), and data persistence (MySQL).
- Role-based Access Control: Multiple PHP files implementing login, role checking, and user session handling (includes/auth_check.php, process_login.php, etc.).
- API-style Communication: Dedicated API endpoints (in the api/ folder) for operations like adding projects or tasks.
- Modular Components: Though many PHP files exist in the root, there are logical groupings (for example, HR components, project management, chat) that should be depicted as modules.
- Use of Standard Libraries: TCPDF for PDF generation and the composer-managed vendor libraries for external functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Web Server & Environment
    subgraph "Web Server & Environment"
        WS1[".htaccess"]:::server
        WS2["config.php"]:::server
        WS3["config/"]:::server
    end

    %% Frontend/UI Layer
    subgraph "Frontend/UI Layer"
        FE1["login.php"]:::frontend
        FE2["admin_dashboard.php"]:::frontend
        FE3["employee_dashboard.php"]:::frontend
        FE4["manager_dash.php"]:::frontend
        FE5["multi_role_dashboard.php"]:::frontend
        FE6["assets/"]:::frontend
        FE7["modal_contents/"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        BE1["login.php (backend)"]:::backend
        BE2["logout.php"]:::backend
        BE3["auth_check.php"]:::backend
        BE4["process_login.php"]:::backend
        BE5["functions.php"]:::backend
        BE6["includes/"]:::backend
        BE7["api/"]:::backend
    end

    %% Database (MySQL/MariaDB)
    subgraph "Database (MySQL/MariaDB)"
        DB1["main.sql"]:::database
        DB2["25.03.25.sql"]:::database
        DB3["2/4/25.sql"]:::database
        DB4["sql/"]:::database
        DB5["projects.sql"]:::database
        DB6["tasks.sql"]:::database
    end

    %% External Dependencies & Libraries
    subgraph "External Dependencies & Libraries"
        ED1["vendor/"]:::external
        ED2["composer.json"]:::external
        ED3["composer.lock"]:::external
        ED4["package.json"]:::external
        ED5["package-lock.json"]:::external
        ED6["tcpdf/"]:::external
    end

    %% File Storage
    subgraph "File Storage"
        FS1["uploads/"]:::storage
    end

    %% Connections
    WS1 --> FE1
    WS1 --> BE1
    FE1 -->|"HTTP_AJAX"| BE1
    FE1 -->|"loads"| FE6
    FE1 -->|"modal"| FE7
    BE1 --> BE3
    BE1 --> BE4
    BE4 -->|"CRUD"| DB1
    BE7 -->|"CRUD"| DB4
    BE7 -->|"FileOps"| FS1
    BE5 -->|"PDF"| ED6
    BE5 -->|"Uses"| ED1
    BE7 -->|"uses"| ED1
    BE7 -->|"uses"| ED2
    BE7 -->|"uses"| ED3
    BE7 -->|"uses"| ED4
    BE7 -->|"uses"| ED5

    %% Style Classes
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef storage fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef server fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events - Frontend/UI Layer
    click FE1 "https://github.com/aaadityapal/connect/blob/main/login.php"
    click FE2 "https://github.com/aaadityapal/connect/blob/main/admin_dashboard.php"
    click FE3 "https://github.com/aaadityapal/connect/blob/main/employee_dashboard.php"
    click FE4 "https://github.com/aaadityapal/connect/blob/main/manager_dash.php"
    click FE5 "https://github.com/aaadityapal/connect/blob/main/multi_role_dashboard.php"
    click FE6 "https://github.com/aaadityapal/connect/tree/main/assets/"
    click FE7 "https://github.com/aaadityapal/connect/tree/main/modal_contents/"

    %% Click Events - Backend/API Layer
    click BE1 "https://github.com/aaadityapal/connect/blob/main/login.php"
    click BE2 "https://github.com/aaadityapal/connect/blob/main/logout.php"
    click BE3 "https://github.com/aaadityapal/connect/blob/main/auth_check.php"
    click BE4 "https://github.com/aaadityapal/connect/blob/main/process_login.php"
    click BE5 "https://github.com/aaadityapal/connect/blob/main/functions.php"
    click BE6 "https://github.com/aaadityapal/connect/tree/main/includes/"
    click BE7 "https://github.com/aaadityapal/connect/tree/main/api/"

    %% Click Events - Database
    click DB1 "https://github.com/aaadityapal/connect/blob/main/main.sql"
    click DB2 "https://github.com/aaadityapal/connect/blob/main/25.03.25.sql"
    click DB3 "https://github.com/aaadityapal/connect/blob/main/2/4/25.sql"
    click DB4 "https://github.com/aaadityapal/connect/tree/main/sql/"
    click DB5 "https://github.com/aaadityapal/connect/blob/main/projects.sql"
    click DB6 "https://github.com/aaadityapal/connect/blob/main/tasks.sql"

    %% Click Events - External Dependencies & Libraries
    click ED1 "https://github.com/aaadityapal/connect/tree/main/vendor/"
    click ED2 "https://github.com/aaadityapal/connect/blob/main/composer.json"
    click ED3 "https://github.com/aaadityapal/connect/blob/main/composer.lock"
    click ED4 "https://github.com/aaadityapal/connect/blob/main/package.json"
    click ED5 "https://github.com/aaadityapal/connect/blob/main/package-lock.json"
    click ED6 "https://github.com/aaadityapal/connect/tree/main/tcpdf/"

    %% Click Events - Web Server & Environment
    click WS1 "https://github.com/aaadityapal/connect/blob/main/.htaccess"
    click WS2 "https://github.com/aaadityapal/connect/blob/main/config.php"
    click WS3 "https://github.com/aaadityapal/connect/tree/main/config/"
```
