# nguyentruongvietbao/swd392_client architecture

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

- Interactive diagram: https://gitdiagram.com/nguyentruongvietbao/swd392_client
- Repository: https://github.com/nguyentruongvietbao/swd392_client

## Overview

##### Identifying the Project Type and Purpose
- This is a frontend-focused single-page application (SPA) built using React in combination with Vite.
- The README clarifies that the project is a minimal React + Vite setup with hot module replacement (HMR) enabled via official plugins.
- The extensive file structure under “src” shows multiple pages and components which indicate that the application supports role-based views (e.g., admin, advertiser, publisher, and authentication flows).

##### Analyzing the File Structure
- Top-Level Files: The presence of configuration files such as vite.config.js, eslint.config.js, package.json, and .env illustrates that standard development tools and environment configuration are in use.
- Public Assets: The “public” and “index.html” files serve as the entry point for the browser.
- Components, Pages, and Routes:
- The “src/components” folder holds reusable UI elements like the Navbar, Loading spinners, and a specialized authentication image.
- The “src/pages” folder is subdivided into areas for different user roles (admin, advertiser, publisher) and authentication (Login, Register pages). This setup clearly supports multi-role navigation and access control.
- The “src/routes” folder includes both a ProtectedRoute component and an index to organize routing logic. This is key in showing the flow of authentication and authorization.
- Libraries and Constants:
- The “src/lib” folder contains an axiosInstance, implying that API communication is a critical part of the application.
- The “src/constants” hold application-wide enums and theme definitions.
- State Management:
- The “src/store” folder contains custom hooks (e.g., useAuthStore, useThemeStore) that manage application state, likely for tracking user sessions and UI states (like themes).

a. Main Components:
- Browser/Client: Represents the running application served by “index.html”.
- React App Container: Your top-level “App.jsx” that incorporates routing and global components like Navbar.
- Routing Layer: Illustrate the “src/routes” components (ProtectedRoute.jsx, index.jsx) that manage page-level access.
- Page Components: Segregate pages by user roles (admin, advertiser, publisher, auth, error, home, etc.) according to the “src/pages” directory.
- API Interaction: Show the “axiosInstance” in the “src/lib” directory which handles backend communication (even though the backend isn’t part of this repository, it’s a part of the data flow).
- State Management: Represent custom hooks such as useAuthStore and useThemeStore, which govern authentication and theme state.

b. Relationships and Interactions:
- From the Browser to the React App (via “index.html” loading “main.jsx”).
- Within the App, show how the Routing Layer directs users to different Page Components.
- That the ProtectedRoute components help secure routes based on authentication state provided by useAuthStore.
- Communication from Page or Component levels to the API layer via the axiosInstance.
- How global constants and themes are accessed throughout the app.

c. Architectural Patterns and Design Principles:
- Component-Based Architecture: Emphasize the modularity evident from distinct UI components.
- Separation of Concerns: Highlight that routes, state management, API handling, and UI are all separated into different directories.
- Role-Based Access: Since there are specific folders for admin, advertiser, and publisher, make it clear that the application follows a multi-role design with potentially distinct workflows.
- State and Context Management: Note the use of custom hooks for centralized state management.

d. Relevant Technologies:
- React for UI development.
- Vite as the build tool and development server.
- ESLint for code linting and quality.
- Axios (via a custom axiosInstance) for handling API requests.
- Possibly a library for state management (custom hooks, perhaps built on top of React Context or Zustand).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Browser/Client"]:::browser
    B["index.html"]:::browser
    C["main.jsx"]:::app
    D["App.jsx"]:::app
    E["UI Components (Navbar, Loading, AuthImagePattern)"]:::ui
    F["Routing Layer (index.jsx, ProtectedRoute.jsx)"]:::routing
    G["Page Components (admin, advertiser, publisher, auth)"]:::pages
    H["API Interaction (axiosInstance)"]:::api
    I["State Management (useAuthStore, useThemeStore)"]:::state
    J["Global Constants (enums, themes)"]:::constants

    A -->|"loads"| B
    B -->|"parses"| C
    C -->|"initiates"| D
    D -->|"includes"| E
    D -->|"includes"| F
    F -->|"routes-to"| G
    G -->|"triggers-API"| H
    F -->|"protected-by"| I
    G -->|"accesses"| I
    D -->|"applies-themes-from"| J

    click B "https://github.com/nguyentruongvietbao/swd392_client/blob/master/index.html"
    click C "https://github.com/nguyentruongvietbao/swd392_client/blob/master/src/main.jsx"
    click D "https://github.com/nguyentruongvietbao/swd392_client/blob/master/src/App.jsx"
    click E "https://github.com/nguyentruongvietbao/swd392_client/tree/master/src/components"
    click F "https://github.com/nguyentruongvietbao/swd392_client/tree/master/src/routes"
    click G "https://github.com/nguyentruongvietbao/swd392_client/tree/master/src/pages"
    click H "https://github.com/nguyentruongvietbao/swd392_client/blob/master/src/lib/axiosInstance.js"
    click I "https://github.com/nguyentruongvietbao/swd392_client/tree/master/src/store"
    click J "https://github.com/nguyentruongvietbao/swd392_client/tree/master/src/constants"

    classDef browser fill:#AED6F1,stroke:#1B4F72,stroke-width:2px,color:#1B2631;
    classDef app fill:#D5F5E3,stroke:#1E8449,stroke-width:2px,color:#145A32;
    classDef ui fill:#85C1E9,stroke:#2874A6,stroke-width:2px,color:#154360;
    classDef routing fill:#ABEBC6,stroke:#138D75,stroke-width:2px,color:#0B5345;
    classDef pages fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:#7D6608;
    classDef api fill:#F5B7B1,stroke:#C0392B,stroke-width:2px,color:#641E16;
    classDef state fill:#FAD7A0,stroke:#D35400,stroke-width:2px,color:#7E5109;
    classDef constants fill:#D2B4DE,stroke:#6C3483,stroke-width:2px,color:#512E5F;
```
