# minhtri593/social_media architecture

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

- Interactive diagram: https://gitdiagram.com/minhtri593/social_media
- Repository: https://github.com/minhtri593/social_media

## Overview

##### Main Components
- PHP Backend – The heart of the application handling business logic, authentication, content management, user interactions, notifications, and administrative functions. This layer consists of numerous PHP files (e.g., api.php, blogs.php, admin.php, etc.) and controllers invoked via AJAX calls found in the “includes/ajax” directories.
- Smarty Templating Engine – Used to decouple presentation from logic. It’s a core part of the backend, with templates stored in “content/themes/default/templates” and pre-compiled versions in “templates_compiled.”
- Database Layer – Although not explicit in the file tree, a database is implied for storing user data, posts, friendships, messages, settings, and analytics. Represent this as a separate “Database” component.
- Asset and Media Storage – Static content like CSS, JavaScript, images, uploads (photos, videos, sounds) found inside “content/uploads” and “includes/assets.” This component may be hosted on a separate server or a CDN.
- External Services – Include integrations such as Google Authentication, OneSignal push notifications (as seen in OneSignalSDKWorker files), and payment/payment webhook services (as shown in “includes/ajax/payments” and “webhooks” directories).

##### Relationships and Interactions
- AJAX Communication: Clearly indicate the many AJAX endpoints contained within the “includes/ajax” folder that serve functions such as chat messaging, notifications, and user settings.
- External Integrations: Map how the application communicates with external services (e.g., Google Authentication, push notifications, and payment gateways via webhooks) and how those modules plug into the core system.

##### Architectural Patterns and Technologies
- Separation of Concerns: Illustrate a clear split between presentation (Smarty templates and Bootstrap for UI), business logic (PHP scripts in root and includes), and data management.
- Real-Time Communication: Highlight components for chat and live notifications where Node.js and AJAX liveliness play key roles.
- Security & Authentication: Note the authentication processes (password recovery, two-factor, login session management) as distinct interaction points between users and the backend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        UI["User Interface (HTML/CSS/JS with Bootstrap)"]:::frontend
        subgraph "Frontend Assets"
            Templates["Templates"]:::frontend
            CSS["Styles (CSS)"]:::frontend
            JS["Scripts (JS Core)"]:::frontend
        end
    end

    %% Server Side
    subgraph "Server Side"
        subgraph "PHP Backend"
            subgraph "Main PHP Files"
                AdminPHP["admin.php"]:::backend
                AdsPHP["ads.php"]:::backend
                ApiPHP["api.php"]:::backend
                BlogsPHP["blogs.php"]:::backend
                MessagesPHP["messages.php"]:::backend
            end
            subgraph "AJAX Controllers"
                AJAX_Core["Core"]:::backend
                AJAX_Posts["Posts"]:::backend
                AJAX_Users["Users"]:::backend
                AJAX_Payments["Payments"]:::backend
            end
            Smarty["Smarty Template Engine"]:::backend
        end
        Database["Database"]:::database
    end

    %% Assets and Storage
    subgraph "Assets & Storage"
        StaticAssets["Static Assets"]:::assets
        Media["Media Uploads"]:::assets
    end

    %% External Services
    subgraph "External Services"
        OneSignal["OneSignal Integration"]:::external
        PaymentWebhook["Payment Webhooks"]:::external
    end

    %% Connections: Client Side to Backend
    UI -->|"AJAX"| AJAX_Core
    UI -->|"AJAX"| AJAX_Posts
    UI -->|"AJAX"| AJAX_Users
    UI -->|"AJAX"| AJAX_Payments
    UI -->|"Loads Assets"| StaticAssets
    UI -->|"Loads Media"| Media

    %% Connections: Backend to Database
    AdminPHP -->|"CRUD"| Database
    AJAX_Core -->|"CRUD"| Database

    %% Connections: Backend Rendering and External Integrations
    Smarty -->|"Render HTML"| UI
    Smarty -->|"Compiles"| Templates
    ApiPHP -->|"PushNotifications"| OneSignal
    ApiPHP -->|"PaymentProcessing"| PaymentWebhook

    %% Click Events for Frontend Client
    click Templates "https://github.com/minhtri593/social_media/tree/main/content/themes/default/templates"
    click CSS "https://github.com/minhtri593/social_media/tree/main/content/themes/default/css"
    click JS "https://github.com/minhtri593/social_media/tree/main/includes/assets/js/core"

    %% Click Events for PHP Backend - Main PHP Files
    click AdminPHP "https://github.com/minhtri593/social_media/blob/main/admin.php"
    click AdsPHP "https://github.com/minhtri593/social_media/blob/main/ads.php"
    click ApiPHP "https://github.com/minhtri593/social_media/blob/main/api.php"
    click BlogsPHP "https://github.com/minhtri593/social_media/blob/main/blogs.php"
    click MessagesPHP "https://github.com/minhtri593/social_media/blob/main/messages.php"

    %% Click Events for AJAX Controllers
    click AJAX_Core "https://github.com/minhtri593/social_media/tree/main/includes/ajax/core"
    click AJAX_Posts "https://github.com/minhtri593/social_media/tree/main/includes/ajax/posts"
    click AJAX_Users "https://github.com/minhtri593/social_media/tree/main/includes/ajax/users"
    click AJAX_Payments "https://github.com/minhtri593/social_media/tree/main/includes/ajax/payments"

    %% Click Event for Smarty Templating Engine
    click Smarty "https://github.com/minhtri593/social_media/tree/main/content/themes/default/templates_compiled"

    %% Click Events for Assets and Media Storage
    click StaticAssets "https://github.com/minhtri593/social_media/tree/main/includes/assets"
    click Media "https://github.com/minhtri593/social_media/tree/main/content/uploads"

    %% Click Events for External Services
    click OneSignal "https://github.com/minhtri593/social_media/blob/main/OneSignalSDKWorker.js"
    click PaymentWebhook "https://github.com/minhtri593/social_media/tree/main/webhooks"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef assets fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
