# phoenix850508/simple-twitter architecture

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

- Interactive diagram: https://gitdiagram.com/phoenix850508/simple-twitter
- Repository: https://github.com/phoenix850508/simple-twitter

## Overview

##### Project type and purpose
- This is a **full-featured React SPA** (Single Page Application) for a Twitter-style client.
- It provides two user flows: a **regular user** (tweet, reply, like, follow, profile) and an **administrator** (view all users, delete tweets).
- It consumes a separate **Twitter API** service (Node.js back-end, not in this repo).

##### File structure
- Top level:
- `public/` → static HTML/CSS/manifest for hosting (GitHub Pages)
- `src/` → source code
– `src/index.js`, `App.jsx` → React root and router setup
– `src/api/` → Axios wrappers for authentication and tweet endpoints
– `src/context/AuthContext.jsx` → global auth state, JWT handling
– `src/components/` → reusable UI pieces (TweetItem, FollowList, Admin panels, Forms)
– `src/pages/` → page-level components (Login, Signup, Home, Main, ReplyList, AdminMain, Setting, User pages)
– `src/styles/`, SCSS modules → styling
- Config/build:
- `package.json`, `.github/workflows/deploy.yml` → CI/CD to GitHub Pages
- `jsconfig.json` → module resolution

##### README
- Confirms React 18, Sass, React-Bootstrap, Axios, jsonwebtoken
- Explains user/admin features and link to back-end repo

##### Main components to illustrate
a. **Client (Browser)** running the React SPA
b. **React Application Layers**
1. **Routing Layer** (`App.jsx` + React Router)
2. **Context/State Layer** (`AuthContext`)
3. **API Layer** (`src/api/auth.js`, `src/api/tweets.js`) using Axios + JWT
4. **UI Layer**
- **Pages** (e.g. `LoginPage`, `HomePage`, `AdminMainPage`)
- **Containers/Components** (TweetCollection, ReplyCollection, FollowList, AdminContainer, etc.)
c. **External Backend Service**
– Twitter API (auth, tweets, users, follows)
– Database (Postgres/Mongo/etc, behind that API)
d. **Build & Deploy Pipeline**
– Webpack build → Static files → GitHub Pages

##### Relationships & data flow
- **User Action** (click, form) → UI Component →
**AuthContext** / local state →
**API call** (Axios → HTTP request, attach JWT) →
**Backend API** → Database → Response →
**API Layer** returns data →
**Context/UI** updates →
**View** re-renders
- Admin flow is identical but uses admin endpoints

##### Architectural patterns & design principles
- **Separation of Concerns**:
- Routing vs. state management vs. API calls vs. presentation
- **Component-Driven Design**: small, reusable UI components assembled into pages
- **Context API** for global auth state (JWT storage and refresh)
- **Module SCSS** for scoped styling

