# 2pisoftware/cmfive-core architecture

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

- Interactive diagram: https://gitdiagram.com/2pisoftware/cmfive-core
- Repository: https://github.com/2pisoftware/cmfive-core

## Overview

##### Main Components
- Front Controller / Entry Point: At the root you see files like index.php and web.php. These represent the entry points that receive HTTP requests from the web server.
- Core Engine (Cmfive System): The “system” folder contains the core classes (in system/classes) handling configuration, routing (Request, MenuLinkType, SessionManager) and database interactions (DbPDO, DbMigration, DbObject, DbService). This layer implements the framework’s base functionality.
- Modules: The “system/modules” directory shows many separate modules (admin, auth, channels, file, form, help, insights, main, report, search, tag, task, timelog, tokens, etc.). Each module follows the structure defined in the README – it has required subdirectories (actions, models, templates, install/migrations, and a config.php). These modules encapsulate discrete features and plug into the core engine.
- Database: The framework uses its own ORM (the “DbObject” classes and “DbService” classes) for accessing MySQL. The install/migrations for each module (and in system/install) show that schema evolution is a big part of the system.
- Assets, Libraries and Templates: There’s a clear separation of static assets (CSS, JS, images in assets folders and in system/templates/…) and third-party libraries (FluentPDO, phpThumb, Vue components etc.), which support both frontend and backend functionality.

##### Relationships and Layers
– Actions (the PHP functions with naming conventions like listsongs_GET, etc.)
– Models (DbObject and DbService classes handling business logic and database interactions)
– Templates (presentation layer files, e.g., listsongs.tpl.php)
– Config (the module’s config.php, which is required to register that module)
- Frontend/Assets: A separate layer for static assets and template files that run on the browser. Mention that the system’s templating engine uses PHP templates as well as integrating with Vue components (present in system/templates/base and Vue-components).

##### Architectural Patterns and Design Principles
- Modularity: Emphasize that most application functionality is encapsulated in self-contained modules. Each module clearly follows an MVC–like pattern (Actions as controllers, Models for business logic/ORM, and Templates for the view).
- Routing and Naming Conventions: Make a note (perhaps a side annotation) that URL routes match module names and actions (e.g., /music/listsongs) and that actions use naming conventions like <action name>_<HTTP VERB>.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Top Layer - HTTP Request and Entry Points
    A("HTTP/S Request"):::webserver
    B("Entry Point (web.php)"):::entry
    A --> B

    %% Core Engine Layer
    subgraph "Cmfive Core Engine"
        CC("Core Classes"):::core
        GC("Global Config (config.php)"):::core
        DBF("DB Setup (db.php)"):::core
        FUN("Functions (functions.php)"):::core
        HH("HTML Helper (html.php)"):::core
        CC --> GC
        GC --> DBF
        DBF --> FUN
        FUN --> HH
    end
    B --> CC

    %% Modules Layer
    subgraph "Modules Layer"
        M("Modules Loader (system/modules)"):::module
        MC("Module Components: Actions,Models,Templates,Config,Migrations"):::module
        M --> MC
    end
    CC --> M

    %% Data / Database Layer
    D("MySQL Database"):::database
    %% Core engine DB access arrow
    DBF -->|"DBAccess"| D
    %% Module models interacting with database
    MC -->|"CRUD"| D

    %% Migration / Installation Component
    MIG("Migrations (system/install)"):::migration
    MIG -->|"SchemaUpdates"| D
    %% Also module specific migrations (not drawn separately) are part of MC

    %% Frontend Assets and External Libraries
    AS("Static Assets (system/templates)"):::asset
    LIB("Third-Party Libraries (system/lib)"):::library
    M -->|"RenderTemplates"| AS
    M -->|"UtilizeLibs"| LIB

    %% Click Events
    click B "https://github.com/2pisoftware/cmfive-core/blob/main/system/web.php"
    click CC "https://github.com/2pisoftware/cmfive-core/tree/main/system/classes"
    click GC "https://github.com/2pisoftware/cmfive-core/blob/main/system/config.php"
    click DBF "https://github.com/2pisoftware/cmfive-core/blob/main/system/db.php"
    click FUN "https://github.com/2pisoftware/cmfive-core/blob/main/system/functions.php"
    click HH "https://github.com/2pisoftware/cmfive-core/blob/main/system/html.php"
    click M "https://github.com/2pisoftware/cmfive-core/tree/main/system/modules"
    click MIG "https://github.com/2pisoftware/cmfive-core/tree/main/system/install"
    click AS "https://github.com/2pisoftware/cmfive-core/tree/main/system/templates"
    click LIB "https://github.com/2pisoftware/cmfive-core/tree/main/system/lib"

    %% Styles
    classDef webserver fill:#f4a460,stroke:#333,stroke-width:2px;
    classDef entry fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef core fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef module fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef database fill:#ffb6c1,stroke:#333,stroke-width:2px;
    classDef migration fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef asset fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef library fill:#dda0dd,stroke:#333,stroke-width:2px;
```
