# ngantrandev/vehicle-repair-shop-web architecture

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

- Interactive diagram: https://gitdiagram.com/ngantrandev/vehicle-repair-shop-web
- Repository: https://github.com/ngantrandev/vehicle-repair-shop-web

## Overview

##### Main Components
- User Interface (UI) Layer:
– Frontend built with React (Vite as the build tool).
– Presentation and Layouts: Several layout directories (DefaultLayout, HomeLayout, SidebarLayout, and FreeLayout) organize the overall view.
– Page Components: Under “src/components/pages”, you have pages for Login, Register, Home, Service Detail, Booking (for users and admin), Profile, etc.
– Reusable UI components: Buttons, inputs, images, dropdowns, breadcrumbs, popups, etc.

- Routing and Navigation:
– Routing is handled in “src/routes” with components like ProtectedRoute that ensures authentication and role-specific navigation.
– Layouts and sidebar/menu components in “src/layouts” encapsulate navigation elements like header, sidebar, and menu.

- State Management & Context:
– User and Breadcrumb contexts (located in “src/context”) manage global state.
– Custom hooks (under “src/hooks”) for common functionalities like debouncing events or user data fetching.

- Service Layer / API Integration:
– The “src/services” folder contains modules for making HTTP requests to the backend API (with URLs provided in environment variables). Examples include authService, bookingService, profileService, and admin-related services.
– Utility functions for HTTP requests and common functions in “src/ultils”.

- External Service Integration:
– Integration of Goong Map React for mapping services, as noted in the README and the “src/components/map/GoongMap.jsx” component.

- Build and Configuration:
– Configuration files and build settings (e.g., vite.config.js, tailwind.config.js, postcss.config.js) that support the development and deployment pipeline.
– Environment configuration is managed through a .env file for API endpoints and Goong Map API keys.

##### Relationships and Interactions
- UI components interact with the routing layer to render proper pages based on URL and user role.
- Page components leverage layout components (header, sidebar) to provide a consistent look and navigation experience.
- The visual components connect to the service layer to request or send data (e.g., booking or user data) over the network.
- Service modules interact with external APIs (the backend API as well as Goong Map services) via HTTP calls.
- Global context providers (UserProvider, BreadcrumbsProvider) wrap around large parts of the UI to share state and enable authentication and navigation breadcrumbs across the application.

##### Architectural Patterns and Design Principles
- Component-Based Architecture (separation of concerns):
– The application is broken into small, reusable React components, making use of higher-order components (e.g., ProtectedRoute) to handle authentication.
- Separation of Presentation, Business Logic, and Data Access:
– Presentation (React components and layouts),
– Data Access via service modules that encapsulate network calls,
– Global state/context for application-wide data management.
- Modular Folder Structure:
– Each “feature” (booking, service, staff, admin) is organized into its own subdirectory, promoting clarity and ease of maintenance.
- Consistent use of environment variables and configuration to drive external API interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI1("Page Components (Login, Register, Home, Service Detail, Booking, Profile, etc.)"):::ui
        UI2("Reusable UI Components"):::ui
        UI3("Assets"):::ui
    end

    %% Routing and Navigation
    subgraph "Routing and Navigation"
        ROUTE("Routing Components"):::routing
        NAV("Layouts & Navigation Elements"):::routing
    end

    %% State Management & Context
    subgraph "State Management & Context"
        CONTEXT("Global Context (UserProvider, BreadcrumbsProvider)"):::state
        HOOKS("Custom Hooks (useDebounce, useUser, useBreadcrumbs)"):::state
    end

    %% Service / API Layer
    subgraph "Service/API Layer"
        SERVICE("Service Modules (authService, bookingService, profileService, etc.)"):::service
        UTIL("Utility Functions (httpRequest, ultils)"):::service
    end

    %% External Services
    subgraph "External Services"
        BACKEND("Backend API"):::external
        GMAPC("Goong Map Component"):::external
        GMAPS("Goong Map Service"):::external
    end

    %% Build and Configuration
    subgraph "Build and Configuration"
        CONFIG1("vite.config.js"):::config
        CONFIG2("tailwind.config.js"):::config
        CONFIG3("postcss.config.js"):::config
        ENV("Environment (.env)"):::config
    end

    %% Connections between layers
    CONTEXT -->|"providesState"| UI1
    HOOKS -->|"enhancesUI"| UI1
    UI2 -->|"usedIn"| UI1
    UI3 -->|"usedIn"| UI1
    UI1 -->|"navigates"| ROUTE
    UI1 -->|"rendersLayout"| NAV
    UI1 -->|"triggersAPI"| SERVICE
    UI1 -->|"rendersMap"| GMAPC
    SERVICE -->|"calls"| BACKEND
    SERVICE -->|"integratesMapAPI"| GMAPS
    UTIL -->|"supports"| SERVICE
    ROUTE -->|"checksAuth"| CONTEXT

    %% Configuration influences
    CONFIG1 -->|"buildsUI"| UI1
    CONFIG2 -->|"stylesUI"| UI1
    CONFIG3 -->|"processesCSS"| UI1
    ENV -->|"configuresEndpoints"| SERVICE
    ENV -->|"providesAPIKeys"| GMAPS

    %% Styles
    classDef ui fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef routing fill:#ffcc80,stroke:#fb8c00,stroke-width:2px;
    classDef state fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef service fill:#d1c4e9,stroke:#7e57c2,stroke-width:2px;
    classDef external fill:#ffe082,stroke:#ffa000,stroke-width:2px;
    classDef config fill:#f8bbd0,stroke:#c2185b,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/components/pages"
    click UI2 "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/components"
    click UI3 "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/assets"
    click ROUTE "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/routes"
    click NAV "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/layouts"
    click CONTEXT "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/context"
    click HOOKS "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/hooks"
    click SERVICE "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/services"
    click UTIL "https://github.com/ngantrandev/vehicle-repair-shop-web/tree/main/src/ultils"
    click GMAPC "https://github.com/ngantrandev/vehicle-repair-shop-web/blob/main/src/components/map/GoongMap.jsx"
    click GMAPS "https://github.com/ngantrandev/vehicle-repair-shop-web/blob/main/src/services/goongMapService.js"
    click CONFIG1 "https://github.com/ngantrandev/vehicle-repair-shop-web/blob/main/vite.config.js"
    click CONFIG2 "https://github.com/ngantrandev/vehicle-repair-shop-web/blob/main/tailwind.config.js"
    click CONFIG3 "https://github.com/ngantrandev/vehicle-repair-shop-web/blob/main/postcss.config.js"
    click ENV "https://github.com/ngantrandev/vehicle-repair-shop-web/blob/main/.env"
```
