# minhduc1706/pawlish-admin architecture

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

- Interactive diagram: https://gitdiagram.com/minhduc1706/pawlish-admin
- Repository: https://github.com/minhduc1706/pawlish-admin

## Overview

##### Project Type and Purpose
- This is a single-page application (SPA) built with React, TypeScript, and Vite.
- It serves as an admin/staff dashboard for a pet care or pet retail management system, providing UIs for appointments, inventory, user management, feedback, reporting, chat, and notifications.
- All “backend” behavior (authentication, data CRUD, real‐time chat) is consumed via HTTP/REST and WebSocket from external services or microservices.

##### High-Level File Structure Analysis
- src/
- App.tsx, main.tsx, index.html: entry points and HTML shell
- api/: Axios-based clients for each domain (appointment, user, inventory, etc.)
- auth/: route protection components
- components/: UI components organized by domain (admin, staff, auth) and low-level UI primitives
- config/: HTTP client & React Query client configuration
- hooks/: custom React hooks wrapping queries & mutations
- queries/: React Query wrapper hooks
- redux/: slice-based global state for auth, chat, search
- store/: root reducer and typed hooks
- interfaces/: TypeScript types for domain entities
- public/: static assets
- config files: vite.config.ts, tsconfig.json, eslint.config.js

##### Key Architectural Patterns & Technologies
- Component-based UI (React TSX)
- Client-side routing with protected routes
- State management:
- React Query for server state (data fetching + caching)
- Redux Toolkit for real-time chat & cross-slice search state
- Network layer: Axios client abstraction + domain service modules in src/api
- Real-time communication: WebSocket (via redux/chat/socket.ts)
- Styling & design system: custom UI primitives under components/ui
- Build & HMR: Vite + @vitejs/plugin-react

a. Frontend (Browser)
- React App
- Component Tree: Top-level Layout → Admin/Staff/UIs
- Router: Auth routes vs. Protected Dashboard routes
- State Layers: React Query & Redux Store
- API Client Layer: axiosClient → domain services
- WebSocket Client (chat)
b. Backend Services (External)
- Auth Service (login/register, JWT)
- REST API Service exposing endpoints for appointments, products, users, etc.
- WebSocket / Chat Service for real-time messaging
- Notification Service (push or polling)
- Possibly third-party services (e.g., payment gateway, email/SMS)
c. Data Stores
- Main relational/NoSQL database behind the REST API
- In-memory cache via React Query
- Redux store slice for chat and search

##### Interactions & Data Flow
- On page load, React App
→ initializes React Query & Redux store
→ renders AuthLayout or DashboardLayout based on JWT presence
- For data views (e.g., Inventory, Dashboard stats):
React Component → custom hook in src/hooks → React Query → Axios client → REST API → JSON → React Query cache → component render
- For chat: WebSocket → redux/chat/socket → dispatch chatSlice updates → Chat UI
- For stateful actions (e.g., login, logout): Redux Thunk → Axios → Auth slice → redirect

