# tuankiet116/media_social_network architecture

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

- Interactive diagram: https://gitdiagram.com/tuankiet116/media_social_network
- Repository: https://github.com/tuankiet116/media_social_network

## Overview

##### Main Components
- Backend Framework: Laravel 8, which includes the core “app” folder (controllers, models, middleware, providers) and additional functionalities via Modules.
- Modular Structure: Two main modules – “Modules/Admin” and “Modules/User”. Each module contains its own configuration, controllers, services, routes, entities, migrations, views, assets, and tests.
- Frontend: Vue3 files in the “resources/js” directory, including components (for posts, messaging, communities, user settings, etc.), Vue routes, Vuex store management, SASS/CSS assets, and additional integration with libraries like CKEditor5.
- Database: Migrations and seeders (in “database/migrations” and “database/seeders”) for tables such as users, admins, posts, communities, comments, messages, notifications, video chat, etc.
- External Services & Components:
- Queue system (artisan queue:listen) for asynchronous operations.
- Storage (local file storage in “storage/app/public”) set up with a symbolic link and default images for avatars and backgrounds.
- Integration with Facebook Developer Console indicated by the README configuration requirements.
- Third-party assets like CKEditor5 for rich text editing.

##### File Structure to Extract Architectural Layers
- Presentation Layer:
- Laravel Blade views inside Modules (e.g., “Modules/User/Resources/views”) and in “resources/views”.
- Vue3 components inside “resources/js/components” that handle the interactive frontend.
- Application Layer:
- Controllers in both “app/Http/Controllers” and within each Module’s “Http/Controllers” handle request routing.
- Service classes (in “app/Services/…” and under Modules/User) manage business logic like notifications, messaging, posts, etc.
- Middleware for authentication and other cross-cutting concerns (e.g., “app/Http/Middleware” and module-specific middleware).
- Event handling, jobs, and policies (see Events, Policies, and Console directories) – capturing various interaction flows.
- Data Layer:
- Models in “app/Models”, along with migrations (in “database/migrations”) and seeders (in “database/seeders” and inside Modules).
- Eloquent relationships among users, posts, comments, notifications, etc.
- Infrastructure:
- Configuration files (in “config” folder) define environment settings, database connections, mail, services, and modules.
- Composer and npm package management files (composer.json, package.json) define dependencies.
- Dockerfile and .env.example for containerization and environment configuration.
- Public assets provided in “public” (entry point index.php, favicon, mix-manifest.json).

##### Depicting Relationships and Data Flow
- Backend as various intertwined modules:
- A central Laravel kernel that routes HTTP requests to controllers.
- Admin and User modules as separate bounded contexts that contain distinct MVC layers.
- Requests coming from the browser (client) to the Laravel router.
- Controllers invoking Service classes and Models.
- Event triggers (e.g., in the User module: MessageEvent, NotificationEvent, VideoChat events).
- Communication between the modules, such as common components (services, storage, queue, etc.)
- External calls (e.g., Facebook API integration) and asynchronous operations (via queues).

##### Architectural Patterns and Design Principles
- MVC Pattern: Separate concerns between Models, Views, and Controllers.
- Modularization: Use of “Modules” (Admin and User) clearly segregates responsibilities.
- Service-Oriented Components: Distinct service classes under “app/Services” handle business logic.
- RESTful Routing: Both the “web.php” and “api.php” files in modules and the primary “routes” folder dictate API endpoints.
- Event-driven Architecture: Use of Events to handle messages, notifications, and video chats.
- Clear separation of concerns between frontend assets (Vue components and resources) and backend processing (Laravel controllers, models, etc.).