##### Technologies & libraries
- React 18, React Router
- Axios for HTTP
- jsonwebtoken on client side for decoding/attaching tokens
- Sass (SCSS modules) + Bootstrap/React-Bootstrap
- GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        GHActions["GitHub Actions"]
        Build["Webpack Build"]
        Deploy["Deploy to GitHub Pages"]
    end
    GHActions -->|"runs build"| Build
    Build -->|"outputs static files"| Deploy

    %% Client Browser
    Deploy -->|"serve static assets"| Browser["Browser (User)"]

    %% React SPA
    subgraph "React SPA" 
        direction TB
        %% Routing Layer
        subgraph "Routing Layer" 
            direction TB
            Index["src/index.js"]:::front
            AppRouter["src/App.jsx"]:::front
        end

        %% Context/State Layer
        AuthCtx["AuthContext (src/context/AuthContext.jsx)"]:::front

        %% API Layer
        subgraph "API Layer" 
            direction TB
            AuthAPI["auth.js"]:::front
            TweetsAPI["tweets.js"]:::front
        end

        %% UI Layer - Pages
        subgraph "Pages" 
            direction TB
            LoginPage["LoginPage"]:::front
            SignupPage["SignupPage"]:::front
            HomePage["HomePage"]:::front
            MainPage["MainPage"]:::front
            ReplyListPage["ReplyListPage"]:::front
            SettingPage["SettingPage"]:::front
            UserSelfPage["UserSelfPage"]:::front
            UserOtherPage["UserOtherPage"]:::front
            UserSelfFollowPage["UserSelfFollowPage"]:::front
            UserOtherFollowPage["UserOtherFollowPage"]:::front
            AdminMainPage["AdminMainPage"]:::front
            AdminPage["AdminPage"]:::front
            AdminUsersPage["AdminUsersPage"]:::front
        end

        %% UI Layer - Reusable Components
        Components["Components (src/components/)"]:::front

        %% Styling & Assets
        subgraph "Styles & Assets"
            direction TB
            Styles["src/styles/"]:::front
            PublicAssets["public/"]:::front
        end
    end

    %% External Backend
    BackendAPI["External Twitter API"]:::external
    Database["Database"]:::external

    %% Config & Tests
    subgraph "Config & Tests"
        Package["package.json"]:::config
        JSConfig["jsconfig.json"]:::config
        DeployYml[".github/workflows/deploy.yml"]:::config
        SetupTests["src/setupTests.js"]:::config
        AppTest["src/App.test.js"]:::config
    end

    %% Relationships
    Browser -->|"loads SPA"| Index
    Index -->|initializes routing| AppRouter
    AppRouter -->|"renders"| AuthCtx
    AuthCtx -->|"provides auth state"| Pages
    Pages -->|"user interaction"| AuthCtx
    Pages -->|"calls"| AuthAPI
    Pages -->|"calls"| TweetsAPI
    AuthAPI -->|"POST /login, token"| BackendAPI
    TweetsAPI -->|"GET/POST tweets"| BackendAPI
    BackendAPI -->|"queries"| Database
    Database -->|"returns data"| BackendAPI
    BackendAPI -->|"responds JSON"| AuthAPI
    BackendAPI -->|"responds JSON"| TweetsAPI
    Components -->|"used by"| Pages
    Components -->|"used by"| AppRouter
    Styles -->|"styling for"| Pages
    PublicAssets -->|"static files for"| Browser
    Package -->|"defines deps & scripts"| GHActions
    JSConfig -->|"module resolution"| Build
    DeployYml -->|"CI config for"| GHActions
    SetupTests -->|"test setup for"| Build
    AppTest -->|"unit tests for"| Build

    %% Click Events
    click Index "https://github.com/phoenix850508/simple-twitter/blob/main/src/index.js"
    click AppRouter "https://github.com/phoenix850508/simple-twitter/blob/main/src/App.jsx"
    click AuthCtx "https://github.com/phoenix850508/simple-twitter/blob/main/src/context/AuthContext.jsx"
    click AuthAPI "https://github.com/phoenix850508/simple-twitter/blob/main/src/api/auth.js"
    click TweetsAPI "https://github.com/phoenix850508/simple-twitter/blob/main/src/api/tweets.js"
    click LoginPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/LoginPage.jsx"
    click SignupPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/SignupPage.jsx"
    click HomePage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/HomePage.jsx"
    click MainPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/MainPage.jsx"
    click ReplyListPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/ReplyListPage.jsx"
    click SettingPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/SettingPage.jsx"
    click UserSelfPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/UserSelfPage.jsx"
    click UserOtherPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/UserOtherPage.jsx"
    click UserSelfFollowPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/UserSelfFollowPage.jsx"
    click UserOtherFollowPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/UserOtherFollowPage.jsx"
    click AdminMainPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/AdminMainPage.jsx"
    click AdminPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/AdminPage.jsx"
    click AdminUsersPage "https://github.com/phoenix850508/simple-twitter/blob/main/src/pages/AdminUsersPage.jsx"
    click Components "https://github.com/phoenix850508/simple-twitter/tree/main/src/components/"
    click Styles "https://github.com/phoenix850508/simple-twitter/tree/main/src/styles/"
    click PublicAssets "https://github.com/phoenix850508/simple-twitter/tree/main/public/"
    click DeployYml "https://github.com/phoenix850508/simple-twitter/blob/main/.github/workflows/deploy.yml"
    click Package "https://github.com/phoenix850508/simple-twitter/blob/main/package.json"
    click JSConfig "https://github.com/phoenix850508/simple-twitter/blob/main/jsconfig.json"
    click SetupTests "https://github.com/phoenix850508/simple-twitter/blob/main/src/setupTests.js"
    click AppTest "https://github.com/phoenix850508/simple-twitter/blob/main/src/App.test.js"

    %% Styles
    classDef front fill:#cce5ff,stroke:#004085,color:#004085
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24
    classDef config fill:#d4edda,stroke:#155724,color:#155724
    classDef pipeline fill:#fff3cd,stroke:#856404,color:#856404
```
