# c-h-o-n/papirsarkany architecture

> Architecture diagram of the GitHub repository c-h-o-n/papirsarkany, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/c-h-o-n/papirsarkany
- Repository: https://github.com/c-h-o-n/papirsarkany

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js Application (src/app directory structure)
- Client-side State Management (src/store directory)
- Component Library (src/components)

b) Backend Layer:
- Next.js API Routes (src/app/(shop)/api)
- Database Layer (Prisma ORM)
- Content Management System (Sanity CMS)

c) External Services:
- Foxpost Integration (shipping service)
- Google Cloud Services
- Email Service

##### Architectural Patterns to Highlight

a) Route Groups Pattern:
- (shop) group for main e-commerce functionality
- (sanity) group for admin/CMS functionality

b) State Management:
- Multiple stores (cart, checkout, toast, foxpost)
- Client-side state hydration

##### Specific Implementation Details

a) Data Flow:
- Client Components → API Routes → Database
- Sanity CMS → Frontend Components
- Checkout Flow → External Services

b) Database Layer:
- Prisma Schema → Database
- Migration Management

**[Client Layer]**
- ↓
**[Next.js Application Layer]**
- ↓
**[API Layer]**
- ↓
**[Service Layer]**
- ↓
**[Data Layer]**

##### Important Elements

- Authentication flow for admin section
- Shopping cart state management
- Order processing pipeline
- Content management workflow
- Testing infrastructure (E2E, Integration, Unit)

##### Specific Implementation Notes

- The separation between shop and admin interfaces
- The integration with Sanity CMS for product management
- The checkout process flow
- State management architecture
- External service integrations (Foxpost, Google Cloud)

##### Technical Stack Indicators

- Next.js
- Prisma
- Sanity
- TailwindCSS
- TypeScript
- Playwright (E2E testing)
- Vitest (Unit testing)

Remember to:
- Annotations for critical paths
- Error handling flows
- Where type definitions are used (globals.d.ts, sanity.types.ts)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Frontend Application]
        CL[Component Library]
        SM[State Management]
    end

    subgraph "Next.js Layer"
        SG[Shop Route Group]
        AG[Admin Route Group]
        AR[API Routes]
    end

    subgraph "Service Layer"
        FP[Foxpost Service]
        GC[Google Cloud]
        EM[Email Service]
    end

    subgraph "Data Layer"
        DB[(Database)]
        PS[Prisma Schema]
        MI[Migrations]
    end

    subgraph "CMS Layer"
        SC[Sanity CMS]
        KS[Kite Schema]
        RS[Reel Schema]
        RDS[Rod Schema]
        TS[Twine Schema]
    end

    subgraph "State Stores"
        CS[Cart Store]
        CHS[Checkout Store]
    end

    subgraph "Testing"
        E2E[E2E Tests]
        INT[Integration Tests]
        UNIT[Unit Tests]
    end

    subgraph "Types"
        GT[Global Types]
        ST[Sanity Types]
    end

    %% Relationships
    FE --> SG
    FE --> AG
    SG --> AR
    AR --> DB
    PS --> DB
    MI --> DB
    SC --> AG
    SC --> KS
    SC --> RS
    SC --> RDS
    SC --> TS
    AR --> FP
    AR --> GC
    AR --> EM
    SM --> CS
    SM --> CHS

    %% Click events
    click FE "https://github.com/c-h-o-n/papirsarkany/tree/main/src/app"
    click CL "https://github.com/c-h-o-n/papirsarkany/tree/main/src/components"
    click SM "https://github.com/c-h-o-n/papirsarkany/tree/main/src/store"
    click SG "https://github.com/c-h-o-n/papirsarkany/tree/main/src/app/(shop)"
    click AG "https://github.com/c-h-o-n/papirsarkany/tree/main/src/app/(sanity)"
    click AR "https://github.com/c-h-o-n/papirsarkany/tree/main/src/app/(shop)/api"
    click FP "https://github.com/c-h-o-n/papirsarkany/blob/main/src/lib/foxpost.ts"
    click GC "https://github.com/c-h-o-n/papirsarkany/blob/main/src/lib/google-cloud.ts"
    click EM "https://github.com/c-h-o-n/papirsarkany/blob/main/src/lib/email.ts"
    click PS "https://github.com/c-h-o-n/papirsarkany/blob/main/prisma/schema.prisma"
    click MI "https://github.com/c-h-o-n/papirsarkany/tree/main/prisma/migrations"
    click SC "https://github.com/c-h-o-n/papirsarkany/tree/main/sanity"
    click KS "https://github.com/c-h-o-n/papirsarkany/tree/main/sanity/schemas/kite"
    click RS "https://github.com/c-h-o-n/papirsarkany/tree/main/sanity/schemas/reel"
    click RDS "https://github.com/c-h-o-n/papirsarkany/tree/main/sanity/schemas/rod"
    click TS "https://github.com/c-h-o-n/papirsarkany/tree/main/sanity/schemas/twine"
    click CS "https://github.com/c-h-o-n/papirsarkany/blob/main/src/store/use-cart-store.ts"
    click CHS "https://github.com/c-h-o-n/papirsarkany/blob/main/src/store/use-checkout-form-store.ts"
    click E2E "https://github.com/c-h-o-n/papirsarkany/tree/main/src/tests/e2e"
    click INT "https://github.com/c-h-o-n/papirsarkany/tree/main/src/tests/integration"
    click UNIT "https://github.com/c-h-o-n/papirsarkany/tree/main/src/tests/unit"
    click GT "https://github.com/c-h-o-n/papirsarkany/blob/main/globals.d.ts"
    click ST "https://github.com/c-h-o-n/papirsarkany/blob/main/sanity/lib/sanity.types.ts"

    %% Styling
    classDef frontend fill:#3b82f6,color:white
    classDef api fill:#22c55e,color:white
    classDef database fill:#a855f7,color:white
    classDef external fill:#f97316,color:white
    classDef cms fill:#eab308,color:white
    classDef testing fill:#64748b,color:white
    classDef types fill:#ec4899,color:white

    class FE,CL,SM frontend
    class AR,SG,AG api
    class DB,PS,MI database
    class FP,GC,EM external
    class SC,KS,RS,RDS,TS cms
    class E2E,INT,UNIT testing
    class GT,ST types
    class CS,CHS frontend
```
