# thusspokedata/kooben-fe architecture

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

## Overview

##### Project Type and Purpose
- This is a modern e-commerce platform for a furniture store, built as a full-stack application.
- The frontend is built with Next.js, TypeScript, and Mantine for UI, with external integrations such as Clerk (for authentication), Axios (for HTTP calls), TanStack Query (for state management/fetching), and a custom error handling system.
- The backend is separate and developed using NestJS (see the kooben-be repo).
- The project uses Docker for containerization, with CI/CD and code quality/security pipelines implemented via GitHub Actions, Amazon CodeGuru, and TruffleHog.

##### Analyzing the File Structure
- The project is primarily organized within the /src directory. The “app” folder is structured into several key subdirectories:
- (auth) for authentication flows (sign-in and sign-up)
- (checkout) for checkout processes including cart and order verification UI components
- (shop) for catalog and product details, indicating a clear separation of concerns for catalog browsing and product detail presentation.
- There are separate directories for reusable components (/components), assets (/assets), styles (/public and /styles), and state management (/store).
- API functions are encapsulated under /src/api as well as a specific segment under /src/app/api for user-related endpoints.
- You also have global layout and utility functionality which reflects a modular and component-based architecture.

a. Main Components:
- Frontend layer: Next.js application including pages, components, hooks, state management, and UI-specific modules (Mantine-based styling).
- Authentication: Integration with Clerk for handling user authentication.
- State Management & Data Fetching: TanStack Query (integrated in API calls using Axios) and custom error handling.
- Backend Interface: A separate backend service built with NestJS (from the related repository) that the Next.js app communicates with via REST APIs.
- External Services: Docker (containerization), GitHub Actions (CI/CD), and Code scanning/security tools like Amazon CodeGuru and TruffleHog.
- Related DevOps & CI/CD: GitHub Actions workflows, Dockerfile, and docker-compose configuration that outline how the application is built, tested, and deployed.

b. Relationships/Interactions:
- The Next.js frontend interacts with the backend API endpoints to fetch product data, user data, and process transactions.
- The application calls external APIs (via Axios), with TanStack Query managing caching and state updates.
- Clerk is used for authentication throughout the frontend, ensuring secure sign-in/signup flows.
- Data flows from the state management layer (/store, hooks) to various components (UI elements in /components, pages in /app).
- CI/CD processes automatically build and containerize the application via Docker and GitHub Actions; these processes then push images to Docker Hub.
- Development and security tools (Amazon CodeGuru, TruffleHog) operate outside the main runtime architecture as part of code quality and security pipelines.

