How nguyenvananit/booking-hotel-frontend works
Project Type and Purpose
• This is a single-page front-end application (“Manage-Hotel-Frontend”) built in React and bundled by Vite.
• Its purpose is to provide a user interface for hotel management: user registration/login, room booking, staff management, services management, reporting/statistics, etc.
File Structure Analysis
• Top level:
• public, index.html – static assets and SPA entry point
• src – all React code, styles and configuration (main.jsx, App.jsx/CSS)
• vite.config.js, package*.json, eslint.config.js, vercel.json – build, lint, deploy configs
• src/components organized by functional domains:
• auth (AuthProvider, Login, Logout, RequireAuth, Profile, Registration)
• booking (BookingList, BookingForm, Checkout, Payment, BookingSuccess, etc.)
• room (DetailRoom, RoomListing, RoomCard, ServicesOfRoom, EditRoom)
• staff (StaffList, AddStaff, StaffTask, AssignWork/Task, TimeKeeping)
• service (ServiceList, AddService, ServiceInRoom)
• statistics (StatisticMain, StatisticRoom/Staff/Rate)
• user (UserList)
• common (DateSlider, Header, Parallax, Filters, Paginator, Modals, etc.)
• utils (ApiFunctions.js & domain-specific API wrappers: booking.js, room.js, staff.js, etc.)
• State management: uses React Context for authentication (AuthProvider) and likely local component state for other domains.
a. Front-End Components Layer
• Browser/Client running React SPA
• Main entry: index.html → main.jsx → App.jsx
• Component modules (Auth, Booking, Room, Staff, Service, Statistics, Common)
• Shared utilities: ApiFunctions.js wraps fetch/XHR to back-end endpoints
b. Build/Deployment Layer
• Vite Dev Server (HMR) for local development
• Build output (static JS/CSS) deployed to CDN or Vercel (per vercel.json)
c. External Services & Back-End
• Authentication service (internal API routes: /login, /register, /logout, /profile)
• Hotel management REST API (endpoints for rooms, bookings, staff, services, statistics)
• Database (MySQL/Postgres/Mongo) behind back-end
• Payment Gateway (calls from Checkout/Payment components)
d. Data Flow
1. User interacts with React components → triggers handlers in BookingForm, Login, etc.
2. Handlers call domain utils (e.g., booking.js → ApiFunctions.post('/bookings', data)).
3. API request goes over HTTP to back-end → database read/write → JSON response.
4. Response bubbles up to components → state updated → UI re-renders.
5. Auth flow uses AuthProvider and RequireAuth to guard routes.
Architectural Patterns & Principles
• Component-Based Architecture: UI broken into feature modules.
• Single Page Application (SPA) with client-side routing (implied via RequireAuth).
• Context API for cross-cutting concerns (authentication state).
• Separation of concerns: API calls isolated in utils folder.
• Deployment via static hosting (Vercel) and CDN.
Essential Details to Capture
• Context Provider boundary and protected routes (RequireAuth)
• Feature-based folder structure
• Utility layer that abstracts all HTTP calls
• Deployment targets (Vercel) and build tool (Vite)
• External dependencies (Payment Gateway, Auth service, DB)