# saurabhpratapsingh23/eco-cart-conscious-code architecture

> Architecture diagram of the GitHub repository saurabhpratapsingh23/eco-cart-conscious-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saurabhpratapsingh23/eco-cart-conscious-code
- Repository: https://github.com/saurabhpratapsingh23/eco-cart-conscious-code

## Overview

##### Project type and purpose
- This is a single-page web application (SPA) built with React, TypeScript and Vite.
- Purpose: an e-commerce style storefront with authentication, product listing, cart management and user profile pages.

##### File structure
- Top level:
- package.json / lock files and bun.lockb → dependency management and build scripts
- .env → runtime configuration (e.g. API base URLs)
- public/index.html → HTML shell served to the browser
- src folder:
- src/pages → route-based React page components (AuthPage, Homepage, CartPage, ProfilePage, NotFound)
- src/components (and components/ui) → presentational and layout components (Header, Footer, ProductCard, ProductModal, plus a full UI component library from shadcn-ui)
- src/contexts → React Context providers for AuthContext and CartContext (state management layers)
- src/hooks → custom hooks (use-mobile, use-toast)
- src/services/api.ts → HTTP client layer for talking to external REST API endpoints
- src/lib/utils.ts → shared utility functions
- src/main.tsx → React application entry point and provider wiring
- Configuration: Vite (vite.config.ts), Tailwind (tailwind.config.ts), ESLint, TypeScript (tsconfig.json)

##### README for additional insights
- Confirms tech stack: Vite, TypeScript, React, shadcn-ui, Tailwind CSS
- Mentions API_DOCUMENTATION.txt – implies a REST API contract that the front end consumes
- Deployment via Lovable (static hosting) so the build output is served as static assets

