How rahmounidev/v2 works
Project type and purpose
• This is a full-stack web application built with Next.js (App Router + Pages Router) serving both UI pages and API endpoints.
• Its purpose is to power the customer-facing side (“espace client”) of Droovo, a food-delivery service: handling authentication, browsing restaurants/dishes, placing orders, loyalty points, reviews, and notifications.
File structure
• app/: Next.js App Router entrypoints for pages (cart, checkout, login, loyalty, orders, restaurant details, etc.) and global layout/styles.
• pages/api/: Next.js API routes (auth, restaurants, orders, profile, reviews, stats, setup).
• components/: React components for UI, theming, header/footer, loyalty badge, map, notifications, review system, and a UI primitives library.
• lib/: Business logic utilities (auth, DB-access via Prisma, session handling, input validations with Zod).
• prisma/ + database/: DB schema, migrations, seed scripts, and raw SQL for MySQL.
• middleware.ts: For session protection or route-level guards.
• scripts/: Shell scripts for DB setup.
• dist/: Compiled output (for deployment or SSR).
• Configuration files: next.config.mjs, tsconfig.json, tailwind.config.ts, .env.example, package.json.
README for additional insights
• Uses MySQL via Prisma (DATABASE_URL).
• Iron-session for server-side session management.
• Zod for request validation.
• Lists all API endpoints and security considerations.
• Mentions notifications (WhatsApp).
• Database entities: users, customers, dishes, orders, categories, reviews, promotions.
a. Main components:
• Client Browser: React-based pages served by Next.js; calls API endpoints via fetch.
• Next.js Server:
• App Router: Server and client components rendering UI (app/).
• Pages Router (API): Serverless or Node API routes (pages/api/).
• Middleware: Session validation, route guarding.
• Authentication & Session: iron-session + session cookies; auth library in lib/auth.ts
• Business Logic Layer: lib/db.ts (Prisma Client), lib/utils.ts, lib/validations/*.
• Database: MySQL (resto_db) managed with Prisma; migrations/seed.
• External Services:
• WhatsApp notifications (components/notifications/whatsapp-notification.tsx)
• Potential email/WebSocket future.
b. Relationships & data flow:
1. User → Browser (UI React pages)
2. Browser → Next.js API (POST/GET /api/*)
3. API → Middleware (session check) → Validation (Zod) → Business logic (lib/)
4. Business logic → Prisma → MySQL ←→ migrations/seed
5. Business logic → External Service (WhatsApp)
6. Next.js SSR/SSG uses DB to pre-render pages in app/.
c. Architectural patterns/design principles:
• Separation of concerns: UI components, API routes, business logic, data access layer.
• Layered architecture: Presentation (app/, components), Application (pages/api), Domain logic (lib/validations, lib/utils), Data access (Prisma).
• Server-side rendering + client hydration via Next.js App Router.
• Serverless functions (API routes) or Node endpoints.
• Middleware pipeline for cross-cutting concerns (session, logging).
d. Key technologies/frameworks/libraries:
• Next.js 13 (App + Pages Router)
• React, TypeScript
• Prisma ORM + MySQL
• iron-session for session management
• Zod for input validation
• Tailwind CSS
• External notifications (e.g., Twilio/WhatsApp)