# luannguyenthien/ssmedia-fe architecture

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

- Interactive diagram: https://gitdiagram.com/luannguyenthien/ssmedia-fe
- Repository: https://github.com/luannguyenthien/ssmedia-fe

## Overview

##### Project type and purpose
- This is a Single-Page Application (SPA) front end built with React, Vite, and Tailwind/PostCSS.
- It implements a social-media-style UI: chat, posts, notifications, profiles, admin dashboard, etc.
- It uses Redux Toolkit for state, a mock server for local API development, and real HTTP/WebSocket services for production.

##### File structure
- Top-level build & orchestrator files: Dockerfile, docker-compose.yml, Vite & ESLint configs.
- `/src` contains:
- `main.jsx` & `index.html` entrypoints
- `pages/` – routed pages (auth, social, admin, error)
- `components/` – UI building blocks (cards, buttons, chat window, modals, header, sidebar…)
- `redux-toolkit/` – API slices & reducers, global `store.js`
- `services/` – API clients (axios, REST services under `/api/*`) and a Socket service
- `hooks/` – reusable React hooks
- `mocks/` – MSW server, handlers & fake data for local dev/testing
- Build & deploy concerns: Docker, GitHub Actions CI, ESLint, PostCSS, Tailwind, Vite build.

##### Key architecture insights from README
- Vite + React fast-refresh dev server
- ESLint config for code quality
- Suggestion to extend into TS for production (not presently used)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Browser
    Browser(["Browser (SPA)"]):::external

    %% Dev Server & Mock
    subgraph "Development Environment" 
        direction TB
        ViteConfig["Vite Dev Server<br/>(vite.config.js)"]:::dev
        MSWServer["MSW Mock Server<br/>(server.js)"]:::dev
        Handlers["Request Handlers<br/>(src/mocks/handlers/)"]:::dev
        MockData["Fake Data<br/>(src/mocks/data/)"]:::dev
    end

    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        MainEntrypoint["main.jsx"]:::ui
        AppComp["App.jsx"]:::ui
        Routes["routes.jsx"]:::ui
        Pages["Routed Pages<br/>(src/pages/)"]:::ui
        Components["Reusable Components<br/>(src/components/)"]:::ui
        HTMLTemplate["index.html"]:::ui
    end

    %% State Layer
    subgraph "State Layer" 
        direction TB
        Store["store.js"]:::state
        APISlices["API Slices<br/>(src/redux-toolkit/api/)"]:::state
        Reducers["Feature Reducers<br/>(src/redux-toolkit/reducers/)"]:::state
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        Axios["Axios HTTP Client<br/>(axios.js)"]:::service
        RESTServices["REST API Services<br/>(src/services/api/)"]:::service
        SocketSrv["WebSocket Client<br/>(socket.service.js)"]:::service
        Utils["Service Utilities<br/>(src/services/utils/)"]:::service
    end

    %% External Backends
    subgraph "External Services" 
        direction TB
        RESTAPI(["REST API Backend"]):::external
        WebSocket(["WebSocket Server"]):::external
    end

    %% DevOps / CI-CD
    subgraph "DevOps & CI/CD"
        direction TB
        GitHubActions["GitHub Actions<br/>(.github/workflows/docker-image.yml)"]:::infra
        DockerfileNode["Dockerfile"]:::infra
        Compose["docker-compose.yml"]:::infra
    end

    %% Connections
    Browser -->|loads via| ViteConfig
    Browser -- HMR/Assets --> ViteConfig
    Browser -->|intercepts calls in dev| MSWServer
    MSWServer --> Handlers
    MSWServer --> MockData

    Browser --> MainEntrypoint
    MainEntrypoint --> AppComp
    AppComp --> Routes
    AppComp --> Components
    Routes --> Pages

    Components -->|dispatch actions| Store
    Pages -->|dispatch actions| Store
    Store --> APISlices
    Store --> Reducers

    APISlices -->|invoke| Axios
    Reducers -->|update state| AppComp

    Axios --> RESTServices
    RESTServices -->|HTTP| RESTAPI
    SocketSrv -->|WS| WebSocket
    AppComp -->|init WS| SocketSrv

    GitHubActions --> DockerfileNode
    GitHubActions --> Compose

    %% Click Events
    click MainEntrypoint "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/main.jsx"
    click AppComp "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/App.jsx"
    click Routes "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/routes.jsx"
    click Pages "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/pages/"
    click Components "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/components/"
    click HTMLTemplate "https://github.com/luannguyenthien/ssmedia-fe/blob/main/index.html"

    click Store "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/redux-toolkit/store.js"
    click APISlices "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/redux-toolkit/api/"
    click Reducers "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/redux-toolkit/reducers/"

    click Axios "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/services/axios.js"
    click RESTServices "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/services/api/"
    click SocketSrv "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/services/socket/socket.service.js"
    click Utils "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/services/utils/"

    click MSWServer "https://github.com/luannguyenthien/ssmedia-fe/blob/main/src/mocks/server.js"
    click Handlers "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/mocks/handlers/"
    click MockData "https://github.com/luannguyenthien/ssmedia-fe/tree/main/src/mocks/data/"

    click ViteConfig "https://github.com/luannguyenthien/ssmedia-fe/blob/main/vite.config.js"
    click PostCSS "https://github.com/luannguyenthien/ssmedia-fe/blob/main/postcss.config.js"
    click Tailwind "https://github.com/luannguyenthien/ssmedia-fe/blob/main/tailwind.config.js"
    click ESLint "https://github.com/luannguyenthien/ssmedia-fe/blob/main/eslint.config.js"

    click DockerfileNode "https://github.com/luannguyenthien/ssmedia-fe/tree/main/Dockerfile"
    click Compose "https://github.com/luannguyenthien/ssmedia-fe/blob/main/docker-compose.yml"
    click GitHubActions "https://github.com/luannguyenthien/ssmedia-fe/blob/main/.github/workflows/docker-image.yml"

    %% Styles
    classDef ui fill:#e0f7fa,stroke:#006064
    classDef state fill:#e8f5e9,stroke:#2e7d32
    classDef service fill:#fff3e0,stroke:#ef6c00
    classDef dev fill:#f3e5f5,stroke:#6a1b9a,stroke-dasharray: 5 5
    classDef external fill:#ffebee,stroke:#c62828
    classDef infra fill:#eceff1,stroke:#455a64
```
