How yunusmujadidi/commerce-app works
Project type and purpose
• This is a full‑stack Next.js e‑commerce platform with two main interfaces:
• A public storefront (“main” routes under app/(main)) where customers browse products and manage a cart
• It uses Next.js App Router, NextAuth for authentication, Prisma ORM for database access, and Stripe for checkout and webhooks.
File structure
• Top‑level directories:
• app/ – Next.js pages organized into (auth), (main), and dashboard route groups
• actions/ – business‑logic modules (e.g., product-action.ts, checkout-action.ts) that encapsulate database calls and third‑party integrations
• components/ – reusable UI pieces and forms
• hooks/ – custom React hooks (cart, modals, etc.)
• lib/ – shared utilities: prisma.ts initializes Prisma client, stripe.ts wraps Stripe SDK, get-session.ts for session handling
• providers/ – React context providers (theme, modal)
• Config files: next.config.ts, tsconfig.json, tailwind.config.ts, etc.
• The presence of API routes under app/(auth)/api (NextAuth callbacks, webhook) indicates serverless endpoints running alongside the frontend.
README for additional insights
• Confirms a Create‑Next‑App boilerplate
a. Main components
• Client Browser (React client components served by Next.js)
• Next.js Frontend (App Router pages + layouts under app/)
• Next.js Server/API (API routes for auth and webhooks, server‑side data‑fetching in Server Components)
• Action Layer (actions/ modules)
• ORM Layer (Prisma client in lib/prisma.ts)
• Database (e.g., PostgreSQL/MySQL)
• Authentication Service (NextAuth managing sessions, OAuth providers)
• Payment Service (Stripe API + webhooks → app/(auth)/api/webhook/route.ts)
• External Hosting (e.g., Vercel)
b. Relationships and interactions
• Browser ↔ Next.js Frontend: HTTP(S) requests, SSR/SSG, client‑side hydration
• Next.js Frontend → Next.js Server/API: data fetching calls (getServerSideProps‐style, fetch in Server Components)
• Next.js Server �� Action Layer: import and invoke domain actions (e.g., productAction.getAll())
• Action Layer �� Prisma Client: SQL queries to the relational database
• Next.js API routes ↔ NextAuth: authentication workflows, session tokens stored in DB
• Checkout Flow: Frontend invokes checkout action → Stripe API → returns session ID → on completion Stripe sends webhook → Next.js webhook route updates order status via Prisma
• Providers/hook components wrap the React tree for theme, modal, and cart state
c. Architectural patterns and design principles
• Layered architecture: UI → actions (business logic) → data (ORM)
• Server Components vs. Client Components pattern in Next.js App Router
• Single monolithic Next.js service hosting both front and API endpoints
• Clear separation of concerns: actions/ holds business logic, components/ holds UI, lib/ holds infrastructure code
d. Key technologies and libraries
• Next.js App Router (React 18 Server Components)
• NextAuth.js (authentication)
• Prisma ORM (database access)
• Stripe SDK (payments)
• Tailwind CSS (styling)
• pnpm (package manager)