# kenchiwar/fe-invetory architecture

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

- Interactive diagram: https://gitdiagram.com/kenchiwar/fe-invetory
- Repository: https://github.com/kenchiwar/fe-invetory

## Overview

##### Project Type and Purpose
- This is a front-end single-page application (SPA) built with React and TypeScript using Vite as the bundler. It leverages redux with redux-thunk for state management and async API calls.
- The project is structured to render multiple pages (e.g., Home, BrandList, CurrentStock, NotFound) with a clear division of components, layout, API service calls, and state management.

##### Main Components
- UI Layer:
- React Components: Represented by files under src/Components and src/components (note the distinction in naming conventions).
- Layout & Page Components: Look at src/Components/Layout (e.g., MainLayout.tsx, TestRedux) and src/pages (e.g., Home, BrandList, CurrentStock, NotFound).
- Routing:
- Central routing defined in the src/routes.tsx file, which connects pages/components.
- Additional routing helper functions in src/helper/routerHelper.ts.
- API Service Layer:
- API handler files under src/api (such as api-service.ts, axios-instance.ts, base-service.ts, brand-service.ts, current-stock-service.ts, query-builder.ts).
- These components encapsulate logic to communicate with external backend endpoints.
- State Management:
- Redux Store and Reducers: Found in src/redux (with reducers for Brand, CurrentStock, Loading, and a general BaseApi reducer).
- redux-thunk is used to handle asynchronous API calls (as mentioned in the README).
- Constants & Styles:
- Constants defined in src/constants (for endpoints and HTTP statuses).
- Styling is managed through src/styles (SCSS and Tailwind CSS styles).

##### Indicating Relationships and Interactions
- UI components (presentational) interact with the Redux store:
- Dispatch actions (via redux-thunk) when user events occur.
- Actions call the API service layer to retrieve or update data.
- API Services:
- They abstract away HTTP calls (using axios-instance) and expose methods to various parts of the application.
- Redux Flow:

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Clearly separated layers for presentation (React components/pages), business logic (Redux actions/thunks), API interactions, and styling.
- Modular Design:
- Each domain (e.g., Brand, CurrentStock) has dedicated components, reducers, and services.
- Use of Aliases:
- As noted in the README (“nhớ coi mấy cái alias để xài // @compnents kiểu vậy đó”), indicating that care should be taken to clearly denote module boundaries.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "UI Components"
        UCC1["Components Dir (src/Components)"]:::ui
        UCC2["Components Dir (src/components)"]:::ui
        UIL["Layout Components (src/Components/Layout)"]:::ui
        UIP["Page Components (src/pages)"]:::ui
    end

    subgraph "Routing"
        RouteMain["Main Routing (src/routes.tsx)"]:::routing
        RouteHelp["Routing Helper (src/helper/routerHelper.ts)"]:::routing
    end

    subgraph "Redux & State Management"
        ReduxStore["Redux Store (src/redux/store.ts)"]:::redux
        ReduxReducers["Redux Reducers (src/redux/reducers)"]:::redux
        ReduxThunk["redux-thunk Middleware"]:::redux
        ReduxTypes["Redux Types (src/redux/types.ts)"]:::redux
    end

    subgraph "API Services"
        API1["api-service (src/api/api-service.ts)"]:::api
        API2["axios-instance (src/api/axios-instance.ts)"]:::api
        API3["base-service (src/api/base-service.ts)"]:::api
        API4["brand-service (src/api/brand-service.ts)"]:::api
        API5["current-stock-service (src/api/current-stock-service.ts)"]:::api
        API6["query-builder (src/api/query-builder.ts)"]:::api
    end

    subgraph "Resources"
        Constants["Constants (src/constants/endpoint.ts & httpStatus.ts)"]:::resources
        Styling["Styles (src/styles/scss & taildwind.css)"]:::resources
    end

    %% UI dispatches actions to Redux Thunk
    UCC1 -->|"dispatch"| ReduxThunk
    UCC2 -->|"dispatch"| ReduxThunk
    UIL -->|"dispatch"| ReduxThunk
    UIP -->|"dispatch"| ReduxThunk

    %% Routing directs navigation to Page Components
    RouteMain -->|"renders"| UIP
    RouteHelp -->|"assists"| RouteMain

    %% Redux Thunk calls the API Service layer
    ReduxThunk -->|"calls"| API1
    API1 -->|"returns"| ReduxThunk

    %% Redux flow: Thunk updates Reducers then commits to Store
    ReduxThunk -->|"updates"| ReduxReducers
    ReduxReducers -->|"commits state"| ReduxStore
    ReduxStore -->|"triggers re-render"| UIL
    ReduxStore -->|"triggers re-render"| UIP

    %% API Service layer dependencies
    API1 -->|"uses"| API2
    API1 -->|"uses"| API3
    API1 -->|"uses"| API4
    API1 -->|"uses"| API5
    API1 -->|"uses"| API6

    %% Resources supply styles and constants to UI components
    Constants -->|"provides"| UIL
    Constants -->|"provides"| UIP
    Styling -->|"styles"| UIL
    Styling -->|"styles"| UIP

    %% Classes for styling nodes
    classDef ui fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef routing fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef redux fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef api fill:#FADBD8,stroke:#CB4335,stroke-width:2px;
    classDef resources fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;

    %% Click Events for UI Components
    click UCC1 "https://github.com/kenchiwar/fe-invetory/tree/main/src/Components"
    click UCC2 "https://github.com/kenchiwar/fe-invetory/tree/main/src/components"
    click UIL "https://github.com/kenchiwar/fe-invetory/tree/main/src/Components/Layout"
    click UIP "https://github.com/kenchiwar/fe-invetory/tree/main/src/pages"

    %% Click Events for Routing
    click RouteMain "https://github.com/kenchiwar/fe-invetory/blob/main/src/routes.tsx"
    click RouteHelp "https://github.com/kenchiwar/fe-invetory/blob/main/src/helper/routerHelper.ts"

    %% Click Events for API Services
    click API1 "https://github.com/kenchiwar/fe-invetory/blob/main/src/api/api-service.ts"
    click API2 "https://github.com/kenchiwar/fe-invetory/blob/main/src/api/axios-instance.ts"
    click API3 "https://github.com/kenchiwar/fe-invetory/blob/main/src/api/base-service.ts"
    click API4 "https://github.com/kenchiwar/fe-invetory/blob/main/src/api/brand-service.ts"
    click API5 "https://github.com/kenchiwar/fe-invetory/blob/main/src/api/current-stock-service.ts"
    click API6 "https://github.com/kenchiwar/fe-invetory/blob/main/src/api/query-builder.ts"

    %% Click Events for Redux
    click ReduxStore "https://github.com/kenchiwar/fe-invetory/blob/main/src/redux/store.ts"
    click ReduxReducers "https://github.com/kenchiwar/fe-invetory/tree/main/src/redux/reducers"
    click ReduxTypes "https://github.com/kenchiwar/fe-invetory/blob/main/src/redux/types.ts"

    %% Click Events for Resources
    click Constants "https://github.com/kenchiwar/fe-invetory/blob/main/src/constants/endpoint.ts"
    click Styling "https://github.com/kenchiwar/fe-invetory/blob/main/src/styles/taildwind.css"
```
