How tyri0n11/web-app-car-rental-service works
Project Type and Purpose
• This is a full-stack Car Rental Service web application.
• Frontend: a React (TypeScript) SPA built with Vite, React Router, Tailwind CSS, Material UI, Context API, Axios.
• Backend: a monolithic NestJS service structured into modules (Auth, User, Car, Booking, Payment, Review, etc.), using Prisma ORM over PostgreSQL, Redis caching, BullMQ job queues, Cloudinary file storage, Nodemailer email service, Swagger API docs, and Winston logging.
Main Components
a. Frontend Client
• Browser application (SPA)
• Context providers (AuthContext, BookingContext, CarContext, etc.)
• API layer (services under client/src/apis) communicating via Axios to backend REST endpoints
• UI components (buttons, cards, modals, pages, filters, layouts) organized per feature (home, car, booking, admin dashboard, profile, auth)
• Routing (PublicRoutes, ProtectedRoutes, AdminRoutes)
b. Backend API
• NestJS application (server/src)
• Modules: Auth, User, Car, Category, Booking, Payment, Review, Transaction, Activity, Dashboard, Image, Email, Database
• Controllers (handling HTTP routes) → Services (business logic) → Prisma (data persistence)
• Guards (JWT, roles, resource ownership) for authentication & authorization
• Interceptors & Filters for response formatting & exception handling
• Middleware (e.g., logger)
c. Data Stores & Infrastructure
• PostgreSQL (primary relational database)
• Redis (cache for sessions, rate-limiting, job queue backend)
• BullMQ job queue (workers: processTransaction, unlockCar)
• Cloudinary (file storage for images)
• SMTP email service (Nodemailer)
• Docker & Docker Compose (containerization)
Component Relationships & Data Flow
1. The browser issues HTTP(S) requests to the NestJS API (e.g., user sign-in, fetch car list, create booking).
2. API Controllers receive requests → apply Guards → pass to Services.
3. Services interact with Prisma to read/write PostgreSQL data.
4. For heavy-lifting tasks (e.g., transaction processing, unlocking cars), Services enqueue jobs into BullMQ (backed by Redis).
5. Dedicated Worker processes pick up jobs from the queue, execute business logic, update DB, and may call external services (email, Cloudinary).
6. Services use Redis for caching frequently accessed data (e.g., categories, car lists) and session state.
7. File uploads go from client → Cloudinary (via backend proxy).
8. Email notifications (verification, booking confirmation) go via Nodemailer/SMTP.
Architectural Patterns & Design Principles
• Frontend: Component-based architecture, Single Responsibility (each component handles one UI concern), Context API for shared state, service layer (API wrappers).
• Backend: Modular monolith (one NestJS app split into feature modules), Controller–Service–Repository pattern, DTOs for input validation, Guards for cross-cutting security, Interceptors/Filters for response and error management, Decorators for code reuse.
• Infrastructure: Twelve-factor app (config via env vars), containerization, job queue for asynchronous processing, caching layer, centralized logging.