##### Essential Elements
- Clear labels: “Browser”, “React App”, “Redux Store”, “React Query Cache”, “REST API”, “WebSocket Server”.

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Presentation Layer"
    direction TB
    ReactEntry1["main.tsx"]:::ui
    ReactEntry2["App.tsx"]:::ui
    HTMLShell["index.html"]:::ui
    CSS["index.css"]:::ui

    subgraph "Components"
      direction TB
      subgraph "Layouts"
        direction TB
        AuthLayout["AuthLayout"]:::ui
        DashboardLayout["DashboardLayout"]:::ui
        AppSidebar["AppSidebar"]:::ui
        DashboardHeader["DashboardHeader"]:::ui
      end
      UIPrimitives["UI Primitives"]:::ui
      AdminModules["Admin Modules"]:::ui
      StaffModules["Staff Modules"]:::ui
      subgraph "Auth Components"
        direction TB
        LoginForm["LoginForm"]:::ui
        RegisterForm["RegisterForm"]:::ui
        AuthToggle["AuthToggle"]:::ui
      end
    end

    ProtectRoute["ProtectRoute"]:::network
  end

  subgraph "Application Layer"
    direction TB
    QueryClient["React Query Client"]:::network
    Hooks["Custom Hooks"]:::state
    Queries["React Query Hooks"]:::state

    subgraph "Redux State"
      direction TB
      AuthSlice["Auth Slice"]:::state
      AuthThunk["Auth Thunk"]:::state
      ChatSlice["Chat Slice"]:::state
      ChatSocketSlice["Chat Socket"]:::network
      SearchSlice["Search Slice"]:::state
    end

    StoreIndex["Store Setup"]:::state
  end

  subgraph "Infrastructure Layer"
    direction TB
    AxiosClient["axiosClient"]:::network
    APIClients["Domain API Clients"]:::network
    WebSocketClient["WebSocket Client"]:::network
  end

  subgraph "External Services"
    direction TB
    AuthService["Auth Service"]:::external
    RESTAPI["REST API Service"]:::external
    ChatWS["Chat WebSocket Server"]:::external
    NotificationService["Notification Service"]:::external
    PaymentGateway["Payment Gateway"]:::external
    Database["Database"]:::external
  end

  %% Connections Presentation -> Application
  ReactEntry2 -->|renders| Components
  ReactEntry2 -->|provides store| StoreIndex
  ReactEntry2 -->|initializes| QueryClient
  ReactEntry2 -->|initializes| StoreIndex
  Components -->|uses protection| ProtectRoute

  %% UI to Application
  UIPrimitives -->|uses| QueryClient
  AdminModules -->|calls hooks| Hooks
  StaffModules -->|calls hooks| Hooks
  LoginForm -->|dispatch login| AuthThunk
  ProtectRoute -->|reads state| AuthSlice

  %% Application internal
  Hooks -->|use| QueryClient
  Queries -->|use| QueryClient
  AuthThunk -->|HTTP| AxiosClient
  ChatSocketSlice -->|WS dispatch| ChatSlice
  StoreIndex -->|combines| AuthSlice
  StoreIndex -->|combines| ChatSlice
  StoreIndex -->|combines| SearchSlice

  %% Application -> Infrastructure
  QueryClient -->|fetch via| AxiosClient
  AxiosClient -->|calls| APIClients
  WebSocketClient -.->|WS CONNECT| ChatWS

  %% Infrastructure -> External
  APIClients -->|HTTP| RESTAPI
  AxiosClient -->|requests| RESTAPI
  WebSocketClient -->|WS messages| ChatWS
  RESTAPI -->|persists| Database
  NotificationService -->|push/poll| RESTAPI
  AxiosClient -->|requests| NotificationService
  AxiosClient -->|requests| PaymentGateway

  %% Caching sync
  AdminModules <-->|cache sync| QueryClient
  StaffModules <-->|cache sync| QueryClient

  %% Click Events
  click ReactEntry1 "https://github.com/minhduc1706/pawlish-admin/blob/main/src/main.tsx"
  click ReactEntry2 "https://github.com/minhduc1706/pawlish-admin/blob/main/src/App.tsx"
  click HTMLShell "https://github.com/minhduc1706/pawlish-admin/blob/main/index.html"
  click CSS "https://github.com/minhduc1706/pawlish-admin/blob/main/src/index.css"
  click AxiosClient "https://github.com/minhduc1706/pawlish-admin/blob/main/src/config/axiosClient.ts"
  click APIClients "https://github.com/minhduc1706/pawlish-admin/tree/main/src/api"
  click QueryClient "https://github.com/minhduc1706/pawlish-admin/blob/main/src/config/queryClient.ts"
  click ProtectRoute "https://github.com/minhduc1706/pawlish-admin/blob/main/src/auth/ProtectRoute.tsx"
  click AuthLayout "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/auth/AuthLayout.tsx"
  click DashboardLayout "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/layout/DashboardLayout.tsx"
  click AppSidebar "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/layout/AppSidebar.tsx"
  click DashboardHeader "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/layout/DashboardHeader.tsx"
  click UIPrimitives "https://github.com/minhduc1706/pawlish-admin/tree/main/src/components/ui"
  click AdminModules "https://github.com/minhduc1706/pawlish-admin/tree/main/src/components/admin"
  click StaffModules "https://github.com/minhduc1706/pawlish-admin/tree/main/src/components/staff"
  click LoginForm "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/auth/LoginForm.tsx"
  click RegisterForm "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/auth/RegisterForm.tsx"
  click AuthToggle "https://github.com/minhduc1706/pawlish-admin/blob/main/src/components/auth/AuthToggle.tsx"
  click Hooks "https://github.com/minhduc1706/pawlish-admin/tree/main/src/hooks"
  click Queries "https://github.com/minhduc1706/pawlish-admin/tree/main/src/queries"
  click AuthSlice "https://github.com/minhduc1706/pawlish-admin/blob/main/src/redux/auth/authSlice.ts"
  click AuthThunk "https://github.com/minhduc1706/pawlish-admin/blob/main/src/redux/auth/authThunk.ts"
  click ChatSlice "https://github.com/minhduc1706/pawlish-admin/blob/main/src/redux/chat/chatSlice.ts"
  click ChatSocketSlice "https://github.com/minhduc1706/pawlish-admin/blob/main/src/redux/chat/socket.ts"
  click SearchSlice "https://github.com/minhduc1706/pawlish-admin/blob/main/src/redux/search/searchSlice.ts"
  click StoreIndex "https://github.com/minhduc1706/pawlish-admin/blob/main/src/store/index.ts"
  click APIClients "https://github.com/minhduc1706/pawlish-admin/tree/main/src/api"
  click Interfaces "https://github.com/minhduc1706/pawlish-admin/tree/main/src/interfaces"
  click Utils "https://github.com/minhduc1706/pawlish-admin/blob/main/src/lib/utils.ts"
  click ChartColors "https://github.com/minhduc1706/pawlish-admin/blob/main/src/lib/chart-colors.ts"
  click Public "https://github.com/minhduc1706/pawlish-admin/tree/main/public/"
  click AuthService "https://github.com/minhduc1706/pawlish-admin/blob/main/config/vite.config.ts"
  click RESTAPI "https://github.com/minhduc1706/pawlish-admin/blob/main/config/tsconfig.json"
  click PaymentGateway "https://github.com/minhduc1706/pawlish-admin/blob/main/eslint.config.js"

  classDef ui fill:#D0E8FF,stroke:#0366d6
  classDef state fill:#DFFFD0,stroke:#228B22
  classDef network fill:#FFE0B2,stroke:#FF8C00,stroke-dasharray: 5 5
  classDef external fill:#E0E0E0,stroke:#555
```
