# the-honest-ingredients-org/thi-frontend-dev architecture

> Architecture diagram of the GitHub repository the-honest-ingredients-org/thi-frontend-dev, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/the-honest-ingredients-org/thi-frontend-dev
- Repository: https://github.com/the-honest-ingredients-org/thi-frontend-dev

## Overview

##### Main Components
- Next.js Frontend: Represent the Next.js application as the core user interface built from the src/app directory. Divide the frontend further into submodules based on routing groups:
– Authentication Module: Located under src/app/(auth) with pages for login, registration, and password reset.
– Main (Customer-Facing) Module: Found under src/app/(root) with pages like home, products, cart, checkout, contact us, about us, order placed, and profile.
– Administrative Module: The admin section (src/app/(root)/admin) which handles site management, orders, products, and customer interactions.

- API Endpoints: Highlight the backend API routes from src/app/api. Show separate endpoints for different domains such as:
– Admin APIs (e.g., admin.ts): For administrative tasks.
– User APIs (user.ts): For user data and operations.
– Document APIs (documents/route.ts): Possibly managing content/assets.

- Utility and Data Layers:
– SWR Hooks: Represent the data fetching layer separated for admin and user (under src/swr). This custom hook layer is responsible for interacting with the APIs.
– Library Integrations: Include libraries for database operations (prismaDB.tsx in src/app/libs), payment processing (stripe.ts), and any other integrations from the libs/s3 or firebase directories.

- External Services:
– Firebase: Show the Firebase configuration (firebase/index.config.ts) which might be used for real-time data, analytics, or authentication.
– Payment Gateways: Stripe integration is found in the src/lib/stripe.ts file.

##### Relationships and Interactions
– UI Components (in the components folder) and Context Providers (in src/context) managing state.
– Frontend API calls (via SWR hooks) to backend API routes.

- API routes encapsulate business logic, then potentially call external or internal services such as the database (using Prisma in the libs folder), Stripe for payment processing, or S3 for media storage.

##### Architectural Patterns/Design Principles
- Layer Separation: Clearly distinguish the presentation layer (Next.js pages and frontend components) from the backend API layer, and further separate out the service/integration layer (Firebase, S3, Stripe, Prisma).
- Modular Design: Notice the use of logical grouping (the (auth) and (root) folders in src/app, and clear divisions in the components directory for MainPage, LoginPage, etc.).
- Client-Side Data Fetching: SWR hooks suggest a reactive data fetching mechanism that ties into Next.js’s server/client capabilities.

##### Relevant Technologies and Their Roles
- Next.js: As the framework for the full-stack application.
- React: For UI components.
- SWR: For client-side data fetching and caching.
- Prisma (likely): For database interactions via src/app/libs/prismaDB.tsx.
- Stripe: For payment processes via src/lib/stripe.ts.
- Firebase & AWS S3: For real-time services, authentication/configuration, and asset storage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        F_Main["Next.js Frontend"]:::frontend
        F_Auth["Authentication Module"]:::frontend
        F_Cust["Customer-Facing Module"]:::frontend
        F_Admin["Administrative Module"]:::frontend
    end

    %% API Layer
    subgraph "Backend APIs"
        API_Admin["Admin API Endpoint"]:::api
        API_User["User API Endpoint"]:::api
        API_Doc["Document API Endpoint"]:::api
    end

    %% Data & Utility Layer
    subgraph "Data & Utility"
        SWR["SWR Hooks (Data Fetching Layer)"]:::utility
        DB["Database Integration (Prisma)"]:::utility
        Stripe["Payment Processing (Stripe)"]:::utility
    end

    %% External Services Layer
    subgraph "External Services"
        Firebase["Firebase Integration"]:::external
        S3["AWS S3 Integration"]:::external
    end

    %% Connections from Frontend Modules to Data Fetching Layer
    F_Auth -->|"calls"| SWR
    F_Cust -->|"calls"| SWR
    F_Admin -->|"calls"| SWR

    %% Connections from Data Fetching Layer to API Endpoints
    SWR -->|"fetches"| API_Admin
    SWR -->|"fetches"| API_User
    SWR -->|"fetches"| API_Doc

    %% API Endpoints use Database Integration
    API_Admin -->|"queries"| DB
    API_User -->|"queries"| DB
    API_Doc -->|"queries"| DB

    %% Specific API interactions with Utility Services
    API_User -->|"payments"| Stripe
    API_Admin -->|"media"| S3

    %% Authentication uses External Service
    F_Auth -->|"authenticates"| Firebase

    %% Click Events
    click F_Main "https://github.com/the-honest-ingredients-org/thi-frontend-dev/tree/master/src/app"
    click F_Auth "https://github.com/the-honest-ingredients-org/thi-frontend-dev/tree/master/src/app/(auth)"
    click F_Cust "https://github.com/the-honest-ingredients-org/thi-frontend-dev/tree/master/src/app/(root)"
    click F_Admin "https://github.com/the-honest-ingredients-org/thi-frontend-dev/tree/master/src/app/(root)/admin"
    click API_Admin "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/src/app/api/admin/admin.ts"
    click API_User "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/src/app/api/user/user.ts"
    click API_Doc "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/src/app/api/documents/route.ts"
    click SWR "https://github.com/the-honest-ingredients-org/thi-frontend-dev/tree/master/src/swr"
    click DB "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/src/app/libs/prismaDB.tsx"
    click Stripe "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/src/lib/stripe.ts"
    click Firebase "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/firebase/index.config.ts"
    click S3 "https://github.com/the-honest-ingredients-org/thi-frontend-dev/blob/master/s3/index.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px;
```
