# ounziw/recently_viewed_page architecture

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

- Interactive diagram: https://gitdiagram.com/ounziw/recently_viewed_page
- Repository: https://github.com/ounziw/recently_viewed_page

## Overview

Step 1. Identify Main Components:
- Client-Side Logic – The add-on uses JavaScript (record.js, view.js) and leverages local storage to store and retrieve browsing history. This allows the client’s browser to retain data independent of server load or caching.
- Custom Templates – Under the “templates/withimage” folder, there are template files (view.php, view.js) to customize the appearance of the recently viewed items based on the theme. The integration with underscore.js (concrete5 includes this library) is used for rendering dynamic content.

Step 2. Analyze Relationships and Data Flow:
- The Frontend (Web Browser):
– Activates client-side JavaScript (record.js, view.js) that captures the page visit events and interacts with local storage.
– Uses customized templates to render the block’s UI, drawing data from local storage and possibly from the PHP controller.
- The Block (Server-Side PHP):
– Uses PHP files (controller.php, add.php, edit.php) to initialize the block and manage configuration within concrete5.
– The db.xml may be responsible for any database schema needed on installation, despite the primary storage being on the client.
- Concrete5 Core System:
– Acts as the integration framework that loads the add-on’s components through its block mechanism and its theme engine, ensuring proper rendering and configuration.
- Data Flow:
– The client’s browser loads the page with the block.
– The JavaScript code captures the user’s interactions and updates local storage.
– The PHP block controller may retrieve or send additional configuration or template data as required for rendering.

Step 3. Highlight Architectural Patterns and Technologies:
- Integration Pattern – This add-on follows a plug-in or modular approach, where its PHP components are registered as a block inside the concrete5 CMS.
- Clear Separation of Client and Server – The client handles the real-time tracking using JavaScript and local storage, minimizing server load; whereas the server-side code is mainly for integration with the CMS and providing configuration.
- Use of Concrete5’s Templating – The custom template supports theming and dynamic content rendering through underscore.js.
- Dependency on Concrete5 Core – The project relies on concrete5 (v7.5+ as noted) with its inherent architectural constraints.

– Inside this block, list the server-side components (PHP controller, configuration files like db.xml, installation scripts).
##### Architectural separation by grouping blocks together
– Group together all files and functionalities that belong to the server-side (PHP files, installation scripts) separately from the client-side (JS and templates).
– Highlight the customization extension point with the “withimage” template as part of the overall block’s presentation layer.

Step 5. Final Touches:
- Annotations to indicate that the main design principle is offloading history tracking to the client to reduce server load.
- Mention key dependencies (underscore.js, concrete5 versions, and local storage use).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Concrete5 CMS Layer
    subgraph "Concrete5 CMS Layer"
        CMS["Concrete5 CMS"]:::cms
        AddOn["Recently Viewed Block (Server-Side)"]:::server
        CMS -->|"embeds"| AddOn
    end

    %% Server-Side Block Components
    subgraph "Server-Side Block Components"
        Controller["Controller (controller.php)"]:::server
        AddBlock["Add Block (add.php)"]:::server
        EditBlock["Edit Block (edit.php)"]:::server
        FormSetup["Form Setup (form_setup_html.php)"]:::server
        DBSchema["DB Schema (db.xml)"]:::server
    end

    AddOn --> Controller
    AddOn --> AddBlock
    AddOn --> EditBlock
    AddOn --> FormSetup
    AddOn --> DBSchema

    %% Client Browser Components
    subgraph "Client Browser"
        direction TB
        Browser["Web Browser"]:::client
        subgraph "JavaScript Module"
            RecordJS["Record.js"]:::client
            ViewJS["View.js"]:::client
        end
        subgraph "Custom Templates"
            TemplatePHP["Template - view.php"]:::client
            TemplateJS["Template - view.js"]:::client
        end
        LocalStorage["Local Storage"]:::storage
        Browser -->|"loads"| RecordJS
        Browser -->|"renders"| TemplatePHP
        Browser -->|"renders"| TemplateJS
        RecordJS -->|"updates"| LocalStorage
    end

    CMS -->|"rendersPage"| Browser
    Controller -->|"sendsConfig"| Browser

    %% Styles
    classDef cms fill:#b3cde0,stroke:#1f78b4,stroke-width:2px;
    classDef server fill:#fbb4ae,stroke:#e31a1c,stroke-width:2px;
    classDef client fill:#ccebc5,stroke:#33a02c,stroke-width:2px;
    classDef storage fill:#ffffcc,stroke:#ff7f00,stroke-width:2px;

    %% Click Events
    click CMS "https://github.com/ounziw/recently_viewed_page/tree/master/ounziw_recent_views"
    click Controller "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/controller.php"
    click AddBlock "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/add.php"
    click EditBlock "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/edit.php"
    click FormSetup "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/form_setup_html.php"
    click DBSchema "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/db.xml"
    click RecordJS "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/js/record.js"
    click ViewJS "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/view.js"
    click TemplatePHP "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/templates/withimage/view.php"
    click TemplateJS "https://github.com/ounziw/recently_viewed_page/blob/master/ounziw_recent_views/blocks/recent_views/templates/withimage/view.js"
```
