# proftanish/ecommerce-app architecture

> Architecture diagram of the GitHub repository proftanish/ecommerce-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/proftanish/ecommerce-app
- Repository: https://github.com/proftanish/ecommerce-app

## Overview

##### Project type and purpose
- This is a single‑page application (SPA) built with React, TypeScript, and Vite.
- Its purpose appears to be an e‑commerce storefront: browsing products, user authentication (via Supabase), shopping cart, and order placement.

##### File structure
- Top‐level:
- public / index.html – static entry point
- src/
– components/ (presentational UI components)
– features/ (feature modules for auth, cart, products, orders, customer)
– pages/ (route targets: Homepage, Login, Signup, ProductDetails, StorePage, etc.)
– services/ (API clients for auth, products, orders, customers, Supabase)
– store.ts (Redux or Redux Toolkit store configuration)
– lib/, utils/, hooks/ (shared utilities, type definitions, custom hooks)
- Configuration:
- vite.config.ts – build/dev server
- tsconfig*.json – TypeScript setups
- eslint.config.js, postcss.config.js, tailwind.config.js

##### Extract additional insights from README
- Focuses on React + TypeScript + Vite best practices
- Encourages ESLint, fast refresh via official Vite React plugins

##### Main components
a. Frontend (Browser / React SPA)
- UI Layer: components/, pages/
- State Layer: store.ts + feature slices (cartSlice, etc.)
- Hooks Layer: custom hooks for localStorage, routing, forms
- Services Layer: apiAuth, apiProducts, apiOrder, apiCustomer, supabase client
b. External Services
- Supabase (Auth, Database)
- Potential third‑party (e.g., payment gateway if added later)
c. Build & Deployment
- Vite dev server / build pipeline
- Static hosting (Netlify/Vercel/AWS S3 + CloudFront)

##### Relationships & data flows
- User in Browser → React Router → Page component → dispatch Redux action → service function
- Service function → HTTP request → Supabase REST / GraphQL → Database
- Supabase → HTTP response → service → Redux dispatch/update → UI re‑render
- LocalStorage hook for persisting cart or auth token

##### Architectural patterns & design principles
- Feature‑based module organization (features/authentication, features/cart, etc.)
- Container‑presentational segregation: pages & feature containers vs. reused UI components
- Single source of truth in Redux store (store.ts + slices)
- Separation of concerns: API calls abstracted in services/, business logic encapsulated in feature hooks