a. Main components:
- Browser / Client (SPA)
- Static asset host / CDN (serves index.html, JS, CSS)
- React Application layers:
– Presentation Layer (components & pages)
– UI Library (shadcn-ui + Tailwind)
– State Management Layer (AuthContext, CartContext)
– Service Layer (api.ts HTTP client)
- External REST API backend (authentication, products, cart endpoints)
b. Relationships and data flow:
– Browser requests index.html from CDN → loads bundle (main.js, styles)
– React router initializes page components → components dispatch actions via contexts → contexts call api.ts → HTTP requests to external API → responses flow back to contexts → re-render UI components
– UI triggers (e.g. Add to Cart) update CartContext → optional POST to /cart endpoint
c. Architectural patterns and principles:
– Component-based architecture (presentational vs. container/context)
– Separation of concerns: UI / state / services
– Context API for global state (authentication, cart)
– Layered design: Presentation → State → Service → External API
d. Key technologies:
– Vite (dev server and bundler)
– React & React Router (routing implied by pages)
– TypeScript for static typing
– Tailwind CSS + shadcn-ui for styling and UI primitives
– Fetch or Axios in api.ts for HTTP requests

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Static Hosting
    subgraph "Static Hosting/CDN" 
        direction TB
        CDN["Static Host / CDN"]:::external
    end

    %% Browser
    Browser["Browser (Client)"]:::external

    CDN --> Browser

    %% React Application Entry
    subgraph "React Application" 
        direction TB

        subgraph "Entry Point" 
            direction TB
            MainTsx["src/main.tsx"]:::entry
            AppTsx["src/App.tsx"]:::entry
        end

        Browser --> MainTsx
        MainTsx --> AppTsx

        %% Presentation Layer
        subgraph "Presentation Layer (Pages & UI)" 
            direction TB
            subgraph "Pages (Routing)" 
                direction TB
                AuthPage["AuthPage"]:::pages
                Homepage["Homepage"]:::pages
                CartPage["CartPage"]:::pages
                ProfilePage["ProfilePage"]:::pages
                NotFound["NotFound"]:::pages
            end
            subgraph "Components & UI Library" 
                direction TB
                Header["Header"]:::components
                Footer["Footer"]:::components
                ProductCard["ProductCard"]:::components
                ProductModal["ProductModal"]:::components
                LoginForm["LoginForm"]:::components
                SignupForm["SignupForm"]:::components
                UILib["UI Library (shadcn-ui + Tailwind)"]:::components
            end
            subgraph "Styles" 
                direction TB
                IndexCSS["src/index.css"]:::styles
                AppCSS["src/App.css"]:::styles
            end
        end

        AppTsx --> AuthPage
        AppTsx --> Homepage
        AppTsx --> CartPage
        AppTsx --> ProfilePage
        AppTsx --> NotFound

        AuthPage --> Header
        Homepage --> ProductCard
        ProductCard --> ProductModal
        AuthPage --> LoginForm
        AuthPage --> SignupForm
        Header --> Footer
        UILib --> Header
        UILib --> Footer
        IndexCSS --> UILib
        AppCSS --> UILib

        %% State Management
        subgraph "State Management" 
            direction TB
            AuthContext["AuthContext"]:::state
            CartContext["CartContext"]:::state
            AuthContext --> CartContext
        end

        %% Hooks
        subgraph "Custom Hooks" 
            direction TB
            UseMobile["use-mobile"]:::hooks
            UseToast["use-toast"]:::hooks
        end

        %% Service & Utils
        subgraph "Service Layer & Utils" 
            direction TB
            API["src/services/api.ts"]:::service
            Utils["src/lib/utils.ts"]:::service
            Env[".env"]:::config
        end

        %% Data Flow Connections
        Header --> AuthContext
        Footer --> CartContext
        CartPage --> CartContext
        ProfilePage --> AuthContext
        AuthContext --> UseToast
        CartContext --> UseToast
        AuthContext --> UseMobile
        CartContext --> UseMobile
        AuthContext --> API
        CartContext --> API
        API --> Utils
        API --> Env

        %% External REST API
        ExternalAPI["External REST API"]:::external
        API --> ExternalAPI
    end

    %% Build & Config Tools
    subgraph "Build & Config" 
        direction TB
        Vite["vite.config.ts"]:::config
        TailwindCfg["tailwind.config.ts"]:::config
        TSConfig["tsconfig.json / tsconfig.*.json"]:::config
        ESLint["eslint.config.js"]:::config
    end

    Vite --- MainTsx
    TailwindCfg --- UILib
    TSConfig --- MainTsx
    ESLint --- MainTsx

    %% Click Events
    click MainTsx "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/main.tsx"
    click AppTsx "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/App.tsx"
    click AuthPage "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/pages/AuthPage.tsx"
    click Homepage "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/pages/Homepage.tsx"
    click CartPage "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/pages/CartPage.tsx"
    click ProfilePage "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/pages/ProfilePage.tsx"
    click NotFound "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/pages/NotFound.tsx"
    click Header "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/components/Header.tsx"
    click Footer "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/components/Footer.tsx"
    click ProductCard "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/components/ProductCard.tsx"
    click ProductModal "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/components/ProductModal.tsx"
    click LoginForm "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/components/LoginForm.tsx"
    click SignupForm "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/components/SignupForm.tsx"
    click UILib "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/tree/main/src/components/ui/"
    click AuthContext "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/contexts/AuthContext.tsx"
    click CartContext "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/contexts/CartContext.tsx"
    click UseMobile "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/hooks/use-mobile.tsx"
    click UseToast "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/hooks/use-toast.ts"
    click API "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/services/api.ts"
    click Utils "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/lib/utils.ts"
    click IndexCSS "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/index.css"
    click AppCSS "https://github.com/saurabhpratapsingh23/eco-cart-conscious-code/blob/main/src/App.css"

    %% Styles
    classDef entry fill:#cce5ff,stroke:#004085
    classDef pages fill:#cce5ff,stroke:#004085
    classDef components fill:#cce5ff,stroke:#004085
    classDef state fill:#b8daff,stroke:#004085
    classDef hooks fill:#b8daff,stroke:#004085
    classDef service fill:#bee5eb,stroke:#0c5460
    classDef external fill:#d4edda,stroke:#155724
    classDef config fill:#e2e3e5,stroke:#383d41
    classDef styles fill:#ffeeba,stroke:#856404
```
