# thaitamtzer/daitongquan_fe architecture

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

- Interactive diagram: https://gitdiagram.com/thaitamtzer/daitongquan_fe
- Repository: https://github.com/thaitamtzer/daitongquan_fe

## Overview

##### Project Type & Purpose
- This is a Next.js + React + TypeScript front-end application (“SGOD-DAITONGQUAN-FE”) that implements a rich admin/dashboard interface (“đại tổng quản”).
- It uses Material-UI (MUI) for styling, Next.js for SSR/SSG and routing, Axios for REST calls, and a custom state management layer under `/store`.

##### File Structure Analysis
- Top-level “client” directory holds everything:
- `/public`: static assets (images, locales)
- `/src`: source code, divided into
– `@core`: shared UI components, layouts, theming, utilities
– `@fake-db`: mock data for local dev
– `app` & `pages`: Next.js routing (app directory or pages directory)
– `configs`: global configuration (ACL, auth, theme, i18n)
– `context` & custom `hooks`: React Contexts (AuthContext), settings, clipboard, debounce
– `layouts` & `views`: higher-level page skeletons and detailed views for apps, dashboards, forms, etc.
– `service`: Axios-based API clients for each domain (users, invoices, chat, categories, stats…)
– `store`: application state (per feature) using a custom store pattern
– `types`: TypeScript interfaces for props, data models, APIs
- Config files: `next.config.{js,mjs}`, `tsconfig.json`, `tailwind.config.ts`, ESLint, Prettier, etc.

a. Next.js Application (SSR/CSR)
- Entry points: `pages/_app.tsx`, `app/layout.tsx`
- Routing: `pages/*` or `app/*` directory
b. UI Layer
- Views: `/src/views` – compose UI building blocks
- Pages: `/src/pages` – route-driven entry
- Core Components: `/src/@core/components` – generic controls (cards, checkboxes, navguards)
- Theming: `/src/@core/theme`, `/src/styles`, MUI overrides
c. State Management
- `/src/store`: per-feature stores (calendar, chat, email, invoice…)
- Context: `/src/context/AuthContext.tsx` for authentication state
d. Service Layer
- `/src/service/*`: Axios clients calling external REST API
- `/src/lib/axios.ts`: central Axios instance (baseURL, interceptors)
e. Data Flow & External Dependencies
- External API Server (backend endpoints for auth, data fetch, mutations)
- i18n JSON files under `/public/locales`
- CDN or hosting static assets (`/public/images`)

##### Relationships & Interactions
- Pages → Views → Core Components: UI composition
- Pages & Views dispatch actions to Store → update global state
- Service Layer called by Store or directly in hooks → HTTP calls to backend
- Context Providers wrap App → supply Auth and Settings to all components
- Next.js SSR/SSG pipeline fetches data (getServerSideProps, getStaticProps) → hydrates UI

##### Architectural Patterns & Principles
- Component-based architecture (Atomic to Composite)
- Separation of Concerns:
- UI (views/components) vs. Business logic (service) vs. State (store/context)
- DRY + Theming: centralized theme config and overrides
- Type safety with TypeScript (`/src/types`)

##### Essential Elements to Capture
- Next.js routing layer and entry points
- Core component library vs. feature-specific view components
- State management topology (per-feature stores + global context)
- API integration via Axios services
- Static hosting for public assets and localization files

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Next.js Application
    subgraph "Next.js Application"
        NextAppEntry1["_app.tsx"]:::entry
        NextAppEntry2["layout.tsx"]:::entry
    end

    %% UI Layer
    subgraph "UI Layer" 
        Pages["Pages Directory"]:::ui
        AppRouter["App Directory (App Router)"]:::ui
        CoreComponents["Core UI Components"]:::ui
        ThemeConfig["Theme Config & Overrides"]:::ui
        Layouts["Shared Layouts"]:::ui
        Views["Views (Feature UIs)"]:::ui
    end

    %% State Layer
    subgraph "State & Context"
        Store["Store (Feature Stores)"]:::state
        AuthContext["Auth Context"]:::state
        SettingsContext["Settings Context"]:::state
    end

    %% Service Layer
    subgraph "Service Layer"
        AxiosInstance["Axios Instance"]:::service
        RestClients["Domain API Services"]:::service
    end

    %% Static Assets & Configs
    subgraph "Static Assets & Configs"
        Types["TypeScript Types"]:::static
        Images["Public Images"]:::static
        Locales["Locale JSON Files"]:::static
        Configs["Configuration Files"]:::static
    end

    %% External Backend
    ExternalAPI["External API Server"]:::external

    %% Relationships
    NextAppEntry1 -->|"wraps"| Pages
    NextAppEntry2 -->|"wraps"| AppRouter
    Pages -->|"compose UI"| Views
    AppRouter -->|"compose UI"| Views
    Views -->|"use core"| CoreComponents
    Views -->|"use layouts"| Layouts
    CoreComponents -->|"theme overrides"| ThemeConfig
    Pages -->|"dispatch/read"| Store
    Views -->|"dispatch/read"| Store
    Store -->|"calls via"| RestClients
    RestClients -->|"through"| AxiosInstance
    RestClients -->|"HTTP calls"| ExternalAPI
    AuthContext -->|"provides auth"| Pages
    SettingsContext -->|"provides settings"| Pages
    AxiosInstance -->|"intercepts"| RestClients

    %% Static & Configs usage
    CoreComponents -->|"types"| Types
    Views -->|"types"| Types
    Configs -->|"applies to"| ThemeConfig
    Images -->|"served to"| Pages
    Locales -->|"i18n for"| Pages

    %% Click Events
    click NextAppEntry1 "https://github.com/thaitamtzer/daitongquan_fe/blob/main/client/src/pages/_app.tsx"
    click NextAppEntry2 "https://github.com/thaitamtzer/daitongquan_fe/blob/main/client/src/app/layout.tsx"
    click Pages "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/pages"
    click AppRouter "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/app"
    click CoreComponents "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/@core/components"
    click ThemeConfig "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/@core/theme"
    click Layouts "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/@core/layouts"
    click Views "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/views"
    click Store "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/store"
    click AuthContext "https://github.com/thaitamtzer/daitongquan_fe/blob/main/client/src/context/AuthContext.tsx"
    click SettingsContext "https://github.com/thaitamtzer/daitongquan_fe/blob/main/client/src/@core/context/settingsContext.tsx"
    click AxiosInstance "https://github.com/thaitamtzer/daitongquan_fe/blob/main/client/src/lib/axios.ts"
    click RestClients "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/service"
    click Types "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/types"
    click Images "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/public/images"
    click Locales "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/public/locales"
    click Configs "https://github.com/thaitamtzer/daitongquan_fe/tree/main/client/src/configs"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef state fill:#E6FFCC,stroke:#2E7D32,color:#2E7D32
    classDef service fill:#FFE1B3,stroke:#FF8C00,color:#FF8C00
    classDef static fill:#F0F0F0,stroke:#A0A0A0,color:#606060
    classDef entry fill:#CDEFFD,stroke:#0284C7,color:#0284C7
    classDef external fill:#FFD6D6,stroke:#D32F2F,color:#D32F2F
```
