# hopscotcher/dekut-marketplace architecture

> Architecture diagram of the GitHub repository hopscotcher/dekut-marketplace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hopscotcher/dekut-marketplace
- Repository: https://github.com/hopscotcher/dekut-marketplace

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js (App Router) e-commerce/marketplace application.
- It provides client-side React pages (product listings, search, sell form, user dashboard) and serverless API routes (CRUD for products, user & bulk operations).
- It uses Prisma as the ORM for database access, React Query (via queryClient) for data fetching/caching, and custom UI components.

##### High-Level Architectural Components
a. Client Layer (Next.js Pages & Components)
– src/app: React server & client components for pages (/, /products, /categories, /search, /sell, /user/dashboard).
– src/components: reusable UI blocks (common, features, product form, layout, search filters).
– src/contexts & src/stores: global state providers (ProductContext, UserContext) and Zustand store (searchStore).
– src/hooks & src/lib/queryClient: custom hooks for data operations and React Query setup.

b. Server Layer (API Routes & Services)
– src/app/api: Next.js serverless route handlers → route.ts for /api/products, /api/users, including bulk and nested routes.
– src/services: business logic for CRUD operations (productService).

c. Data Access Layer (Prisma & Database)
– prisma/schema.prisma & prisma/seed.ts: ORM schema definitions and seed script, connecting to a relational database (e.g. PostgreSQL).

d. Static & Configuration
– public: static assets.
– next.config.ts, postcss.config.mjs, eslint.config.mjs: build, styling, linting configurations.
– package.json & tsconfig.json: dependencies & TypeScript config.

##### Component Interactions and Data Flow
- User Browser → Next.js Client (React Pages & Components)
↳ Calls React Query hooks → src/services → fetch() → Next.js API Routes
- Next.js API Routes → src/services → Prisma Client → Database
- Responses bubble back: Database → Prisma → service returns JSON → API route → React Query → UI updates.
- Global State (contexts/stores) synchronizes UI components (e.g., searchStore for filters, UserContext for auth state).

##### Architectural Patterns & Principles
- Layered Architecture: Presentation → Business Logic → Data Access
- Serverless Functions: Next.js API routes as micro-endpoints
- Client-side Data Caching: React Query (queryClient)
- ORM Abstraction: Prisma for type-safe DB access
- Modular UI: Atomic/common components + feature-specific components

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        subgraph "Pages"
            direction TB
            Home["Home Page"]:::client
            Products["Products Listing"]:::client
            ProductDetail["Product Detail"]:::client
            Categories["Categories Listing"]:::client
            Search["Search Page"]:::client
            Sell["Sell Page"]:::client
            Dashboard["User Dashboard"]:::client
        end
        subgraph "Layout & Styles"
            direction TB
            Layout["Global Layout"]:::client
            Globals["Global Styles"]:::client
            Header["Header Component"]:::client
            Footer["Footer Component"]:::client
        end
        subgraph "UI Components"
            direction TB
            Common["Common Components"]:::client
            Features["Feature Components"]:::client
            Form["Product Form"]:::client
            SearchUI["Search Components"]:::client
            Primitives["UI Primitives"]:::client
        end
        subgraph "State Management"
            direction TB
            Contexts["React Contexts"]:::client
            Store["Zustand Store"]:::client
        end
        subgraph "Hooks & Utilities"
            direction TB
            Hooks["Custom Hooks"]:::client
            QueryClient["React Query Setup"]:::client
            TypesUtils["Types & Utils"]:::client
        end
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        API["Next.js API Routes"]:::api
        Services["Business Services"]:::api
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        PrismaClient["Prisma Client"]:::orm
        PrismaSchema["ORM Schema & Seed"]:::orm
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        Database["PostgreSQL Database"]:::infra
        Static["Static Assets & Config"]:::infra
    end

    %% Connections
    Browser["User Browser"]:::client
    Browser -->|"HTTP/SSR"| Home
    Home --> Hooks
    Products --> Hooks
    ProductDetail --> Hooks
    Categories --> Hooks
    Search --> Hooks
    Sell --> Hooks
    Dashboard --> Hooks

    Hooks -->|"fetch()/HTTP"| API
    API -->|calls| Services
    Services -->|Prisma Client query| PrismaClient
    PrismaClient -->|SQL queries| Database
    Database -->|results| PrismaClient
    PrismaClient -->|data objects| Services
    Services -->|JSON response| API
    API -->|HTTP response| Hooks

    Static --> Browser

    %% Click Events - Pages
    click Home "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/page.tsx"
    click Products "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/products/page.tsx"
    click ProductDetail "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/products/[id]/page.tsx"
    click Categories "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/categories/page.tsx"
    click Search "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/search/page.tsx"
    click Sell "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/sell/page.tsx"
    click Dashboard "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/user/dashboard/page.tsx"

    %% Click Events - Layout & Styles
    click Layout "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/layout.tsx"
    click Globals "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/app/globals.css"
    click Header "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/components/layout/Header.tsx"
    click Footer "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/components/layout/Footer.tsx"

    %% Click Events - UI Components
    click Common "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/components/common"
    click Features "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/components/features"
    click Form "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/components/product/ProductCreateForm.tsx"
    click SearchUI "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/components/search"
    click Primitives "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/components/ui"

    %% Click Events - State Management
    click Contexts "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/contexts"
    click Store "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/stores/searchStore.ts"

    %% Click Events - Hooks & Utilities
    click Hooks "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/hooks"
    click QueryClient "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/lib/queryClient.ts"
    click TypesUtils "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/lib/types.ts"

    %% Click Events - Server Layer
    click API "https://github.com/hopscotcher/dekut-marketplace/tree/main/src/app/api"
    click Services "https://github.com/hopscotcher/dekut-marketplace/blob/main/src/services/productService.ts"

    %% Click Events - Data Access Layer
    click PrismaSchema "https://github.com/hopscotcher/dekut-marketplace/blob/main/prisma/schema.prisma"

    %% Click Events - Infrastructure
    click Static "https://github.com/hopscotcher/dekut-marketplace/tree/main/public/"
    click Database "https://github.com/hopscotcher/dekut-marketplace/blob/main/prisma/seed.ts"

    %% Styles
    classDef client fill:#cce5ff,stroke:#4d94ff,stroke-width:1px
    classDef api fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef orm fill:#fff3cd,stroke:#ffcd39,stroke-width:1px
    classDef infra fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
```
