How hamzachaali-web/test_e-commerce works
Project type and purpose
• This is a full-stack e-commerce web application built with Next.js (using the new App Router).
• The front end is React/TypeScript pages under app/, the back end lives in Next.js API routes under app/api/, and Prisma/SQLite (or another SQL DB) is used for persistence.
File structure
• Top-level directories:
• app/ – Next.js pages & layout, feature-specific routes (account, product, checkout, login, search).
• app/api/ – serverless API endpoints for products, customers (login/register/profile), orders, favorites, ratings, search, similar-products, auth operations.
• components/ – reusable UI components (nav bar, banners, product rating, favorite button, etc.).
• lib/ – shared libraries: JWT handling, middleware, Prisma client.
• prisma/ – database schema, migrations, and seed data file (data.db).
• public/, config files (next.config.ts, Tailwind, ESLint, PostCSS, tsconfig).
README for additional insights
• Confirms standard Next.js setup (create-next-app), no special monorepo or microservices splitting.
• The application will be deployed on Vercel or any Node.js host; uses next/font optimization.
a. Main components
• Browser (client) – issues page requests and API calls.
• Next.js Application – performs SSR/SSG for pages, hosts API routes under app/api.
• Prisma ORM layer (lib/prisma.ts) – abstracts DB access.
• Database – SQLite for local dev (prisma/data.db) or PostgreSQL/MySQL in production.
• External Payment Provider – invoked in checkout/paymentProvider.
• JWT Auth Service – custom middleware in lib/middleware.ts validating tokens.
b. Relationships & data flow
1. Client → Next.js page request (e.g., /product/123) → Server-side rendering → DB via Prisma → render HTML.
2. Client → API request (/api/auth, /api/products, /api/orders, etc.) → Next.js Lambda → Auth Middleware → Prisma → DB → JSON response.
3. Checkout flow: Client → /api/orders → server creates order in DB → invokes external Payment Provider API → callback/webhook.
4. Favorites & ratings: Client uses protected API endpoints with JWT in headers → middleware validates → prisma updates favorites/ratings tables.
c. Architectural patterns & design principles
• Layered architecture: Presentation (React pages & components), Application (Next.js routing & API), Data (Prisma & DB).
• Use of Context API (components/ContextAPI) for front-end state.
• JWT-based stateless authentication.
• Modular pages under app/feature for feature separation.
• Database migrations to evolve schema in prisma/migrations.
d. Key technologies
• Next.js (App Router, server components, API routes)
• React & TypeScript
• Prisma ORM + SQLite/PostgreSQL
• JWT for auth
• Tailwind CSS for styling
• Vercel (or Node) for deployment