# 0xt4req/ems architecture

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

- Interactive diagram: https://gitdiagram.com/0xt4req/ems
- Repository: https://github.com/0xt4req/ems

## Overview

##### Project Type and Purpose
- This project is a web-based Event Management System built using pure PHP & MySQL.
- It includes user authentication, event management (CRUD operations), attendee registration, dashboards (admin and host/user), and a JSON API endpoint.
- Key features such as AJAX integration, role-based access control (RBAC), and secure database interactions make it a full-stack web application with an emphasis on backend business logic and a separate public-facing frontend.

##### Analyzing the File Structure
- Top-level Files/Directories:
- .htaccess, index.php: Likely web server routing files.
- /api: Contains the API endpoint (e.g., index.php) and its own .htaccess for URL rewriting.
- /classes: Contains PHP classes that implement business logic including classes for authentication, event management, database connection, and various user and event types.
- /config: Contains configuration files and initialization scripts (e.g., init.php) for setting up the database and system initialization.
- /public: Contains view files divided into subdirectories (e.g., “admin”, “user”), with dedicated entry points and shared header/footer. This indicates clear segregation of presentation (UI) from core business logic.
- /resources: Contains client-side resources like JavaScript (e.g. togglePassword.js) and JSON config (e.g., particles.json).

- Architectural Patterns Reflected in the Structure:
- Separation of concerns: API endpoints, business logic (classes), configuration, and presentation (public views) are clearly separated.
- A pattern similar to Model-View-Controller (MVC) is evident (even if not strictly enforced) where models and business logic reside in the classes, and views are in the public/views directory.
- The use of configuration (config/init.php and Database.php) provides a centralized mechanism for environmental settings and database connections.

##### Key Insights from the README
- The README emphasizes installation steps including database setup using the init script and instructions for changing configuration details.
- It documents core features, security practices (such as password hashing, use of prepared statements), and even shows example UI screenshots.
- The API documentation link and list of features (like search, event reports, and AJAX enhancement) hint at multiple interactions across different parts of the application.

##### Detailed Elements
- Each component should have clear labels (e.g., “API”, “Authentication & Event Management”, “Database”).
- From user interactions (via the Frontend) to API calls.
- From API calls to business logic components.
- From the business logic to the Database.
- And return flows for responses.
- Clearly delineate areas for security components (e.g., the Auth class managing login and role-based access) and error handling (noted in the README and classes).
- Dependency on external libraries such as Bootstrap for UI and note where AJAX improvements are used.

Final Note for the Principal Software Engineer:

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser("Browser"):::frontend

    subgraph "Public UI (Views)"
        FE_Index("Home Page"):::frontend
        FE_Login("Login Page"):::frontend
        FE_Register("Register Page"):::frontend
        FE_Admin("Admin Dashboard"):::frontend
        FE_UserDash("User Dashboard"):::frontend
        FE_Header("Header"):::frontend
        FE_Footer("Footer"):::frontend
    end

    subgraph "API Layer"
        API("API Endpoint"):::api
        API_HTACCESS("API Rewrite"):::api
    end

    subgraph "Business Logic / Models"
        subgraph "Core Logic"
            BL_Auth("Authentication"):::backend
            subgraph "Event Management"
                BL_BaseEvent("Base Event"):::backend
                BL_PrivateEvent("Private Event"):::backend
                BL_PublicEvents("Public Events"):::backend
                BL_EventApi("Event API"):::backend
            end
            subgraph "User Management"
                BL_Admin("Admin Management"):::backend
                BL_User("User Management"):::backend
            end
            subgraph "Attendee Registration"
                BL_Attendee("Attendee"):::backend
                BL_PublicAttendee("Public Attendee"):::backend
            end
            BL_Database("Database Connection"):::backend
        end
    end

    CFG("Configuration & Initialization"):::config
    CFG_HTACCESS("Config Rewrite"):::config

    subgraph "Client-Side Resources"
        RS_JS("Toggle Password JS"):::resources
        RS_JSON("Particles Config JSON"):::resources
    end

    DB("MySQL Database"):::database

    %% Relationships
    Browser --> FE_Index
    FE_Index -->|"AJAX_call"| API
    FE_Index -->|"Page_render"| BL_Auth

    API_HTACCESS --> API
    API -->|"routes_request"| BL_EventApi

    CFG --> BL_Database
    CFG_HTACCESS --> CFG

    BL_Auth --> BL_Database
    BL_BaseEvent --> BL_Database
    BL_PrivateEvent --> BL_Database
    BL_PublicEvents --> BL_Database
    BL_EventApi --> BL_Database
    BL_Admin --> BL_Database
    BL_User --> BL_Database
    BL_Attendee --> BL_Database
    BL_PublicAttendee --> BL_Database

    BL_Database -->|"connects_to"| DB

    RS_JS --- FE_Index
    RS_JSON --- FE_Index

    %% Click Events for Frontend
    click FE_Admin "https://github.com/0xt4req/ems/blob/main/public/views/admin/dashboard.php"
    click FE_UserDash "https://github.com/0xt4req/ems/blob/main/public/views/user/dashboard.php"
    click FE_Login "https://github.com/0xt4req/ems/blob/main/public/views/login.php"
    click FE_Register "https://github.com/0xt4req/ems/blob/main/public/views/register.php"
    click FE_Index "https://github.com/0xt4req/ems/blob/main/public/views/index.php"
    click FE_Header "https://github.com/0xt4req/ems/blob/main/public/views/header.php"
    click FE_Footer "https://github.com/0xt4req/ems/blob/main/public/views/footer.php"

    %% Click Events for API Layer
    click API "https://github.com/0xt4req/ems/blob/main/api/index.php"
    click API_HTACCESS "https://github.com/0xt4req/ems/blob/main/api/.htaccess"

    %% Click Events for Business Logic / Models
    click BL_Auth "https://github.com/0xt4req/ems/blob/main/classes/Auth.php"
    click BL_BaseEvent "https://github.com/0xt4req/ems/blob/main/classes/BaseEvent.php"
    click BL_PrivateEvent "https://github.com/0xt4req/ems/blob/main/classes/PrivateEvent.php"
    click BL_PublicEvents "https://github.com/0xt4req/ems/blob/main/classes/PublicEvents.php"
    click BL_EventApi "https://github.com/0xt4req/ems/blob/main/classes/EventApi.php"
    click BL_Admin "https://github.com/0xt4req/ems/blob/main/classes/Admin.php"
    click BL_User "https://github.com/0xt4req/ems/blob/main/classes/User.php"
    click BL_Attendee "https://github.com/0xt4req/ems/blob/main/classes/Attendee.php"
    click BL_PublicAttendee "https://github.com/0xt4req/ems/blob/main/classes/PublicAttendee.php"
    click BL_Database "https://github.com/0xt4req/ems/blob/main/classes/Database.php"

    %% Click Events for Configuration and Initialization
    click CFG "https://github.com/0xt4req/ems/blob/main/config/init.php"
    click CFG_HTACCESS "https://github.com/0xt4req/ems/blob/main/config/.htaccess"

    %% Click Events for Client-Side Resources
    click RS_JS "https://github.com/0xt4req/ems/blob/main/resources/js/togglePassword.js"
    click RS_JSON "https://github.com/0xt4req/ems/blob/main/resources/particles.json"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef api fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef config fill:#FFFFE0,stroke:#000,stroke-width:1px;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef resources fill:#FFDAB9,stroke:#000,stroke-width:1px;
```
