# ronaldbit/mopla architecture

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

- Interactive diagram: https://gitdiagram.com/ronaldbit/mopla
- Repository: https://github.com/ronaldbit/mopla

## Overview

##### Project type and purpose
- Mopla is a lightweight, standalone PHP template-engine library designed to cleanly separate PHP logic from HTML.
- It does not ship as a full-stack web app but as a reusable component you include in your PHP pages or frameworks.

##### File structure
- Top-level folders:
- src/ – core engine classes (Mopla.php, Parser.php, Filters.php, ErrorHandler.php, Utils.php)
- demo/ – example application showing integration (index.php + templates/)
- docs/ – written documentation
- No composer.json: Mopla is self-contained, no external dependencies.
- src/ follows a functional decomposition:
- Mopla.php: orchestration entry point
- Parser.php: template syntax → PHP conversion
- Filters.php: pluggable variable filters
- ErrorHandler.php: runtime error/warning capture
- Utils.php: string and helper utilities

##### README for additional insights
- Shows the render flow: application calls Mopla::render(template, variables)
- Lists supported directives ({if}, {for}, {set}, {include}, etc.)
- ErrorHandler provides line-level context without stopping execution

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Application
    Client["Client Application"]:::external
    %% Core Engine Components
    Mopla["Mopla Engine\nMopla.php"]:::core
    Parser["Parser Module\nParser.php"]:::core
    %% Extension Points
    Filters["Filters Module\nFilters.php"]:::ext
    Utils["Utils Module\nUtils.php"]:::ext
    %% Error Handling
    Error["ErrorHandler Module\nErrorHandler.php"]:::error
    %% Template Storage
    Templates[(Template Storage\ndemo/templates)]:::storage
    %% PHP Execution
    PHPEngine["PHP Engine\n(eval/include)"]:::core

    %% Flow
    Client -->|"calls render(template, vars)"| Mopla
    Mopla -->|"registers callbacks"| Error
    Mopla -->|"passes template text"| Parser
    Parser -->|"tokenize & transform"| Utils
    Parser -->|"compile filter expressions"| Filters
    Parser -->|"resolve includes & load partials"| Templates
    Parser -->|"emits PHP code"| Mopla
    Mopla -->|"eval compiled code"| PHPEngine
    PHPEngine -->|"errors/exceptions"| Error
    PHPEngine -->|"HTML output"| Client

    %% Click Events
    click Client "https://github.com/ronaldbit/mopla/blob/main/demo/index.php"
    click Templates "https://github.com/ronaldbit/mopla/tree/main/demo/templates/"
    click Mopla "https://github.com/ronaldbit/mopla/blob/main/src/Mopla.php"
    click Parser "https://github.com/ronaldbit/mopla/blob/main/src/Parser.php"
    click Filters "https://github.com/ronaldbit/mopla/blob/main/src/Filters.php"
    click Error "https://github.com/ronaldbit/mopla/blob/main/src/ErrorHandler.php"
    click Utils "https://github.com/ronaldbit/mopla/blob/main/src/Utils.php"

    %% Styles
    classDef core fill:#AEDFFD,stroke:#333,stroke-width:1px
    classDef ext fill:#C2F0C2,stroke:#333,stroke-width:1px
    classDef error fill:#FFD8A8,stroke:#333,stroke-width:1px
    classDef external fill:#E8E8E8,stroke:#333,stroke-width:1px
    classDef storage fill:#F0E68C,stroke:#333,stroke-width:1px
```
