How moesiomarcelino/ignite-shop works
Project Type & Purpose
• This is a full-stack Next.js application bootstrapped via create-next-app.
• Primary purpose: a small e-commerce storefront with product listing pages, a shopping cart context, and a Stripe-based checkout flow.
File Structure
• src/pages: React page components (SSR/SSG) including dynamic product pages (/product/[id].tsx), home, checkout success.
• src/pages/api: Next.js serverless API route (/api/checkout.ts) handles checkout session creation.
• src/components: UI building blocks (Button, Header, Cart, Badge).
• src/contexts: React Context for cart state shared across pages.
• src/lib/stripe.ts: Wrapper around Stripe Node SDK, used by API route.
• public & src/assets: Static assets (images, fonts).
• src/styles: CSS modules or styled components for pages and UI.
Key Architectural Patterns
• “Hybrid rendering” of Next.js: SSR/SSG for pages, client-side hydration.
• Component-based UI in React.
• State management via React Context (cart).
• Serverless functions for back-end logic (Next API routes).
• External service integration (Stripe).
Main Components & Their Interactions
a. Browser / Client
• Renders pages (/, /product/:id, /success), hydrated React.
• Invokes client-side code in src/components and src/contexts.
• Sends an HTTP POST to /api/checkout when “Checkout” is clicked.
b. Next.js Server (Serverless Runtime)
• Hosts React pages (SSR/SSG) and serves static files from public.
• Runs /api/checkout.ts, importing src/lib/stripe.ts to create a Stripe Checkout session.
c. Stripe External Service
• Receives Checkout Session creation requests (via Stripe SDK).
• Hosts the hosted payment page.
• Redirects user back to /success after payment.
d. State Management
• Cart Context holds selected products on the client during browsing.
• No persistent database—cart lives in memory until checkout.
Important Technologies
• Next.js for routing, SSR/SSG, and API routes.
• React Context for global cart state.
• Stripe Node SDK for payment integration.
• TypeScript for type-safe interfaces (src/interfaces).
• CSS Modules / Styled components in src/styles.