# thiagotsdelima/ignit-shop architecture

> Architecture diagram of the GitHub repository thiagotsdelima/ignit-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/thiagotsdelima/ignit-shop
- Repository: https://github.com/thiagotsdelima/ignit-shop

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce web application built with Next.js.
- The README and file tree show:
- A React-based frontend under `src/pages` and `src/components`.
- Serverless API routes in `src/pages/api`, notably `checkout.ts` which integrates with Stripe.
- Client-side state management via Context + Reducer (`shopCartContext.tsx`, `shopCartReducer.ts`).
- Styling with CSS-in-JS (`src/styles`).

##### High-Level Architecture
┌──────────────────┐       ┌────────────────────┐
│   Browser / UX   │──────▶│    Next.js SSR     │
│(React Components)│       │– Pages & Components│
└──────────────────┘       └────────────────────┘
│                            │
│ Client-side cart state     │
│ in Context + Reducer       │
▼                            │
┌──────────────────┐                   │
│  HTTP Requests   │◀──────────────────┘
│ (e.g. /api/checkout)                  │
└──────────────────┘                   ▼
│                    ┌──────────────────┐
│ POST /api/checkout │ Stripe SDK      │
▼                    │ (create session)│
┌──────────────────┐           └──────────────────┘
│  Next.js Server  │
│ API Route Layer  │
└──────────────────┘

##### Main Components
a. Frontend Layer
- React pages (`pages/index.tsx`, `pages/product/[id].tsx`, `pages/success.tsx`)
- Shared UI components (`Badge`, `BagButton`, `MenuContent`, etc.)
- Global styles (`src/styles/global.ts`, page styles)
- Client-side state: Context (`shopCartContext.tsx`) + Reducer (`shopCartReducer.ts`)
b. Backend / Serverless Layer
- Next.js API Routes (`pages/api/checkout.ts`) hosted as serverless functions
- Stripe integration (`src/services/stripe.ts`)
c. External Services
- Stripe Checkout (payment processing)
d. Assets & Configuration
- Public assets (`public/`) for images
- Next.js configuration (`next.config.mjs`)
- TypeScript config (`tsconfig.json`)

##### Relationships & Data Flows
- User interacts with React UI → updates cart context/reducer.
- On “Checkout” click → frontend POST to `/api/checkout`.
- Next.js serverless function calls Stripe SDK → returns Checkout Session URL.
- Frontend redirects user to Stripe Checkout page → Stripe processes payment.
- Stripe redirects back to `/success` on payment success.

##### Architectural Patterns & Principles
- “Separation of Concerns”: UI components vs. business logic (Context/Reducer) vs. payment integration (service + API).
- Serverless functions for backend endpoints → No dedicated server required.
- SSR/SSG features of Next.js for fast page loads.

##### Technologies & Frameworks (annotate
- Next.js / React
- TypeScript
- Context API + Reducer (state management)
- Stripe Node SDK
- CSS-in-JS (styled-components or equivalent via `styles/*.ts`)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser / UI)"
        direction TB
        Browser["Browser / UX"]:::client
        subgraph "Pages" 
            direction TB
            HomePage["Home Page<br/>(src/pages/index.tsx)"]:::client
            ProductPage["Product Detail Page<br/>(src/pages/product/[id].tsx)"]:::client
            SuccessPage["Success Page<br/>(src/pages/success.tsx)"]:::client
            CustomApp["Custom App<br/>(_app.tsx)"]:::client
            CustomDoc["Custom Document<br/>(_document.tsx)"]:::client
        end
        subgraph "Components"
            direction TB
            Badge["Badge Component"]:::client
            BagButton["BagButton Component"]:::client
            MenuContent["MenuContent Component"]:::client
            MenuHamburguer["MenuHamburguer Component"]:::client
        end
        subgraph "Styles"
            direction TB
            GlobalStyles["Global Styles"]:::client
            PageStyles["Page-Specific Styles"]:::client
        end
        subgraph "State Management"
            direction TB
            CartContext["Cart Context"]:::client
            CartReducer["Cart Reducer & Actions"]:::client
        end
    end

    %% Serverless / API Layer
    subgraph "Serverless / API (Next.js)"
        direction TB
        CheckoutAPI["Checkout API Route<br/>(src/pages/api/checkout.ts)"]:::server
        StripeService["Stripe Integration Service<br/>(src/services/stripe.ts)"]:::server
    end

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

    %% Config & Assets
    subgraph "Config & Assets"
        direction TB
        PublicAssets["Public Assets<br/>(public/)"]:::config
        NextConfig["Next.js Config<br/>(next.config.mjs)"]:::config
        TSConfig["TypeScript Config<br/>(tsconfig.json)"]:::config
    end

    %% Connections
    Browser -->|interacts with| HomePage
    Browser --> ProductPage
    Browser --> SuccessPage
    HomePage --> CartContext
    ProductPage --> CartContext
    CartContext --> CartReducer
    SuccessPage --> CartContext

    HomePage -->|uses| Badge
    HomePage --> BagButton
    HomePage --> MenuContent
    HomePage --> MenuHamburguer

    CustomApp --> GlobalStyles
    CustomApp --> PageStyles
    HomePage --> PageStyles
    ProductPage --> PageStyles
    SuccessPage --> PageStyles

    CartContext -->|dispatch actions| CartReducer

    HomePage -->|POST /api/checkout| CheckoutAPI
    CheckoutAPI -->|calls| StripeService
    StripeService -->|creates session| Stripe
    Stripe -->|redirect back to /success| SuccessPage

    PublicAssets --> HomePage
    PublicAssets --> ProductPage
    PublicAssets --> SuccessPage
    NextConfig --> CustomApp
    TSConfig --> CustomApp

    %% Click Events
    click HomePage "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/pages/index.tsx"
    click ProductPage "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/pages/product/[id].tsx"
    click SuccessPage "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/pages/success.tsx"
    click CustomApp "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/pages/_app.tsx"
    click CustomDoc "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/pages/_document.tsx"
    click Badge "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/components/Badge/index.tsx"
    click BagButton "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/components/BagButton/index.tsx"
    click MenuContent "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/components/MenuContent/index.tsx"
    click MenuHamburguer "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/components/MenuHamburguer/index.tsx"
    click StripeService "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/services/stripe.ts"

    click PublicAssets "https://github.com/thiagotsdelima/ignit-shop/tree/main/public/"
    click NextConfig "https://github.com/thiagotsdelima/ignit-shop/blob/main/next.config.mjs"
    click TSConfig "https://github.com/thiagotsdelima/ignit-shop/blob/main/tsconfig.json"

    %% Styles click
    click GlobalStyles "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/styles/global.ts"
    click GlobalStyles "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/styles/index.ts"
    click PageStyles "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/styles/pages/app.ts"
    click PageStyles "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/styles/pages/home.ts"
    click PageStyles "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/styles/pages/product.ts"
    click PageStyles "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/styles/pages/success.ts"

    %% State click
    click CartContext "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/context/shopCartContext.tsx"
    click CartReducer "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/reducer/shopCartReducer.ts"
    click CartReducer "https://github.com/thiagotsdelima/ignit-shop/blob/main/src/reducer/actions.ts"

    %% Class Definitions
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef server fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
