# djmiguelr/fcfcamps architecture

> Architecture diagram of the GitHub repository djmiguelr/fcfcamps, 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/djmiguelr/fcfcamps
- Repository: https://github.com/djmiguelr/fcfcamps

## Overview

##### Main Components

- Frontend (Next.js Application):
- Pages and Layout: Located under the "app" directory with pages such as the landing page (app/page.tsx) and checkout pages (app/checkout/page.tsx, app/checkout/success/page.tsx).
- Global styles: app/globals.css and additional styles in the "styles" folder.
- Layout and Routing: The standard Next.js layout (app/layout.tsx) and sitemap configuration (app/sitemap.ts).

- Backend/API:
- API Route: An API endpoint is provided in app/api/submit-form/route.ts. This endpoint likely handles form submissions (e.g., pre-registration or contact forms).
- Environment Configuration: Use of environment variables (.env.local) to secure credentials for the Google Sheets API (Google service email, private key, and sheet ID).

- Components and UI Library:
- Reusable Components: Various UI elements such as benefit cards, photo galleries, checkout buttons, modal dialogs, and so on are found in the "components" directory.
- Component Library: The "components/ui" subfolder contains detailed UI primitives (e.g., accordion, dialog, input, slider, toast, etc.) that provide building blocks for the user interface.

- Hooks and Utility Functions:
- Custom Hooks: Found in the "hooks" folder (e.g., use-mobile, use-toast) to encapsulate common functionality.
- Utility Functions: The "lib" folder, specifically lib/utils.ts, which may contain helper functions utilized throughout the application.

- External Dependencies:
- Google Sheets API: Configured via environment variables.
- Tailwind CSS: For styling, configured through tailwind.config.ts.
- Build and Deployment: Next.js configuration (next.config.mjs), along with package management (package.json, pnpm-lock.yaml) and deployment scripts mentioned in the README (including PM2 for production).

##### Relationships and Data Flow

- User Interactions:
- Users access the landing page and interact with various UI components and checkout processes.
- As users navigate through UI components, custom hooks manage responsiveness (mobile view) and toast notifications.

- Data Flow:
- The client-side pages interact with the backend API (e.g., form submission via /api/submit-form) using Next.js built-in API routes.
- Upon submission, the server-side component communicates with Google Sheets API to save data.

- Component Integration:
- The UI components form the core building blocks of the interface, interacting with the pages.
- The layout is wrapped with theme providers and global styles to ensure consistency.

- Environment & External Service Integration:
- When deployed, server startup and runtime configurations (with PM2) ensure persistence.
- Environment-specific variables enable secure integration with Google Sheets for data management.

##### Architectural Patterns and Principles

- Next.js File-based Routing: Utilize the app directory to define the routes and API endpoints.
- Modular and Component-Based Architecture: Separation of concerns is clear with dedicated directories for pages, components, hooks, and utilities.
- Separation of Concerns: Clear separation between presentation (React components and UI elements) and business logic (API routes and server configurations).
- Declarative UI and Reusability: Usage of React functional components and custom hooks fosters code reuse and easier maintenance.

##### Final Checklist

