# shafihuzaib/hfeeds architecture

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

- Interactive diagram: https://gitdiagram.com/shafihuzaib/hfeeds
- Repository: https://github.com/shafihuzaib/hfeeds

## Overview

##### Project type and purpose
- This is a small PHP-based web application (“hFeeds”) that generates RSS feeds for arbitrary web pages by letting a user define “global” and “repeatable” HTML extraction patterns.
- There is no separate database: all generated feeds live as PHP-wrapped XML files under the `xml/` directory with an `.htaccess` that tells Apache (or another server) to treat `.xml` as PHP.

##### File structure
- Top-level scripts:
- `index.php` – initial form for the page URL and encoding
- `pattern.php` – displays the source and lets users pick global/repeatable patterns
- `prepat.php` – takes the pattern selections plus feed-metadata and generates the final feed file
- `header.php` / `style.css` / `images/` – shared UI elements and styling
- Configuration & dependencies:
- `.gitignore`, `TODO.txt`, `README.md`, `app.json`, NetBeans project files under `nbproject/`
- The `xml/` folder holds the generated feeds. It contains an `.htaccess` that maps `.xml` to the PHP engine and two template files (`default.php` and `include.php`) that build each feed.

##### README for additional insights
- There is no database layer; feed definitions and generated items are entirely file-based.
- Users walk through 3 steps (enter URL, define patterns, set feed fields) before the app spits out a live RSS feed link in `xml/XYZ.xml`.

a. Main components
- Client (Web Browser)
- Web Server (e.g., Apache/Nginx) with PHP handler
- PHP application layers:
– UI layer (index.php → pattern.php → prepat.php)
– Extraction engine (pattern parsing, HTML scraping code embedded in these scripts)
- File Storage: the `xml/` directory (generated RSS feed files)
- External Systems: Target Web Pages (the URL the user enters) and RSS Consumers (feed readers)
b. Relationships & data flow
1. Browser → HTTP GET/POST → index.php
2. index.php → shows form → user submits → pattern.php
3. pattern.php → HTML scrape of target URL → user selects patterns → submits to prepat.php
4. prepat.php → writes out an `.xml` PHP file into `xml/`
5. Browser/RSS reader → requests `xml/XYZ.xml` → `.htaccess` routes to PHP → serves RSS XML
c. Architectural patterns & principles
- Single-page stepwise UI (wizard style)
- File-based persistence (no DB)
- Separation of concerns between UI (header.php/style.css), pattern logic, and feed template (`xml/*.php`)
d. Key technologies & libraries
- PHP 7+ (built-in DOM functions or regex for scraping)
- Apache `.htaccess` for extension mapping
- Composer (optional) for any future library additions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems Layer
    subgraph "External Systems" 
        direction TB
        TargetWeb["Target Web Page"]:::external
    end

    %% Client Layer
    subgraph "Client"
        direction TB
        Browser["Web Browser"]:::external
    end

    %% Web Server & PHP Application
    subgraph "Web Server & PHP Application"
        direction TB

        %% Presentation/UI Layer
        subgraph "UI Layer" 
            direction TB
            Index["index.php"]:::frontend
            Pattern["pattern.php"]:::frontend
            Prepat["prepat.php"]:::frontend
            Header["header.php"]:::frontend
            Style["style.css"]:::frontend
            Images["images/"]:::frontend
        end

        %% Business Logic Layer
        subgraph "Business Logic"
            direction TB
            ExtractEngine["Extraction Engine"]:::business
        end
    end

    %% Feed Storage & Handler
    subgraph "Feed Storage & Handler"
        direction TB
        XMLDir["xml/"]:::storage
        HTAccess[".htaccess"]:::storage
        DefaultTpl["default.php"]:::storage
        IncludeTpl["include.php"]:::storage
    end

    %% RSS Consumer
    subgraph "RSS Consumers"
        direction TB
        RSSReader["RSS Reader"]:::external
    end

    %% Config & Dependencies
    subgraph "Config & Dependencies"
        direction TB
        ComposerJSON["composer.json"]:::config
        ComposerLock["composer.lock"]:::config
        GitIgnore[".gitignore"]:::config
        Readme["README.md"]:::config
        Todo["TODO.txt"]:::config
        AppJSON["app.json"]:::config
        NBProject["nbproject/"]:::config
    end

    %% Data Flows
    Browser -->|GET URL| Index
    Index -->|POST URL & encoding| Pattern
    Pattern -->|FETCH HTML| TargetWeb
    Pattern -->|POST patterns & metadata| Prepat
    Prepat -->|WRITE feed| XMLDir
    XMLDir --> HTAccess
    HTAccess --> DefaultTpl
    HTAccess --> IncludeTpl
    RSSReader -->|FETCH feed| XMLDir

    %% Internal calls
    Pattern --> ExtractEngine
    Prepat --> ExtractEngine

    %% Click Events
    click Index "https://github.com/shafihuzaib/hfeeds/blob/master/index.php"
    click Pattern "https://github.com/shafihuzaib/hfeeds/blob/master/pattern.php"
    click Prepat "https://github.com/shafihuzaib/hfeeds/blob/master/prepat.php"
    click Header "https://github.com/shafihuzaib/hfeeds/blob/master/header.php"
    click Style "https://github.com/shafihuzaib/hfeeds/blob/master/style.css"
    click Images "https://github.com/shafihuzaib/hfeeds/tree/master/images/"
    click XMLDir "https://github.com/shafihuzaib/hfeeds/tree/master/xml/"
    click HTAccess "https://github.com/shafihuzaib/hfeeds/blob/master/xml/.htaccess"
    click DefaultTpl "https://github.com/shafihuzaib/hfeeds/blob/master/xml/default.php"
    click IncludeTpl "https://github.com/shafihuzaib/hfeeds/blob/master/xml/include.php"
    click ComposerJSON "https://github.com/shafihuzaib/hfeeds/blob/master/composer.json"
    click ComposerLock "https://github.com/shafihuzaib/hfeeds/blob/master/composer.lock"
    click GitIgnore "https://github.com/shafihuzaib/hfeeds/blob/master/.gitignore"
    click Readme "https://github.com/shafihuzaib/hfeeds/blob/master/README.md"
    click Todo "https://github.com/shafihuzaib/hfeeds/blob/master/TODO.txt"
    click AppJSON "https://github.com/shafihuzaib/hfeeds/blob/master/app.json"
    click NBProject "https://github.com/shafihuzaib/hfeeds/tree/master/nbproject/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000;
    classDef business fill:#d4edda,stroke:#28a745,color:#000;
    classDef storage fill:#fff3cd,stroke:#ffc107,color:#000;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000;
    classDef config fill:#f0f0f0,stroke:#888888,color:#000;
```