##### Detail
- Every major directory as a component or subcomponent
- Where cross‑cutting utilities (hooks/, lib/, utils/) are consumed
- Don’t omit the build step (Vite) or static assets (public/)
- High‐level runtime: Browser ↔ Supabase

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main Browser Container
    subgraph "React SPA (Vite)" 
        direction TB

        %% UI Layer
        subgraph "UI Layer"
            direction TB
            Components["Presentational Components"]:::uiLayer
            AppLayout["Core Layout Component"]:::uiLayer
            UIPrimitives["UI Primitives"]:::uiLayer
            Pages["Pages (Route Targets)"]:::uiLayer
        end

        %% State Layer
        subgraph "State Layer"
            direction TB
            Store["Redux Store Configuration"]:::state
            CartSlice["Cart Feature Slice"]:::state
            AuthHooks["Auth Hooks & Slices"]:::state
        end

        %% Hooks Layer
        subgraph "Hooks Layer"
            direction TB
            CustomHooks["Custom Hooks"]:::hooks
        end

        %% Services Layer
        subgraph "Services Layer"
            direction TB
            ApiAuth["Authentication API Client"]:::services
            ApiProducts["Products API Client"]:::services
            ApiOrder["Orders API Client"]:::services
            ApiCustomer["Customer API Client"]:::services
            SupabaseClient["Supabase Client Config"]:::services
        end

        %% Shared Utilities
        SharedUtils["Shared Utilities (lib/, utils/)"]:::shared

    end

    %% External Systems
    Supabase["Supabase (Auth & DB)"]:::external

    %% Static Assets and Build Config
    StaticAssets["Static Assets (public/index.html)"]:::config
    ViteConfig["Vite Config"]:::config
    TSConfig["TypeScript Configs"]:::config

    %% Data Flows
    User["User"]:::external
    User -->|"interacts"| Components
    Components -->|"routes"| Pages
    Pages -->|"dispatch action"| Store
    Store -->|"reads/writes"| CartSlice
    Store -->|"invokes"| AuthHooks
    AuthHooks -->|"calls"| ApiAuth
    Pages -->|"calls"| ApiProducts
    Pages -->|"calls"| ApiOrder
    Pages -->|"calls"| ApiCustomer
    ApiAuth -->|"HTTP request"| Supabase
    ApiProducts -->|"HTTP request"| Supabase
    ApiOrder -->|"HTTP request"| Supabase
    ApiCustomer -->|"HTTP request"| Supabase
    Supabase -->|"response"| SupabaseClient
    SupabaseClient -->|"updates"| Store
    Store -->|"state update"| Components

    %% Config and Build
    ViteConfig -.->|"serves SPA"| User
    TSConfig -.->|"typing"| Store

    StaticAssets -.->|"served"| User

    %% Click Events
    click Components "https://github.com/proftanish/ecommerce-app/tree/main/src/components/"
    click AppLayout "https://github.com/proftanish/ecommerce-app/blob/main/src/components/AppLayout.tsx"
    click UIPrimitives "https://github.com/proftanish/ecommerce-app/tree/main/src/components/ui/"
    click Pages "https://github.com/proftanish/ecommerce-app/tree/main/src/pages/"
    click Store "https://github.com/proftanish/ecommerce-app/blob/main/src/store.ts"
    click CartSlice "https://github.com/proftanish/ecommerce-app/blob/main/src/features/cart/cartSlice.ts"
    click AuthHooks "https://github.com/proftanish/ecommerce-app/blob/main/src/features/authentication/useLogin.ts"
    click AuthHooks "https://github.com/proftanish/ecommerce-app/blob/main/src/features/authentication/useSignup.ts"
    click AuthHooks "https://github.com/proftanish/ecommerce-app/blob/main/src/features/authentication/useLogout.ts"
    click SupabaseClient "https://github.com/proftanish/ecommerce-app/blob/main/src/services/supabase.ts"
    click ApiAuth "https://github.com/proftanish/ecommerce-app/blob/main/src/services/apiAuth.ts"
    click ApiProducts "https://github.com/proftanish/ecommerce-app/blob/main/src/services/apiProducts.ts"
    click ApiOrder "https://github.com/proftanish/ecommerce-app/blob/main/src/services/apiOrder.ts"
    click ApiCustomer "https://github.com/proftanish/ecommerce-app/blob/main/src/services/apiCustomer.ts"
    click CustomHooks "https://github.com/proftanish/ecommerce-app/tree/main/src/hooks/"
    click SharedUtils "https://github.com/proftanish/ecommerce-app/tree/main/src/lib/"
    click SharedUtils "https://github.com/proftanish/ecommerce-app/tree/main/src/utils/"
    click StaticAssets "https://github.com/proftanish/ecommerce-app/blob/main/public/index.html"
    click ViteConfig "https://github.com/proftanish/ecommerce-app/blob/main/vite.config.ts"
    click TSConfig "https://github.com/proftanish/ecommerce-app/blob/main/tsconfig.json"

    %% Styles
    classDef uiLayer fill:#e0f7fa,stroke:#0288d1,color:#000
    classDef state fill:#b3e5fc,stroke:#1976d2,color:#000
    classDef hooks fill:#ffecb3,stroke:#f9a825,color:#000
    classDef services fill:#c8e6c9,stroke:#388e3c,color:#000
    classDef external fill:#ffe0b2,stroke:#f57c00,color:#000
    classDef config fill:#d1c4e9,stroke:#8e24aa,color:#000
    classDef shared fill:#f0f4c3,stroke:#afb42b,color:#000
```
