# patrykbarc/old-sailor-ts architecture

> Architecture diagram of the GitHub repository patrykbarc/old-sailor-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/patrykbarc/old-sailor-ts
- Repository: https://github.com/patrykbarc/old-sailor-ts

## Overview

##### Main Components
- Frontend (Next.js / React) – Emphasize the page routing and component structure:
- Main pages in src/app, for example:
▸ (home) pages (career, contact, privacy-policy, etc.)
▸ Store pages under src/app/store with distinct routes for cart, products, and product details.
- Component library—the extensive folder structure under src/components includes UI controls (Button, Card, Form, etc.), layouts, and both main page and store-specific views.
- Shared styling utilities and configuration (Tailwind CSS, custom stylesheets in src/app/globals.css and customStyles.css).

- Backend/API – Represent the lightweight backend:
- API endpoints defined under src/app/api (such as the recaptchaSubmit route). This endpoint handles reCAPTCHA interactions for form verification.
- Server-side logic or middleware that might reside in the Next.js API routes.

- External Integrations and Services
- Shopify API: Show how the application integrates with Shopify. Include components from src/lib/shopify (mutations, queries, and API helper modules) that encapsulate the interactions with the Shopify storefront.
- Google reCAPTCHA: Indicate the use of reCAPTCHA both on the client (via custom hooks and helper functions in src/lib/functions/recaptcha) and the server (API endpoint).

- State Management and Utilities
- React Context API: Represent the Cart context from src/lib/contexts/CartContext, reflecting state management for the store’s cart functionality.
- Utility functions: Include utility modules in src/lib, such as formatting, debouncing, and helper functions that assist with pricing, pagination, and product details.
- Custom hooks for cart management, checkout flows, and product logic.

##### Relationships and Data Flow
- Component Interactions: Illustrate how UI components interact with context providers (e.g., CartProvider) to manage state and trigger shared logic.
- External Data Sources: Represent the flow from the Next.js server/client to Shopify by drawing connections to the shopify API modules in src/lib/shopify, highlighting data fetching and mutations (add-to-cart, create-cart, etc.).

##### Architectural Patterns and Design Principles
- Component-based and Modular Architecture: The large number of reusable UI components supports a modular design.
- Separation of Concerns: Next.js pages handle routing and render views, while API endpoints and lib functions isolate business logic and external integration.
- State and Context Management: The use of the React Context API for cart management emphasizes client-side state segregation that supports predictable data flow.
- External Service Integration: Clearly mark integration points for Shopify (GraphQL queries/mutations) and Google reCAPTCHA as integral parts of the overall design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Client
    UC("User Client / Browser"):::external

    %% Frontend Subgraph
    subgraph "Frontend (Next.js App)"
        GP("General Pages"):::frontend
        SP("Store Pages"):::frontend
        UI("UI Components"):::frontend
        V("Views"):::frontend
        GS("Global Styling"):::frontend
        CFG("Config"):::frontend
        CC("State Management (Cart Context)"):::frontend
        CH("Custom Hooks & Utilities"):::utility
    end

    %% Backend Subgraph
    subgraph "Backend / Server"
        RE("reCAPTCHA API Endpoint"):::backend
    end

    %% External Services
    SA("Shopify API Integration"):::external
    GR("Google reCAPTCHA"):::external

    %% Connections from User to Frontend pages
    UC -->|"access"| GP
    UC -->|"access"| SP

    %% Frontend internal connections
    GP -->|"renders"| UI
    SP -->|"renders"| V
    SP -->|"fetches"| SA
    UI -->|"submitsForm"| RE
    UI -->|"uses"| CC
    CH -->|"enhances"| UI
    CH -->|"supports"| CC
    UI -->|"styledBy"| GS
    UI -->|"configBy"| CFG

    %% Backend and External Integration
    RE -->|"validatesWith"| GR

    %% Click Events
    click GP "https://github.com/patrykbarc/old-sailor-ts/tree/main/src/app/(home)"
    click SP "https://github.com/patrykbarc/old-sailor-ts/tree/main/src/app/store"
    click UI "https://github.com/patrykbarc/old-sailor-ts/tree/main/src/components/ui"
    click V "https://github.com/patrykbarc/old-sailor-ts/tree/main/src/components/views"
    click GS "https://github.com/patrykbarc/old-sailor-ts/blob/main/src/app/globals.css"
    click CFG "https://github.com/patrykbarc/old-sailor-ts/blob/main/next.config.mjs"
    click RE "https://github.com/patrykbarc/old-sailor-ts/blob/main/src/app/api/recaptchaSubmit/route.ts"
    click SA "https://github.com/patrykbarc/old-sailor-ts/tree/main/src/lib/shopify"
    click GR "https://github.com/patrykbarc/old-sailor-ts/blob/main/src/lib/functions/recaptcha/recaptchaSubmit.ts"
    click CC "https://github.com/patrykbarc/old-sailor-ts/blob/main/src/lib/contexts/CartContext.ts"
    click CH "https://github.com/patrykbarc/old-sailor-ts/blob/main/src/lib/customHooks/useCart.tsx"

    %% Styles
    classDef frontend fill:#CFE2F3,stroke:#6D9EEB,stroke-width:2px;
    classDef backend fill:#F4CCCC,stroke:#CC0000,stroke-width:2px;
    classDef external fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
    classDef utility fill:#FFF2CC,stroke:#E69138,stroke-width:2px;
```
