How nahidruhan/spread-fast-client works
1. What this repo is
- This is the client-side SPA for Spread Fast, a logistics/courier platform.
- It is a React + Vite application deployed as a static frontend, with a separate backend API described in the README but not included in this repo.
2. App bootstrap and runtime boundaries
- src/main.jsx is the entry point and wires together the global app shell.
- The app uses src/index.css plus the Vite build pipeline, and is hosted via Firebase Hosting config (firebase.json, .firebaserc).
- Static content in public/ is served directly by the hosting layer.
3. Authentication and user identity
- Authentication is centralized in src/context/authcontext and src/context/authprovider, with Firebase initialized in src/firebase/firebase.init.js.
- useAuth.jsx exposes the current user/session state to the rest of the app.
- The auth layer is the main boundary between anonymous users and protected parcel/rider/admin functionality.
4. Routing and access control
- src/routes/Router.jsx defines the client navigation map.
- Route guards are split by role:
- PrivateRoute.jsx for logged-in users
- AdminRoute.jsx for admin-only screens
- RiderRoute.jsx for rider-only screens
- Forbidden.jsx and components/error/* handle access-denied and error states.
5. Layout hierarchy
- The app is organized around three top-level shells:
- RootLayout.jsx for the public-facing site
- AuthLayout.jsx for login/register screens
- DashboardLayout.jsx for authenticated dashboard pages
- Shared chrome lives in src/pages/shared and src/components, especially Navbar, Sidebar, Footer, Logo, Loading, and Border.
6. Public/customer experience
- The home/marketing side is under src/pages/home, with sections for banner, services, how-it-works, features, FAQ, collaboration, and reviews.
- Informational pages like AboutUs and Coverage support the customer discovery flow.
- SendParcel.jsx is the key customer transaction entry point for booking a parcel.
7. Parcel lifecycle and customer dashboard flows
- Customer parcel management is in src/pages/dashboard/my-parcels, including MyParcels.jsx and Tracking.jsx.
- Payment-related screens are isolated in src/pages/dashboard/payment, with explicit success and cancellation return pages.
- PaymentHistory.jsx shows completed transactions and receipt-like history, which implies a backend-backed payment/order record.
8. Rider operations
- Rider-specific UI lives in src/pages/rider and src/pages/dashboard/rider.
- These screens are designed around delivery execution: accepting work, updating delivery status, and managing active jobs.
- The README indicates rider availability/work status is part of the workflow, so the navbar/dashboard likely serves as the control surface for dispatch eligibility.
9. Admin operations
- Administrative parcel oversight is in AllParcels.jsx and PendingParcel.jsx.
- User moderation is handled in UserManage.jsx.
- The admin area is the operational control plane for approving riders, managing users, and moving parcels through hub/origin/destination states.
10. Data access and server interaction
- useAxiosSecure.jsx is the main client-side data access abstraction for authenticated API calls to the backend.
- useRole.jsx likely resolves the current user’s role for routing and UI gating.
- From the README, the frontend talks to a separate Node/Express + MongoDB backend and uses Stripe for payments; Firebase Auth tokens are used to secure requests.
11. Static data and local content
- The app includes local JSON datasets such as public/reviews.json, public/serviceCenters.json, and src/assets/warehouses.json.
- These files support location/coverage and testimonial content without requiring runtime API calls.
- Visual assets are organized under src/assets, including banners and brand imagery.
12. Error, loading, and empty-state handling
- Loading.jsx provides a shared loading state across async screens.
- Error boundaries/pages are split into reusable error and forbidden views, which keeps route failures and authorization failures distinct.
- This suggests the app is designed to handle protected async dashboards gracefully rather than only static marketing pages.
13. Architecture summary for diagramming
- A good diagram would show:
- Public SPA shell → marketing pages
- Auth layer → Firebase login/register/social auth
- Role-gated dashboard → customer, rider, admin sub-flows
- Secure API boundary → useAxiosSecure to backend services
- Payment boundary → Stripe checkout with success/cancel redirects
- Static assets/data → hosted JSON and media files consumed directly by the client
Main entry points: useAxiosSecure.jsx useAxiosSecure · Router.jsx Router · Navbar.jsx Navbar · Payment.jsx Payment
Components 34
Public SPA
Marketing and customer-facing pages
- Root shell · Public-facing application shell
src/layouts/RootLayout.jsx - Home · Marketing landing page
src/pages/home/home/Home.jsx - Send parcel · Customer parcel booking entry point
src/pages/send-parcel/SendParcel.jsx - About us · Company and service overview
src/pages/about-us/about-us/AboutUs.jsx - Coverage · Service area and coverage discovery
src/pages/coverage/coverage/Coverage.jsx
Auth & Access
Identity, route guards, and role resolution
- Auth shell · Login and registration shell
src/layouts/AuthLayout.jsx - Router · Client route map and page composition
src/routes/Router.jsx - Private guard · Protects authenticated screens
src/routes/PrivateRoute.jsx - Admin guard · Restricts admin-only screens
src/routes/AdminRoute.jsx - Rider guard · Restricts rider-only screens
src/routes/RiderRoute.jsx - Auth state · Central session and identity state
src/context/authcontext/AuthContext.jsx - Auth provider · Supplies auth state to the app
src/context/authprovider/AuthProvider.jsx - Firebase init · Firebase configuration and auth initialization
src/firebase/firebase.init.js - useAuth · Reads the current user/session
src/hooks/useAuth.jsx - useRole · Resolves user role for gating and UI
src/hooks/useRole.jsx
Role Dashboards
Authenticated customer, rider, and admin operations
- Dashboard shell · Authenticated dashboard shell
src/layouts/DashboardLayout.jsx - My parcels · Customer parcel list and management
src/pages/dashboard/my-parcels/MyParcels.jsx - Tracking · Parcel tracking details
src/pages/dashboard/my-parcels/Tracking.jsx - Payment · Payment flow for parcel orders
src/pages/dashboard/payment/Payment.jsx - Payment success · Successful payment return screen
src/pages/dashboard/payment/PaymentSuccess.jsx - Payment cancel · Cancelled payment return screen
src/pages/dashboard/payment/PaymentCancelled.jsx - Payment history · Completed transaction records
src/pages/dashboard/payment-history/PaymentHistory.jsx - Rider ops · Rider work queue and delivery execution
src/pages/dashboard/rider/RiderDashboard.jsx - Rider page · Rider-facing operational UI
src/pages/rider/rider/Rider.jsx - All parcels · Admin parcel oversight
src/pages/dashboard/all-parcel/AllParcels.jsx - Pending parcels · Admin review and approval queue
src/pages/dashboard/pending-parcel/PendingParcel.jsx - User manage · User moderation and role administration
src/pages/dashboard/user-management/UserManage.jsx
Shared UI
Reusable chrome, states, and error surfaces
- App entry · Vite/React bootstrap and global app wiring
src/main.jsx - useAxiosSecure · Authenticated API access to backend services
src/hooks/useAxiosSecure.jsx - Navbar · Global navigation and account controls
src/pages/shared/navbar/Navbar.jsx - Sidebar · Dashboard navigation shell
src/components/sidebar/Sidebar.jsx - Footer · Site footer
src/pages/shared/footer/Footer.jsx - Loading · Shared async loading state
src/pages/shared/loading/Loading.jsx - Forbidden · Access denied screen
src/components/forbidden/Forbidden.jsx
Connections 37
- App entry → Router: boots · Application entry mounts routed app
- Router → Root shell: public shell · Public pages render through the root layout
- Router → Auth shell: auth shell · Authentication pages render through the auth layout
- Router → Dashboard shell: dashboard shell · Protected pages render through the dashboard layout
- Router → Private guard: gates · Authenticated routes are wrapped by the private guard
- Router → Admin guard: gates · Admin routes are wrapped by the admin guard
- Router → Rider guard: gates · Rider routes are wrapped by the rider guard
- Auth provider → Auth state: provides · Auth provider supplies shared identity state
- Auth state → useAuth: reads · Hook exposes current session state
- Auth state → useRole: reads · Role hook derives authorization state
- Firebase init → Auth provider: auth backend · Firebase initialization supports sign-in and session handling
- useAxiosSecure → Firebase init: tokens · Secure API client relies on authenticated identity
- Root shell → Navbar: uses · Public shell includes global navigation
- Root shell → Footer: uses · Public shell includes footer
- Dashboard shell → Sidebar: uses · Dashboard shell includes sidebar navigation
- Dashboard shell → Loading: uses · Dashboard surfaces shared loading state
- Private guard → Forbidden: blocks · Unauthorized access routes to forbidden screen
- Admin guard → Forbidden: blocks · Admin-only access failures land on forbidden screen
- Rider guard → Forbidden: blocks · Rider-only access failures land on forbidden screen
- Home → Navbar: uses · Marketing pages share the top navigation
- Home → Footer: uses · Marketing pages share the footer
- Send parcel → useAxiosSecure: api · Parcel booking uses authenticated backend calls
- Send parcel → Loading: state · Booking flow uses shared loading feedback
- My parcels → useAxiosSecure: api · Customer parcel data comes from secure API calls
- Tracking → useAxiosSecure: api · Tracking reads parcel state from backend
- Payment → useAxiosSecure: api · Payment flow initiates backend-side checkout work
- Payment → Payment success: redirect · Successful payments return to confirmation page
- Payment → Payment cancel: redirect · Cancelled payments return to cancel page
- Payment history → useAxiosSecure: api · Payment history comes from backend records
- Rider ops → useAxiosSecure: api · Rider operations sync with backend dispatch data
- Rider page → useAxiosSecure: api · Rider screen uses secure dispatch endpoints
- All parcels → useAxiosSecure: api · Admin parcel oversight uses secure data access
- Pending parcels → useAxiosSecure: api · Pending review queue is backend-driven
- User manage → useAxiosSecure: api · User moderation uses secure admin endpoints
- Navbar → useAuth: session · Navbar reflects login state and user identity
- Navbar → useRole: role · Navbar adapts to user role
- Sidebar → useRole: role · Sidebar navigation varies by role