##### Additional Recommendations
- Since the Modules are extensive, consider grouping sub-components within Admin and User modules (for example, group all controllers, then all routes, etc.) but also show how these groups interact with central components like the Laravel kernel and database.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["User Interface (Vue3 SPA & Blade)"]:::frontend
        VueComp["Vue Components & Assets"]:::frontend
        VueStore["Vuex Store"]:::frontend
    end
    UI -->|"initiates"| VueComp
    VueComp -->|"manages state"| VueStore

    %% Backend Core
    subgraph "Backend Core"
        LaravelCore["Laravel Core Application"]:::backend
        Kernel["HTTP Kernel"]:::backend
    end
    UI -->|"HTTP_Request"| LaravelCore
    LaravelCore -->|"routes_to"| Kernel

    %% Admin Module
    subgraph "Admin Module"
        AdminCtrl["Controllers"]:::backend
        AdminProv["Service Providers"]:::backend
        AdminRoutes["Routes"]:::backend
        AdminViews["Views"]:::backend
    end
    Kernel -->|"admin_request"| AdminCtrl
    AdminCtrl -->|"uses"| AdminProv
    AdminProv -->|"defines"| AdminRoutes
    AdminRoutes -->|"renders"| AdminViews

    %% User Module
    subgraph "User Module"
        UserCtrl["Controllers"]:::backend
        UserMW["Middleware & Requests"]:::backend
        UserRoutes["Routes"]:::backend
        UserViews["Views & Emails"]:::backend
        UserEvents["Events"]:::backend
    end
    Kernel -->|"user_request"| UserCtrl
    UserCtrl -->|"applies"| UserMW
    UserCtrl -->|"routes_to"| UserRoutes
    UserRoutes -->|"renders"| UserViews
    UserViews -->|"triggers"| UserEvents

    %% Data Layer
    subgraph "Data Layer"
        DBMigrations["Database Migrations"]:::database
        DBSeeders["Database Seeders"]:::database
    end
    AdminViews -->|"DB_interact"| DBMigrations
    UserEvents -->|"DB_interact"| DBSeeders

    %% Storage System
    Storage["Local File Storage"]:::infrastructure
    AdminViews -->|"files_to"| Storage
    UserViews -->|"files_to"| Storage

    %% External Services
    subgraph "External Services"
        CKEditor["CKEditor5 Integration"]:::external
        QueueSys["Queue System (Artisan)"]:::external
        Facebook["Facebook_API_Integration"]:::external
    end
    UserMW -->|"integrates"| CKEditor
    Kernel -->|"queues_jobs"| QueueSys
    Kernel -->|"fb_calls"| Facebook

    %% Infrastructure & Configuration
    subgraph "Infrastructure & Configuration"
        EnvConfig["Environment & Service Configs"]:::infrastructure
        DockerEnv["Docker & Environment Setup"]:::infrastructure
        PackageMgmt["Package Management"]:::infrastructure
    end
    LaravelCore -->|"config_loads"| EnvConfig
    EnvConfig -->|"defines"| DockerEnv
    DockerEnv -->|"manages"| PackageMgmt

    %% Click Events
    click LaravelCore "https://github.com/tuankiet116/media_social_network/tree/master/app/"
    click Kernel "https://github.com/tuankiet116/media_social_network/blob/master/app/Http/Kernel.php"
    click AdminCtrl "https://github.com/tuankiet116/media_social_network/tree/master/Modules/Admin/Http/Controllers/"
    click AdminProv "https://github.com/tuankiet116/media_social_network/tree/master/Modules/Admin/Providers/"
    click AdminRoutes "https://github.com/tuankiet116/media_social_network/tree/master/Modules/Admin/Routes/"
    click AdminViews "https://github.com/tuankiet116/media_social_network/tree/master/Modules/Admin/Resources/views/"
    click UserCtrl "https://github.com/tuankiet116/media_social_network/tree/master/Modules/User/Http/Controllers/"
    click UserMW "https://github.com/tuankiet116/media_social_network/tree/master/Modules/User/Http/Middleware/"
    click UserRoutes "https://github.com/tuankiet116/media_social_network/tree/master/Modules/User/Routes/"
    click UserViews "https://github.com/tuankiet116/media_social_network/tree/master/Modules/User/Resources/views/"
    click UserEvents "https://github.com/tuankiet116/media_social_network/tree/master/Modules/User/Events/"
    click VueComp "https://github.com/tuankiet116/media_social_network/tree/master/resources/js/components/"
    click VueStore "https://github.com/tuankiet116/media_social_network/tree/master/resources/js/store/"
    click CKEditor "https://github.com/tuankiet116/media_social_network/tree/master/resources/Libraries/CKEditor5"
    click DBMigrations "https://github.com/tuankiet116/media_social_network/tree/master/database/migrations/"
    click DBSeeders "https://github.com/tuankiet116/media_social_network/tree/master/database/seeders/"
    click Storage "https://github.com/tuankiet116/media_social_network/tree/master/storage/app/public"
    click QueueSys "https://github.com/tuankiet116/media_social_network/blob/master/config/queue.php"
    click EnvConfig "https://github.com/tuankiet116/media_social_network/blob/master/.env.example"
    click DockerEnv "https://github.com/tuankiet116/media_social_network/tree/master/Dockerfile"
    click PackageMgmt "https://github.com/tuankiet116/media_social_network/blob/master/composer.json"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef database fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#d9d2e9,stroke:#333,stroke-width:2px;
```
