How pcdaco/pcdaco-web works
Project type and purpose
• This is a full-stack web application built with Next.js (App Router), React, and TypeScript.
• It provides role-based dashboards (admin, consultant, technician, user) to manage cars, bookings, inspections, reports, and withdrawals.
• It integrates with Firebase (auth and possibly data storage) and uses server-side rendering (SSR) and server actions.
File structure
• app/: Next.js entry points, nested layouts, routes under (auth), (dashboard)/(admin|consultants|technicians). Contains React Server Components, Client Components, and server actions.
• components/: Reusable UI pieces (tables, forms, dialogs, data-table, ui primitives).
• domains/ & constants/: Domain-driven design—Zod schemas, TypeScript models, enums, response types.
• hooks/: Encapsulate data-fetching and form logic (React Query or custom hooks).
• lib/: Utility functions, axios.server.ts for server-side API calls, SignalR integration for real-time updates.
• stores/: Global client-state (e.g., url params, Zustand or Context providers).
• configs/: Third-party config (Firebase).
• Top-level config and deployment: Dockerfile, .github workflows (CI/CD), next.config.ts, middleware.ts (auth guard).
Key insights from README
• Uses Next.js App Router for SSR/SSG, built-in routing and API support.
• Firebase configured via environment variables for auth/data.
• Deployed on Vercel or Docker container.
Main components and their relationships
A. Client (Browser)
• Renders React Client Components (tables, forms, modals).
• Initiates navigation between pages under /auth and /dashboard.
• Uses hooks to communicate with the Next.js server via fetch or form submissions (server actions).
B. Next.js Application Server
• App Router: handles routing, nested layouts, SSR (Server Components) and CSR (Client Components).
• Server Actions: API endpoints invoked from Client Components via form submissions or fetch calls.
• axios.server.ts: encapsulates HTTP calls to back-end services or directly to Firebase REST endpoints.
• SignalR Location Hub: for real-time location updates via WebSockets.
C. Business Logic & Domain Layer
• domains/ & constants/: validation schemas, model definitions, enums—shared between server and client components.
• hooks/: data-fetching, caching strategies, and form handling logic (likely backed by React Query or built-in fetch caching).
D. Data Sources & External Services
• Firebase: authentication, possibly Firestore/Realtime Database or Storage.
• External REST APIs: any internal microservices if axios.server.ts points to them.
• SignalR Hub: real-time location service.
E. Deployment & DevOps
• Docker: containerizes the Next.js app.
• GitHub Actions: CI pipeline (docker-image.yml).
• Vercel (optional): automatic deployments.
Architectural patterns and design principles
• Monolithic full-stack but layered: Presentation (React), Application (Next.js), Domain (schemas/models), Infrastructure (utils, axios, SignalR).
• Server-side rendering mixed with client-side interactivity.
• Domain-driven design: clear separation of schemas, models, and business rules.
• Component-based UI with consistent design system (components/ui).
• Hooks abstract data access and form logic.
• Server Actions for secure form submissions and mutations.
Essential elements
• Clear component labels (e.g., “Next.js App Router”, “Server Component: app/dashboard/layout.tsx”, “Hook: use-car.ts”).
• Annotations for critical files (e.g., middleware.ts guards routes, axios.server.ts abstracts HTTP calls).