c. Architectural Patterns & Principles:
- Modular design: A clear separation between pages, shared components, API hooks, and reusable utilities.
- Layered architecture: UI layer, business logic layer (state management and services), and the backend API layer.
- Separation of concerns: Authentication, checkout workflows, and catalog browsing are segmentized into different directories.
- Containerization and CI/CD integrate deployment best practices.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Frontend Layer
  subgraph "Frontend Layer (Next.js)"
    FE_Root["Frontend Root (/src)"]:::frontend
    GlobalPages["Global Layout & Pages (/src/app/layout.tsx, /src/app/page.tsx)"]:::frontend
    FE_Root --> GlobalPages

    %% Authentication Subgraph
    subgraph "Authentication"
      AuthDir["Auth Directory (/src/app/(auth))"]:::frontend
      SignIn["Sign-In Page (/src/app/(auth)/sign-in/[[...sign-in]]/page.tsx)"]:::frontend
      SignUp["Sign-Up Page (/src/app/(auth)/sign-up/[[...sign-up]]/page.tsx)"]:::frontend
      ClerkAPI["Clerk API Endpoint (/src/app/api/users/clerk/[clerkId]/route.ts)"]:::frontend
      AuthDir --> SignIn
      AuthDir --> SignUp
      AuthDir --> ClerkAPI
    end
    GlobalPages --> AuthDir

    %% Checkout Process Subgraph
    subgraph "Checkout Process"
      CheckoutDir["Checkout Directory (/src/app/(checkout))"]:::frontend
      Carrito["Carrito (/src/app/(checkout)/carrito)"]:::frontend
      CarritoUI["Carrito UI (/src/app/(checkout)/carrito/ui)"]:::frontend
      Entrega["Entrega (/src/app/(checkout)/detalles-de-entrega)"]:::frontend
      EntregaUI["Entrega UI (/src/app/(checkout)/detalles-de-entrega/ui)"]:::frontend
      Verificar["Verificar Compra (/src/app/(checkout)/verificar-compra)"]:::frontend
      VerificarUI["Verificar Compra UI (/src/app/(checkout)/verificar-compra/ui)"]:::frontend
      CarritoVacio["Carrito Vacío Page (/src/app/(checkout)/carrito-vacio/page.tsx)"]:::frontend
      CheckoutDir --> Carrito
      Carrito --> CarritoUI
      CheckoutDir --> Entrega
      Entrega --> EntregaUI
      CheckoutDir --> Verificar
      Verificar --> VerificarUI
      CheckoutDir --> CarritoVacio
    end
    GlobalPages --> CheckoutDir

    %% Catalog Browsing Subgraph
    subgraph "Catalog Browsing"
      ShopDir["Shop Directory (/src/app/(shop))"]:::frontend
      CatalogPage["Catalog Page (/src/app/(shop)/catalogo/page.tsx)"]:::frontend
      ProdDetails["Product Details Page (/src/app/(shop)/catalogo/detalles-producto/[slug]/page.tsx)"]:::frontend
      CatalogComponents["Catalog Components (/src/components/catalogo)"]:::frontend
      ShopDir --> CatalogPage
      ShopDir --> ProdDetails
      CatalogComponents --> CardCatalogo["CardCatalogo (/src/components/catalogo/CardCatalogo.tsx)"]:::frontend
      CatalogComponents --> CatalogClient["CatalogClient (/src/components/catalogo/CatalogClient.tsx)"]:::frontend
      CatalogComponents --> CatalogSkeleton["CatalogSkeleton (/src/components/catalogo/CatalogSkeleton.tsx)"]:::frontend
    end
    GlobalPages --> ShopDir

    %% State Management & Data Fetching Subgraph
    subgraph "State Management & Data Fetching"
      Store["State Store (/src/store)"]:::services
      Services["Data Fetch Services (/src/services)"]:::services
      APIFunc["API Functions (/src/api)"]:::services
      Store --> Services
      Services --> APIFunc
    end
    GlobalPages --> Store
    GlobalPages --> Services
  end

  %% Backend Service
  subgraph "Backend Service (NestJS)"
    Backend["Backend (NestJS service)"]:::backend
    APIFunc -->|"calls_via_Axios/TanStack"| Backend
  end

  %% CI/CD & Containerization
  subgraph "CI/CD & Containerization"
    Dockerfile["Dockerfile (project root)"]:::cicd
    DockerCompose["docker-compose.yml (project root)"]:::cicd
    GitHub["GitHub Actions (.github/workflows)"]:::cicd
    Dockerfile --> DockerCompose
    GitHub -->|deploys_to| FE_Root
    GitHub -->|deploys_to| Backend
  end

  %% External Integrations & Utilities
  subgraph "External Integrations & Utilities"
    Clerk["Clerk (Authentication)"]:::external
    Axios["Axios (HTTP Client)"]:::external
    TanStack["TanStack Query"]:::external
    Themings["UI Theming (/src/themes/mantine-theme.ts)"]:::external
    Errors["Error Handling (/src/utils/errors.ts)"]:::external
    AuthDir ---|integrates| Clerk
    Services ---|uses| Axios
    Services ---|manages| TanStack
    FE_Root --- Themings
    FE_Root --- Errors
  end

  %% Click Events for Frontend
  click FE_Root "https://github.com/thusspokedata/kooben-fe/tree/main//src"
  click GlobalPages "https://github.com/thusspokedata/kooben-fe/tree/main//src/app"
  click AuthDir "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(auth)"
  click SignIn "https://github.com/thusspokedata/kooben-fe/blob/main//src/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
  click SignUp "https://github.com/thusspokedata/kooben-fe/blob/main//src/app/(auth)/sign-up/[[...sign-up]]/page.tsx"
  click ClerkAPI "https://github.com/thusspokedata/kooben-fe/blob/main//src/app/api/users/clerk/[clerkId]/route.ts"
  click CheckoutDir "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)"
  click Carrito "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)/carrito"
  click CarritoUI "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)/carrito/ui"
  click Entrega "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)/detalles-de-entrega"
  click EntregaUI "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)/detalles-de-entrega/ui"
  click Verificar "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)/verificar-compra"
  click VerificarUI "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(checkout)/verificar-compra/ui"
  click CarritoVacio "https://github.com/thusspokedata/kooben-fe/blob/main//src/app/(checkout)/carrito-vacio/page.tsx"
  click ShopDir "https://github.com/thusspokedata/kooben-fe/tree/main//src/app/(shop)"
  click CatalogPage "https://github.com/thusspokedata/kooben-fe/blob/main//src/app/(shop)/catalogo/page.tsx"
  click ProdDetails "https://github.com/thusspokedata/kooben-fe/blob/main//src/app/(shop)/catalogo/detalles-producto/[slug]/page.tsx"
  click CatalogComponents "https://github.com/thusspokedata/kooben-fe/tree/main//src/components/catalogo"
  click CardCatalogo "https://github.com/thusspokedata/kooben-fe/blob/main//src/components/catalogo/CardCatalogo.tsx"
  click CatalogClient "https://github.com/thusspokedata/kooben-fe/blob/main//src/components/catalogo/CatalogClient.tsx"
  click CatalogSkeleton "https://github.com/thusspokedata/kooben-fe/blob/main//src/components/catalogo/CatalogSkeleton.tsx"
  click Store "https://github.com/thusspokedata/kooben-fe/tree/main//src/store"
  click Services "https://github.com/thusspokedata/kooben-fe/tree/main//src/services"
  click APIFunc "https://github.com/thusspokedata/kooben-fe/tree/main//src/api"

  %% Click Events for CI/CD & Containerization
  click Dockerfile "https://github.com/thusspokedata/kooben-fe/tree/main//Dockerfile"
  click DockerCompose "https://github.com/thusspokedata/kooben-fe/blob/main//docker-compose.yml"
  click GitHub "https://github.com/thusspokedata/kooben-fe/tree/main//.github/workflows"

  %% Click Events for External Integrations & Utilities
  click Themings "https://github.com/thusspokedata/kooben-fe/blob/main//src/themes/mantine-theme.ts"
  click Errors "https://github.com/thusspokedata/kooben-fe/blob/main//src/utils/errors.ts"

  %% Styles
  classDef frontend fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
  classDef backend fill:#c8e6c9,stroke:#43a047,stroke-width:2px;
  classDef cicd fill:#ffe082,stroke:#ffb300,stroke-width:2px;
  classDef external fill:#fff9c4,stroke:#fdd835,stroke-width:2px;
  classDef services fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;
```
