# espoirbaraka/cypht architecture

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

- Interactive diagram: https://gitdiagram.com/espoirbaraka/cypht
- Repository: https://github.com/espoirbaraka/cypht

## Overview

##### Main Components
- Module Loader & Modules – Emphasize the plugin architecture by displaying the “modules” directory as a collection of many self-contained modules (for example: “imap”, “smtp”, “calendar”, “contacts”, “2fa”, etc.). Note that each module typically includes setup scripts, assets (CSS, JS), and specific PHP files that implement functionality. Illustrate how the core framework dynamically loads these modules.
- Configuration & Deployment – Include configuration files (in “config”, “composer.json”, .env.example) and show that they feed into the behavior of both the core and modules. Also, highlight deployment support through Docker (with the docker folder and docker-compose files), Continuous Integration (GitHub workflows, Travis), and related scripts.
- Testing & Continuous Integration – Represent a separate “tests” layer which includes both PHPUnit and Selenium tests, illustrating how various parts of the system are validated and how integration tests cover interaction with email services and modules.

##### Relationships and Interactions
- The central core framework (index.php, lib/dispatch.php) calls modules through a dispatcher, which in turn may call backend services (database, external email protocols, caching layers).
- Modules communicate with the core by adhering to clearly defined interfaces (especially via modules.php, setup.php files). They add their user interface assets (CSS/JS) and may call external services or share data with other modules.
- External systems such as IMAP/SMTP servers interface with the modules dealing with emails and messaging.

##### Architectural Patterns and Technologies
- MVC-like Separation (where applicable) – Although not a formal MVC framework, the system separates presentation (assets, site.js/site.css) from processing (PHP libraries and modules).
- Deployment and Testing Pipelines – Incorporate Docker and CI/CD (GitHub workflows, Travis CI) by using a separate “Deployment & Testing” section that shows environments and automation scripts.
- Communication Protocols – Show clearly what protocols (IMAP, SMTP, JMAP, EWS) interact with which parts of the system.

##### Being Detailed
- Do not hesitate to break down the project into as many detailed components as necessary. Illustrate sub-components like asset management (CSS/JS under modules), testing (PHPUnit and Selenium tests), and CI/CD automation (GitHub workflows, Travis).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer
    Browser["User Browser"]:::client
    Browser -->|"sends request"| Entry["Entry Point (index.php)"]:::core

    %% Core System Subgraph
    subgraph "Core System"
        Entry
        Dispatch["Dispatch (lib/dispatch.php)"]:::core
        Framework["Framework (lib/framework.php)"]:::core
        ModuleLoader1["Module Loader: modules.php"]:::core
        ModuleLoader2["Module Loader: module.php"]:::core
    end

    Entry -->|"initializes"| Dispatch
    Dispatch -->|"loads"| Framework
    Framework -->|"invokes"| ModuleLoader1
    Framework -->|"invokes"| ModuleLoader2

    %% Modules Subgraph
    subgraph "Modules"
        IMAPModule["IMAP Module"]:::module
        SMTPModule["SMTP Module"]:::module
        CalendarModule["Calendar Module"]:::module
        ContactsModule["Contacts Module"]:::module
        TwoFAModule["2FA Module"]:::module
    end

    ModuleLoader1 -->|"loads"| IMAPModule
    ModuleLoader1 -->|"loads"| SMTPModule
    ModuleLoader2 -->|"loads"| CalendarModule
    ModuleLoader2 -->|"loads"| ContactsModule
    ModuleLoader2 -->|"loads"| TwoFAModule

    %% External Email Services Subgraph
    subgraph "External Email Services"
        IMAPService["IMAP Service"]:::external
        SMTPService["SMTP Service"]:::external
        JMAPService["JMAP Service"]:::external
        EWSService["EWS Service"]:::external
    end

    %% Modules communicating with external email services
    IMAPModule -->|"communicates"| IMAPService
    SMTPModule -->|"communicates"| SMTPService
    IMAPModule ---|"optional"| JMAPService
    SMTPModule ---|"optional"| EWSService

    %% Configuration Subgraph
    subgraph "Configuration"
        ConfigDir["Config Directory"]:::config
        ComposerConfig["Composer Config"]:::config
        EnvExample[".env.example"]:::config
    end

    ConfigDir -->|"configures"| Entry
    ComposerConfig -->|"configures"| Entry
    EnvExample -->|"configures"| Entry

    %% Deployment & Testing Subgraph
    subgraph "Deployment & Testing"
        Docker["Docker Support"]:::deploy
        DockerComposeDev["Docker Compose Dev"]:::deploy
        DockerCompose["Docker Compose"]:::deploy
        GHWorkflows["GitHub Workflows"]:::deploy
        TestingSuite["Testing Suite"]:::test
        TravisCI["Travis CI Config"]:::test
    end

    Docker -->|"supports"| Entry
    DockerComposeDev -->|"orchestrates"| Docker
    DockerCompose -->|"orchestrates"| Docker
    GHWorkflows -->|"automates"| Entry
    TestingSuite -->|"validates"| Entry
    TravisCI -->|"CI checks"| TestingSuite

    %% Styling Classes
    classDef core fill:#fef2cc,stroke:#d4a017,stroke-width:2px;
    classDef module fill:#cce5ff,stroke:#337ab7,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef config fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef deploy fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef test fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef client fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events
    click Entry "https://github.com/espoirbaraka/cypht/blob/master/index.php"
    click Dispatch "https://github.com/espoirbaraka/cypht/blob/master/lib/dispatch.php"
    click Framework "https://github.com/espoirbaraka/cypht/blob/master/lib/framework.php"
    click ModuleLoader1 "https://github.com/espoirbaraka/cypht/blob/master/lib/modules.php"
    click ModuleLoader2 "https://github.com/espoirbaraka/cypht/blob/master/lib/module.php"
    click ConfigDir "https://github.com/espoirbaraka/cypht/tree/master/config/"
    click ComposerConfig "https://github.com/espoirbaraka/cypht/blob/master/composer.json"
    click EnvExample "https://github.com/espoirbaraka/cypht/blob/master/.env.example"
    click IMAPModule "https://github.com/espoirbaraka/cypht/tree/master/modules/imap"
    click SMTPModule "https://github.com/espoirbaraka/cypht/tree/master/modules/smtp"
    click CalendarModule "https://github.com/espoirbaraka/cypht/tree/master/modules/calendar"
    click ContactsModule "https://github.com/espoirbaraka/cypht/tree/master/modules/contacts"
    click TwoFAModule "https://github.com/espoirbaraka/cypht/tree/master/modules/2fa"
    click Docker "https://github.com/espoirbaraka/cypht/tree/master/docker/"
    click DockerComposeDev "https://github.com/espoirbaraka/cypht/blob/master/docker-compose.dev.yaml"
    click DockerCompose "https://github.com/espoirbaraka/cypht/blob/master/docker/docker-compose.yaml"
    click GHWorkflows "https://github.com/espoirbaraka/cypht/tree/master/.github/workflows/"
    click TestingSuite "https://github.com/espoirbaraka/cypht/tree/master/tests/"
    click TravisCI "https://github.com/espoirbaraka/cypht/blob/master/.travis.yml"
```
