How rakib-cloud/car-allocation works
1. Overall shape
- This is a Next.js 16 App Router admin panel for car allocation.
- The app is split into two top-level route groups: authenticated admin pages under src/app/(root) and a public sign-in flow under src/app/(auth).
- A separate maintenance route and a middleware.js boundary indicate some requests can be short-circuited before reaching the normal shell.
2. Route and layout boundaries
- src/app/layout.jsx is the global root layout.
- src/app/(root)/layout.jsx wraps the authenticated area and likely provides the admin shell structure.
- src/components/ui/layouts/admin-layout.jsx, header.jsx, sidebar.jsx, and mobile-footer-nav.jsx form the main navigation shell for desktop/mobile.
- src/app/(auth)/sign-in/page.jsx intentionally sits outside the admin shell, so login has a separate UI and no sidebar/header.
3. Authentication model
- Authentication is JWT-based with httpOnly cookies, which means the browser does not manage tokens directly in client state.
- src/lib/auth/manual-auth.js and the actions under src/lib/actions/auth-actions/ imply a server-centered auth flow.
- sign-in-action.js handles login, token-refresh-action.js handles session renewal, and authorized-request-action.js likely wraps authenticated backend calls.
- src/app/(root)/AuthContext.jsx suggests the authenticated UI still keeps a lightweight client-side auth/session context for downstream components.
4. Request and API layer
- The repo avoids axios and uses a central native fetch wrapper in src/lib/httpClient.js.
- src/constant/api-url.js provides API endpoint definitions, while src/lib/api-envelope.js normalizes response shape across backend calls.
- Error handling is centralized in src/lib/helpers/handle-api-errors.js, so API failures are standardized before reaching UI components.
- src/lib/actions/allocation-actions.js indicates feature-specific server actions for allocation-related backend operations.
5. Server Actions as the primary mutation boundary
- Business mutations appear to happen through Next.js Server Actions rather than direct client API calls.
- This places sensitive work like token handling, refresh logic, and authenticated requests on the server side.
- The architecture therefore separates:
- client UI components for interaction,
- server actions for secure data access and mutations,
- backend API as the source of truth.
6. UI composition and shared components
- src/components/ui/ contains reusable shell primitives and navigation pieces.
- src/components/common/loader.jsx and src/app/loading.jsx provide loading states at different levels of the app.
- src/components/wrappers/page-wrapper.jsx is likely the main page-level gate for access checks and layout consistency.
- src/components/ui/user-role-permission.jsx suggests role-aware rendering is embedded into the UI layer, not just route protection.
7. Access control and route protection
- middleware.js is the first-line boundary for routing/auth decisions and likely enforces redirects or maintenance behavior.
- src/components/wrappers/page-wrapper.jsx and user-role-permission.jsx suggest an additional RBAC layer after navigation, controlling what authenticated users can see.
- This creates a two-step model: request-level gating in middleware and UI-level authorization inside the admin shell.
8. Maintenance mode path
- src/app/maintenance/page.jsx and src/constants/maintenanceMode.js show a dedicated maintenance state.
- The existence of this route plus middleware support implies the app can be globally diverted away from the main admin experience when the environment flag is enabled.
- This is an operational boundary separate from authentication.
9. Theming and providers
- src/providers/antd-provider.jsx and src/providers/theme-provider.jsx establish cross-app UI infrastructure.
- The stack combines Ant Design 6 with Tailwind CSS 4, so component styling is split between design-system widgets and utility classes.
- The README notes the theme is stored in localStorage under car-allocation-theme, so theme preference is client persisted.
10. Data shaping and helper layer
- src/lib/utils/normalize-detail-response.js, src/lib/utils/utils.js, and src/lib/helpers/toaster-helper.js are shared utilities for response normalization, generic helpers, and user notifications.
- src/hooks/useDetailFetch.js indicates at least one reusable data-fetching hook for detail views.
- These helpers reduce duplication around fetching, formatting, and error display.
11. Branding and configuration
- src/constant/branding.js and the theme note in the README indicate the UI is branded and color-coded centrally.
- env.example shows key runtime flags: NEXT_PUBLIC_API_BASE_URL, MAINTENANCE_MODE, and AUTH_COOKIE_SECURE.
- That means the deployment environment directly influences routing, auth cookie behavior, and backend target selection.
12. How data flows through the app
- User hits middleware first.
- If not authenticated, they are routed to /sign-in.
- Sign-in triggers a server action that calls the backend API through the centralized fetch layer, then stores session state in httpOnly cookies.
- Authenticated pages render inside the root layout/admin shell, use shared providers, and fetch/mutate data via server actions and the HTTP wrapper.
- Responses are normalized before reaching components, and role-based wrappers decide what portions of the UI are exposed.
Main entry points: httpClient.js HTTP client · admin-layout.jsx Admin shell · app/layout.jsx Root layout · (root)/layout.jsx Admin layout
Components 31
App routes
Next.js route boundaries and layouts
- Root layout · Global app root layout
src/app/layout.jsx - Sign in · Public login page outside the admin shell
src/app/(auth)/sign-in/page.jsx - Admin layout · Authenticated route-group layout
src/app/(root)/layout.jsx - Admin home · Main authenticated landing page
src/app/(root)/page.jsx - Maintenance · Dedicated maintenance-mode page
src/app/maintenance/page.jsx
Admin shell
Authenticated UI structure and navigation
- Admin shell · Main authenticated shell container
src/components/ui/layouts/admin-layout.jsx - Header · Top navigation for authenticated pages
src/components/ui/header.jsx - Sidebar · Desktop navigation rail
src/components/ui/sidebar.jsx - Mobile nav · Mobile footer navigation
src/components/ui/mobile-footer-nav.jsx
Auth and access
Session, protection, and maintenance boundaries
- Middleware · First-line routing and access boundary
middleware.js - Auth context · Client-side session state for authenticated UI
src/app/(root)/AuthContext.jsx - Manual auth · Server-centered cookie/session auth logic
src/lib/auth/manual-auth.js - Maintenance flag · Maintenance-mode configuration
src/constants/maintenanceMode.js
Data layer
Server actions, HTTP access, and response shaping
- Sign-in action · Handles login exchange
src/lib/actions/auth-actions/sign-in-action.js - Refresh action · Renews session tokens
src/lib/actions/auth-actions/token-refresh-action.js - Authorized request · Authenticated backend request wrapper
src/lib/actions/auth-actions/authorized-request-action.js - Allocation actions · Allocation-specific server mutations
src/lib/actions/allocation-actions.js - HTTP client · Central native fetch layer
src/lib/httpClient.js - API envelope · Normalizes backend response structure
src/lib/api-envelope.js - API URLs · Backend endpoint definitions
src/constant/api-url.js - Error helpers · Centralized API error handling
src/lib/helpers/handle-api-errors.js - Normalize detail · Response normalization helper
src/lib/utils/normalize-detail-response.js
Shared UI
Providers, shared components, and helpers
- Page wrapper · Page-level consistency and access wrapper
src/components/wrappers/page-wrapper.jsx - Role guard · Role-aware rendering in the UI layer
src/components/ui/user-role-permission.jsx - Theme provider · Client theme state and persistence
src/providers/theme-provider.jsx - Antd provider · Ant Design app-wide provider
src/providers/antd-provider.jsx - Loader · Shared loading state component
src/components/common/loader.jsx - Toaster · Global toast notifications
src/components/ui/sonner.jsx - Detail fetch · Reusable detail-view fetch hook
src/hooks/useDetailFetch.js - Utilities · Generic helper utilities
src/lib/utils/utils.js - Branding · Central brand colors and labels
src/constant/branding.js
Connections 30
- Middleware → Sign in: redirects unauthenticated · Routes public users to sign-in when needed
- Middleware → Maintenance: short-circuits · Diverts requests during maintenance mode
- Root layout → Theme provider: wraps · Global layout installs theme state
- Root layout → Antd provider: wraps · Global layout installs UI provider
- Root layout → Loader: uses · Shared app-level loading state
- Root layout → Toaster: mounts · Global notification surface
- Admin layout → Admin shell: renders · Authenticated layout composes the shell
- Admin shell → Header: contains · Desktop top navigation
- Admin shell → Sidebar: contains · Primary desktop navigation
- Admin shell → Mobile nav: contains · Mobile navigation layer
- Admin layout → Auth context: provides · Supplies session context to admin UI
- Admin layout → Page wrapper: wraps · Page-level access and layout consistency
- Page wrapper → Role guard: enforces · Controls role-based visibility
- Sign-in action → Manual auth: uses · Login flow relies on server auth logic
- Sign-in action → HTTP client: calls · Uses central HTTP transport
- Refresh action → Manual auth: uses · Refresh flow updates cookie-backed session
- Authorized request → Manual auth: uses · Authenticated wrapper depends on session state
- Authorized request → HTTP client: calls · Performs backend requests through fetch wrapper
- Allocation actions → HTTP client: calls · Feature mutations use the shared HTTP layer
- HTTP client → API URLs: targets · Resolves backend endpoints
- HTTP client → API envelope: normalizes · Aligns response shape
- HTTP client → Error helpers: handles · Routes failures through centralized error handling
- Detail fetch → HTTP client: fetches via · Reusable detail fetching depends on HTTP client
- Detail fetch → Normalize detail: transforms · Normalizes detail responses for consumers
- Utilities → Normalize detail: supports · Shared helper layer underpins response shaping
- Admin home → Page wrapper: uses · Admin page sits behind the wrapper
- Admin home → Allocation actions: mutates via · Feature page triggers server actions
- Sign in → Sign-in action: submits to · Login page initiates sign-in action
- Maintenance → Maintenance flag: driven by · Maintenance route is controlled by config
- Branding → Admin shell: styles · Branding influences shell presentation