# dangbach1410/social-media-website architecture

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

- Interactive diagram: https://gitdiagram.com/dangbach1410/social-media-website
- Repository: https://github.com/dangbach1410/social-media-website

## Overview

**Dear Principal Software Engineer,**

##### Identify the Project Type and Purpose
- **Project Type:** Web-Based Full-Stack Application
- **Purpose:** Facilitate interaction among students for coursework-related discussions, including features like user authentication, profile management, content management, and advanced search functionality.

**Indicators:**
- **File Structure:** Presence of frontend components (templates, CSS), backend scripts (PHP files), database scripts (`mydatabase.sql`), and includes for database operations.
- **README Highlights:** Describes features such as user authentication, question/comment management, profile management, module management for admins, and responsive design.

##### Analyze the File Structure
- **Top-Level Directories and Files:**
- **PHP Scripts:** Handle various functionalities like user authentication (`login.php`, `signup.php`), content management (`add_module.php`, `edit_post.php`), and others.
- **Includes Directory (`includes/`):** Contains `DatabaseConnection.php` and `DatabaseFunctions.php` for database interactions.
- **Templates Directory (`templates/`):** Houses HTML/PHP templates for different pages, ensuring a separation between logic and presentation.
- **Uploads Directory (`uploads/`):** Likely used for storing user-uploaded content such as profile pictures.
- **CSS File (`style.css`):** Manages the styling and responsiveness of the web pages.
- **Database Script (`mydatabase.sql`):** Defines the database schema.

**Architectural Choices:**
- **MVC Pattern:** Separation of concerns with `templates/` for views, PHP scripts for controllers, and `includes/` for models (database interactions).
- **Modular Design:** Individual PHP files handle specific actions (e.g., `add_module.php`, `delete_post.php`), promoting maintainability and scalability.

**Configuration and Deployment Files:**
- While not explicitly listed, the presence of PHP and MySQL suggests configuration files for database connections and possibly server settings.

##### Examine the README for Additional Insights
- **Architecture Description:** Implicit through features and technologies used.
- **Technologies Stack:**
- **Backend:** PHP (version 7.4 or higher)
- **Database:** MySQL
- **Frontend:** HTML5, CSS3, JavaScript
- **Security:** PDO for secure database interactions
- **Features:** Highlight functionalities give an overview of system components and interactions.

**a. Identify Main Components:**
- **Frontend:**
- **Templates:** HTML/PHP files for UI.
- **CSS and JavaScript:** Styling and client-side interactions.
- **Backend:**
- **PHP Scripts:** Handle business logic (authentication, content management).
- **Includes:** Database connection and functions.
- **Database:**
- **MySQL Database:** Stores users, posts, comments, modules.
- **Uploads:** Storage for user-uploaded files (e.g., profile pictures).
- **External Services:**
- **Local Server (e.g., XAMPP):** Hosting environment.

**b. Determine Relationships and Interactions:**
- **User Interaction Flow:**
1. **Frontend (Browser):** Users interact with the UI built from `templates/`, `style.css`, and JavaScript.
2. **Backend (PHP):** User actions trigger PHP scripts (e.g., `login.php` for authentication).
3. **Database:** PHP scripts use `DatabaseConnection.php` and `DatabaseFunctions.php` (via PDO) to interact with the MySQL database.
4. **Uploads:** PHP scripts handle file uploads and store them in the `uploads/` directory.

**c. Highlight Architectural Patterns:**
- **MVC (Model-View-Controller):**
- **Models:** `includes/DatabaseFunctions.php`
- **Views:** `templates/*.html.php`
- **Controllers:** Individual PHP scripts handling requests
- **Security Practices:**
- Use of PDO to prevent SQL injection
- User authentication and authorization mechanisms

**d. Include Relevant Technologies:**
- **PHP 7.4+:** Server-side logic
- **MySQL:** Data storage
- **HTML5 & CSS3:** Structure and styling
- **JavaScript:** Client-side validation and interactivity
- **PDO:** Secure database interactions

##### Elements

- **Components:**
- **Frontend Layer:**
- Templates (`templates/*.html.php`)
- CSS (`style.css`)
- JavaScript
- **Backend Layer:**
- PHP Scripts (`*.php`)
- Includes (`includes/*.php`)
- **Database:**
- MySQL Database (`mydatabase.sql`)
- **Uploads:**
- `uploads/` directory
- **External Services:**
- Local Server (e.g., XAMPP)

- **Interactions:**
- **User Actions:** Pointing to corresponding frontend components.
- **API Calls:** From frontend to backend PHP scripts.
- **Database Queries:** From `includes/DatabaseFunctions.php` to MySQL.
- **File Uploads:** From frontend to `uploads/` via backend scripts.

- **Visual Aids:**
- **Clear Labels:** Each component should be distinctly labeled.
- **Frontend Components:** Blue
- **Backend Components:** Green
- **Database:** Yellow
- **Uploads:** Orange
- **External Services:** Grey
- **Rectangles:** For components like frontend, backend, database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    User["User (Browser)"]:::external

    %% Subgraphs and modules
    subgraph "Frontend Layer"
        Templates["Templates"]:::frontend
        CSS["style.css"]:::frontend
    end

    subgraph "Backend Layer"
        subgraph "Controllers"
            login["login.php"]:::backend
            signup["signup.php"]:::backend
            add_module["add_module.php"]:::backend
            edit_post["edit_post.php"]:::backend
            delete_post["delete_post.php"]:::backend
        end
        subgraph "Models"
            db_connection["DatabaseConnection.php"]:::backend
            db_functions["DatabaseFunctions.php"]:::backend
        end
    end

    Database[(MySQL Database)]:::database
    Uploads["Uploads"]:::uploads
    External["Local Server (e.g., XAMPP)"]:::external

    %% Connections
    User --> Templates
    Templates --> CSS
    Templates --> login
    Templates --> signup
    login --> db_connection
    login --> db_functions
    signup --> db_connection
    signup --> db_functions
    add_module --> db_connection
    add_module --> db_functions
    edit_post --> db_connection
    edit_post --> db_functions
    delete_post --> db_connection
    delete_post --> db_functions
    db_functions --> Database
    Backend_Layer["Backend Layer"] --> Uploads
    Backend_Layer --> Database
    External --> Backend_Layer

    %% Click Events
    click Templates "https://github.com/dangbach1410/social-media-website/tree/main/templates/"
    click CSS "https://github.com/dangbach1410/social-media-website/blob/main/style.css"
    click login "https://github.com/dangbach1410/social-media-website/blob/main/login.php"
    click signup "https://github.com/dangbach1410/social-media-website/blob/main/signup.php"
    click add_module "https://github.com/dangbach1410/social-media-website/blob/main/add_module.php"
    click edit_post "https://github.com/dangbach1410/social-media-website/blob/main/edit_post.php"
    click delete_post "https://github.com/dangbach1410/social-media-website/blob/main/delete_post.php"
    click db_connection "https://github.com/dangbach1410/social-media-website/blob/main/includes/DatabaseConnection.php"
    click db_functions "https://github.com/dangbach1410/social-media-website/blob/main/includes/DatabaseFunctions.php"
    click Database "https://github.com/dangbach1410/social-media-website/blob/main/mydatabase.sql"
    click Uploads "https://github.com/dangbach1410/social-media-website/tree/main/uploads/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef database fill:#FFFF99,stroke:#000,stroke-width:1px
    classDef uploads fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
