Affiliate CMS Architecture

Complete system overview showing how all components interact

flowchart TB
    subgraph BROWSER["🌐 Browser"]
        REQ["Request: yoursite.com/post/slug"]
    end

    subgraph ENTRY["📥 Entry Points"]
        INDEX["index.php
        Frontend Router"]
        ADMIN_ENTRY["admin/*.php
        Admin Panel"]
    end

    subgraph CORE["🔧 Core System"]
        direction TB
        BOOT["bootstrap.php
        Initializes everything"]
        
        subgraph CLASSES["Core Classes"]
            direction LR
            DB["Database
            PDO Wrapper"]
            SETTINGS["Settings
            Site Config"]
            AUTH["Auth
            Login/Sessions"]
        end
        
        subgraph MODELS["Data Models"]
            direction LR
            POST["Post
            Blog articles"]
            CAT["Category
            Taxonomies"]
            AMZN["AmazonAffiliate
            Product API"]
        end
    end

    subgraph THEMES["🎨 Themes"]
        SELECTOR{"Settings:
        active_theme"}
        T1["developer/
        Dark Mode"]
        T2["minimalist/
        Light & Clean"]
        T3["magazine/
        Bold Colors"]
        
        subgraph FILES["Template Files"]
            H["header.php"]
            F["footer.php"]
            I["index.php"]
            S["single.php"]
        end
    end

    subgraph ADMIN["🔐 Admin Panel"]
        direction TB
        A_DASH["Dashboard"]
        A_POSTS["Posts Manager"]
        A_CATS["Categories"]
        A_SETTINGS["Site Settings"]
        A_AMAZON["Amazon Config"]
        A_THEMES["Theme Selector"]
        A_USERS["User Management"]
    end

    subgraph DATA["🗄️ MySQL"]
        direction LR
        DB_USERS[("users")]
        DB_POSTS[("posts")]
        DB_CATS[("categories")]
        DB_SETTINGS[("settings")]
    end

    subgraph EXTERNAL["🌍 External"]
        AMAZON_API["Amazon PA-API"]
    end

    REQ --> INDEX & ADMIN_ENTRY
    INDEX --> BOOT
    ADMIN_ENTRY --> BOOT
    BOOT --> CLASSES
    BOOT --> MODELS
    
    DB --> DATA
    POST --> DB
    CAT --> DB
    SETTINGS --> DB
    AUTH --> DB
    
    INDEX --> SELECTOR
    SELECTOR --> T1 & T2 & T3
    T1 & T2 & T3 --> FILES
    FILES --> POST & CAT & SETTINGS & AMZN
    
    A_SETTINGS --> SETTINGS
    A_AMAZON --> AMZN
    A_THEMES --> SETTINGS
    A_POSTS --> POST
    A_CATS --> CAT
    A_USERS --> AUTH
    
    AMZN --> AMAZON_API

    classDef purple fill:#6366f1,stroke:#8b5cf6,color:white
    classDef green fill:#10b981,stroke:#059669,color:white
    classDef pink fill:#ec4899,stroke:#be185d,color:white
    classDef orange fill:#f59e0b,stroke:#d97706,color:black
    classDef blue fill:#3b82f6,stroke:#1d4ed8,color:white
    classDef dark fill:#1e1e2e,stroke:#3f3f46,color:#e4e4e7

    class INDEX,BOOT purple
    class T1,T2,T3,H,F,I,S green
    class A_DASH,A_POSTS,A_CATS,A_SETTINGS,A_THEMES,A_USERS pink
    class AMZN,A_AMAZON,AMAZON_API orange
    class DB,DB_USERS,DB_POSTS,DB_CATS,DB_SETTINGS blue
    class POST,CAT,AUTH,SETTINGS dark
            

📍 Request Flow: Viewing a Blog Post

1. Browser hits
/post/my-article
2. .htaccess routes
to index.php
3. Bootstrap loads
core classes
4. Router parses
URL slug
5. Post::getBySlug()
fetches from DB
6. Amazon products
fetched by keywords
7. Active theme's
single.php renders
8. HTML sent
to browser

Core System

The engine that powers everything. Bootstrap initializes the database connection, loads settings, and sets up authentication.

  • bootstrap.php - Application entry point
  • Database.php - PDO wrapper with CRUD helpers
  • Settings.php - Cached site options
  • Auth.php - Sessions, CSRF, password hashing

Theme System

Self-contained theme folders with templates. Switch themes instantly from the admin panel - only the frontend changes.

  • header.php - HTML head, navigation, CSS
  • footer.php - Footer, closing tags
  • index.php - Blog listing template
  • single.php - Individual post with Amazon products

Admin Panel

Complete content management system with a modern dark UI. Manages all site content and configuration.

  • Dashboard with stats overview
  • Rich text post editor
  • Theme switcher with preview
  • SEO meta tags configuration
  • User roles: admin, editor, author

Amazon Integration

Automatic affiliate product recommendations. Works with or without PA-API credentials.

  • Affiliate tag applied to all links
  • Per-post keyword targeting
  • Multiple marketplace support
  • Mock data for testing without API

Database Layer

MySQL with PDO prepared statements for security. All queries use parameter binding to prevent SQL injection.

  • users - Admin accounts with roles
  • posts - Blog content with SEO fields
  • categories - Post taxonomies
  • settings - Key-value site options

Data Models

Business logic classes that interact with the database and provide clean APIs for templates.

  • Post.php - CRUD, search, slugs, views
  • Category.php - Taxonomy management
  • AmazonAffiliate.php - Product search, link generation