How ngantrandev/vehicle-repair-shop-web works
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.