# ribog-digital/magento2-module-offers-page architecture

> Architecture diagram of the GitHub repository ribog-digital/magento2-module-offers-page, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ribog-digital/magento2-module-offers-page
- Repository: https://github.com/ribog-digital/magento2-module-offers-page

## Overview

##### Project type and purpose
- This is a Magento 2 module (extension) named Ribog_Offers.
- Purpose: Provide a dedicated frontend “Offers” page and backend configuration to display active catalog and cart price rules marked “Visible on Offer Page.”

##### File structure
- Top-level Magento module layout:
- Block/Index – frontend block classes
- Controller/Index – frontend controllers for the /offers route
- Model/Config (and Source/Promotions) – config helpers and data sources
- etc/ – routing (frontend/routes.xml), admin config (adminhtml/system.xml), module.xml, ACL, DB schema
- view/frontend – layout XML, templates, CSS, JS for the user-facing Offers page
- view/adminhtml – UI Component XML to add “Visible on Offer Page” toggle in rule edit forms
- No custom database tables; module uses Magento’s catalogrule and salesrule tables plus core_config_data.

##### README for additional insights
- Lists features (Offers page, toggle in price rule forms, enable/disable via system config).
- Describes user flows for admin configuration and frontend access at /offers.

##### Main components and interactions
a. Frontend flow
- Web Client (Browser)
→ HTTP GET /offers
→ Magento Front Controller (index.php → router)
→ Ribog_Offers\Controller\Index\Index
→ Block\Index\Index (viewModel)
→ Template view/frontend/templates/index/index.phtml
→ CSS (view/frontend/web/css) & JS (offers.js)
→ Rendered HTML/CSS/JS back to Browser
→ Browser displays the list of promotions (fetched from Model\Source\Promotions)
b. Backend (Admin) flow
- Magento Admin UI
→ UI Component form definitions (view/adminhtml/ui_component/*.xml)
→ Adds “Visible on Offer Page” attribute to Catalog & Cart Price Rule edit screens
→ Form submission writes attribute to salesrule/catalogrule tables via Magento ORM
→ Module’s etc/adminhtml/system.xml exposes global enable/disable flag stored in core_config_data
c. Data / Persistence
- Magento MySQL Database
– salesrule, catalogrule tables (with new attribute)
– core_config_data (module on/off flag and include promotions setting)

##### Architectural patterns and design principles
- Follows Magento 2 MVC: Controllers → Blocks → Templates
- Leverages Magento UI Component framework in adminhtml
- Uses Dependency Injection (via constructor arguments in PHP classes)
- Configuration via etc/*.xml (routes.xml, module.xml, system.xml, acl.xml)
- No heavy business logic—primarily a presentation and configuration extension

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Browsers
    subgraph "External Clients"
        direction TB
        FB["Web Browser"]:::external
        ADM["Admin Browser"]:::external
    end

    %% Magento Core
    subgraph "Magento Application Core"
        direction TB
        CORE_ROUTER["Front Controller & Router"]:::core
        CORE_ORM["ORM (Magento ResourceModel)"]:::core
    end

    %% Ribog_Offers Module
    subgraph "Ribog_Offers Module"
        direction TB
        subgraph "Controllers"
            CNT["Ribog_Offers\\Controller\\Index\\Index"]:::controller
        end
        subgraph "Blocks & ViewModels"
            BLK["Ribog_Offers\\Block\\Index\\Index"]:::block
        end
        subgraph "Templates & Layouts"
            TPL["index.phtml (Offers page view)"]:::template
            LXML1["offers_index_index.xml"]:::layout
            LXML2["default.xml"]:::layout
        end
        subgraph "Frontend Assets"
            REQJS["requirejs-config.js"]:::asset
            JS["web/js/offers.js"]:::asset
            CSS["web/css/_module.less"]:::asset
        end
        subgraph "Configuration XML"
            ROUTES["etc/frontend/routes.xml"]:::config
            MODULE_XML["etc/module.xml"]:::config
            REG["registration.php"]:::config
            SYSTEM_XML["etc/adminhtml/system.xml"]:::config
            ACL_XML["etc/acl.xml"]:::config
            DB_SCHEMA["etc/db_schema.xml"]:::config
        end
        subgraph "Admin UI Components"
            UI_CAT["catalog_rule_form.xml"]:::ui
            UI_SALES["sales_rule_form.xml"]:::ui
        end
        subgraph "Models"
            CFG_HELPER["Model/Config.php"]:::model
            PROM_SRC["Model/Config/Source/Promotions.php"]:::model
        end
        subgraph "Metadata"
            README["README.md"]:::metadata
            COMPOSER["composer.json"]:::metadata
        end
    end

    %% Database
    DB[(Magento MySQL)]:::database

    %% Frontend Flow
    FB -->|"HTTP GET /offers"| CORE_ROUTER
    CORE_ROUTER -->|"route via routes.xml"| CNT
    CNT -->|"DI inject PromSrc & Config"| BLK
    BLK -->|"renders"| TPL
    TPL -->|"includes CSS & JS"| CSS
    TPL -->|"includes CSS & JS"| JS
    TPL -->|"respond HTML"| FB

    %% Admin Flow
    ADM -->|"loads UI form XML"| UI_CAT
    ADM -->|"loads UI form XML"| UI_SALES
    UI_CAT -->|"renders form"| ADM
    UI_SALES -->|"renders form"| ADM
    ADM -->|"submit form"| CORE_ORM
    CORE_ORM -->|"write rule attribute"| DB
    ADM -->|"load system config XML"| SYSTEM_XML
    ADM -->|"permission check via ACL"| ACL_XML

    %% Core Config & Registration
    REG --> MODULE_XML
    MODULE_XML --> CORE_ROUTER
    MODULE_XML --> CORE_ORM

    %% Models Data Fetch
    BLK -->|"calls"| PROM_SRC
    PROM_SRC -->|"reads rules"| CORE_ORM
    CORE_ORM -->|"read salesrule/catalogrule"| DB
    BLK -->|"reads config"| CFG_HELPER
    CFG_HELPER -->|"reads core_config_data"| DB

    %% Click Events
    click CNT "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/Controller/Index/Index.php"
    click BLK "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/Block/Index/Index.php"
    click TPL "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/frontend/templates/index/index.phtml"
    click LXML1 "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/frontend/layout/offers_index_index.xml"
    click LXML2 "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/frontend/layout/default.xml"
    click REQJS "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/frontend/requirejs-config.js"
    click JS "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/frontend/web/js/offers.js"
    click CSS "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/frontend/web/css/source/_module.less"
    click ROUTES "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/etc/frontend/routes.xml"
    click MODULE_XML "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/etc/module.xml"
    click REG "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/registration.php"
    click UI_CAT "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/adminhtml/ui_component/catalog_rule_form.xml"
    click UI_SALES "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/view/adminhtml/ui_component/sales_rule_form.xml"
    click SYSTEM_XML "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/etc/adminhtml/system.xml"
    click ACL_XML "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/etc/acl.xml"
    click DB_SCHEMA "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/etc/db_schema.xml"
    click CFG_HELPER "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/Model/Config.php"
    click PROM_SRC "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/Model/Config/Source/Promotions.php"
    click README "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/README.md"
    click COMPOSER "https://github.com/ribog-digital/magento2-module-offers-page/blob/main/composer.json"

    %% Styles
    classDef external fill:#E8F5FF,stroke:#0277BD,color:#000;
    classDef core fill:#ECEFF1,stroke:#546E7A,color:#000;
    classDef controller fill:#C8E6C9,stroke:#2E7D32,color:#000;
    classDef block fill:#C8E6C9,stroke:#2E7D32,color:#000;
    classDef template fill:#C8E6C9,stroke:#2E7D32,color:#000;
    classDef layout fill:#DCEDC8,stroke:#558B2F,color:#000;
    classDef asset fill:#F0F4C3,stroke:#AFB42B,color:#000;
    classDef config fill:#FFF9C4,stroke:#FBC02D,color:#000;
    classDef ui fill:#BBDEFB,stroke:#1565C0,color:#000;
    classDef model fill:#D1C4E9,stroke:#5E35B1,color:#000;
    classDef metadata fill:#CFD8DC,stroke:#455A64,color:#000;
    classDef database fill:#FFE0B2,stroke:#EF6C00,color:#000;
```