- Clearly labeled major components: Frontend (pages, components, hooks), API backend, external integrations (Google Sheets).
- Reference any critical technologies (Next.js, React, Tailwind, TypeScript) to provide context on the underlying stack.
- Integration of deployment and build processes as noted in the README for production environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    User(("User")):::external

    subgraph "Frontend (Next.js UI)"
        direction TB
        %% Pages & Layout subgraph
        subgraph "Pages & Layout"
            direction TB
            LP["Landing Page"]:::frontend
            CP["Checkout Page"]:::frontend
            CSP["Checkout Success Page"]:::frontend
            LO["Layout"]:::frontend
            SM["Sitemap"]:::frontend
        end
        %% Reusable Components subgraph
        subgraph "Reusable Components"
            direction TB
            RC["General Components"]:::frontend
            UI["UI Library"]:::frontend
        end
        %% Styles & Assets subgraph
        subgraph "Styles & Assets"
            direction TB
            GA["Globals CSS (app)"]:::frontend
            GS["Globals CSS (styles)"]:::frontend
        end
    end

    subgraph "Hooks & Utilities"
        direction TB
        HM["use-mobile"]:::utility
        HT["use-toast"]:::utility
        UF["Utility Functions"]:::utility
    end

    subgraph "API/Backend"
        direction TB
        API["Submit Form API"]:::backend
    end

    subgraph "External Services"
        direction TB
        GSAPI["Google Sheets API"]:::external
    end

    subgraph "Deployment & Configuration"
        direction TB
        TC["Tailwind CSS"]:::deployment
        NXC["Next.js Config"]:::deployment
    end

    %% Connections
    User --> LP
    User --> CP
    User --> CSP

    %% Pages submit data to API
    LP -->|"submits"| API
    CP -->|"submits"| API
    CSP -->|"submits"| API

    %% API sends data to external service
    API -->|"saves"| GSAPI

    %% Pages use reusable components
    LP -->|"composes"| RC
    CP -->|"composes"| RC
    CSP -->|"composes"| RC

    %% Pages are styled using global styles
    LP -->|"styled-by"| GA
    LP -->|"styled-by"| GS
    CP -->|"styled-by"| GA
    CP -->|"styled-by"| GS
    CSP -->|"styled-by"| GA
    CSP -->|"styled-by"| GS

    %% Reusable Components integrate hooks and utilities
    RC -->|"integrates"| HM
    RC -->|"integrates"| HT
    RC -->|"uses"| UF

    %% Deployment configuration applied to Frontend and API
    TC -->|"configures"| LP
    TC -->|"configures"| API
    NXC -->|"configures"| LP
    NXC -->|"configures"| API

    %% UI Library is part of reusable components
    RC -->|"enhances"| UI

    %% Styles & Assets contribute to Frontend presentation
    GA -->|"applies"| LP
    GS -->|"applies"| LP

    %% Click Events
    click LP "https://github.com/djmiguelr/fcfcamps/blob/main/app/page.tsx"
    click CP "https://github.com/djmiguelr/fcfcamps/blob/main/app/checkout/page.tsx"
    click CSP "https://github.com/djmiguelr/fcfcamps/blob/main/app/checkout/success/page.tsx"
    click LO "https://github.com/djmiguelr/fcfcamps/blob/main/app/layout.tsx"
    click SM "https://github.com/djmiguelr/fcfcamps/blob/main/app/sitemap.ts"
    click GA "https://github.com/djmiguelr/fcfcamps/blob/main/app/globals.css"
    click GS "https://github.com/djmiguelr/fcfcamps/blob/main/styles/globals.css"
    click API "https://github.com/djmiguelr/fcfcamps/blob/main/app/api/submit-form/route.ts"
    click HM "https://github.com/djmiguelr/fcfcamps/blob/main/hooks/use-mobile.tsx"
    click HT "https://github.com/djmiguelr/fcfcamps/blob/main/hooks/use-toast.ts"
    click UF "https://github.com/djmiguelr/fcfcamps/blob/main/lib/utils.ts"
    click TC "https://github.com/djmiguelr/fcfcamps/blob/main/tailwind.config.ts"
    click NXC "https://github.com/djmiguelr/fcfcamps/blob/main/next.config.mjs"
    click RC "https://github.com/djmiguelr/fcfcamps/tree/main/components"
    click UI "https://github.com/djmiguelr/fcfcamps/tree/main/components/ui"

    %% Styles
    classDef frontend fill:#d0e6f7,stroke:#333,stroke-width:2px
    classDef backend fill:#fad4c4,stroke:#333,stroke-width:2px
    classDef utility fill:#f7e6d0,stroke:#333,stroke-width:2px
    classDef external fill:#e0d4f7,stroke:#333,stroke-width:2px
    classDef deployment fill:#d4f7d0,stroke:#333,stroke-width:2px
```
