# moesiomarcelino/ignite-shop architecture

> Architecture diagram of the GitHub repository moesiomarcelino/ignite-shop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moesiomarcelino/ignite-shop
- Repository: https://github.com/moesiomarcelino/ignite-shop

## Overview

##### 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`.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Home["Home Page (/)" ]:::frontend
        Prod["Product Page (/product/[id])"]:::frontend
        Success["Success Page (/success)"]:::frontend
        CartCtx["CartContext Provider"]:::frontend
        subgraph "UI Components"
            direction TB
            Badge["Badge"]:::frontend
            Button["Button"]:::frontend
            CartUI["Cart (UI)"]:::frontend
            Header["Header"]:::frontend
        end
    end

    %% Next.js Application Layer
    subgraph "Next.js Application Layer"
        direction TB
        AppEntry["_app.tsx"]:::backend
        Doc["_document.tsx"]:::backend
        ContextIndex["Contexts Barrel"]:::backend
        API["API Route: /api/checkout"]:::backend
        StripeSDK["Stripe Wrapper"]:::backend
    end

    %% External Service Layer
    subgraph "External Service Layer"
        direction TB
        Stripe["Stripe Checkout"]:::external
    end

    %% Connections
    Home -->|"GET /"| AppEntry
    Prod -->|"GET /product/:id"| AppEntry
    Success -->|"GET /success"| AppEntry
    AppEntry --> CartCtx
    CartCtx --> ContextIndex
    CartCtx <--> Badge
    CartCtx <--> Button
    CartCtx <--> CartUI
    CartCtx <--> Header
    CartUI -->|"POST /api/checkout"| API
    API --> StripeSDK
    StripeSDK -->|"HTTPS Request"| Stripe
    Stripe -->|"Redirect to /success"| Success

    %% Click Events
    click Home "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/pages/index.tsx"
    click Prod "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/pages/product/[id].tsx"
    click Success "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/pages/success.tsx"
    click AppEntry "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/pages/_app.tsx"
    click Doc "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/pages/_document.tsx"
    click CartCtx "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/contexts/cart.tsx"
    click ContextIndex "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/contexts/index.tsx"
    click API "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/pages/api/checkout.ts"
    click StripeSDK "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/lib/stripe.ts"
    click Badge "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/components/badge.tsx"
    click Button "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/components/button.tsx"
    click CartUI "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/components/cart.tsx"
    click Header "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/components/header.tsx"
    click ComponentsBarrel "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/components/index.ts"
    click Globals "https://github.com/moesiomarcelino/ignite-shop/blob/main/src/styles/globals.ts"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#0366d6,color:#000
    classDef backend fill:#D1F7C4,stroke:#28A745,color:#000
    classDef external fill:#FFE5B4,stroke:#E69500,color:#000
```
