# andresbaquiax/ecommerce-front architecture

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

- Interactive diagram: https://gitdiagram.com/andresbaquiax/ecommerce-front
- Repository: https://github.com/andresbaquiax/ecommerce-front

## Overview

##### Project Type and Purpose
- This is a single‐page application (SPA) frontend for an enterprise ecommerce system. It’s built with React 18 and Vite, and designed to be hosted as static assets (e.g., on Vercel or a CDN). It communicates with backend APIs (auth, inventory, orders, invoices, reports, etc.) and a PostgreSQL database.

##### File Structure
- Top‐level artifacts:
- src/ – Application source code subdivided into:
– _mock: dummy data for local development.
– app.tsx & main.tsx: app bootstrap, router, theme provider.
– layouts/: page shell implementations (auth vs dashboard) and header/nav pieces.
– pages/: route views and route titles.
– sections/: composition of components into views (cart, blog, checkout, overview, products, users, etc.).
– services/: HTTP client and per‐resource API wrappers (authService, usuarios, inventario, pedidos, reportes, etc.).
– context/ & hooks/: global state management (AuthContext, CartContext) and custom hooks (useAuth, useRole).
– theme/: design system (palette, typography, shadows) and theme provider.
– utils/: generic helpers (format-number, format-time).
- Config/build files: vite.config.ts, tsconfig.json, eslint.config.mjs, prettier.config.mjs, vercel.json.

##### README
- Confirms React+Vite SPA.
- Lists features (inventory, roles, dashboard, analytics, PostgreSQL backend).
- No backend code here—frontend calls external APIs.
- Mentions HMR, ESLint, build & preview scripts.

##### Main Components
a. Client Browser (User Agent)
b. Static File Host (e.g., Vercel/CDN)
c. React Application (SPA)
- UI Layer: layouts, pages, sections, components
- State Layer: Context Providers (AuthContext, CartContext)
- Service Layer: HTTP client (src/services/http.ts) + API modules
- Theme Layer: theme-provider, design system
- Utility Layer: hooks, utils
d. External Backend APIs (Auth API, Inventory API, Orders API, Reports API, Users API)
e. Database (PostgreSQL) behind the APIs
f. (Optionally) CI/CD Pipeline (GitHub → Vercel)

##### Relationships & Interactions
- Browser requests index.html from Static File Host → downloads JS/CSS bundle
- React SPA bootstraps: ThemeProvider → Router → ContextProviders
- User interacts with UI → triggers component event → calls service (e.g., authService.login)
- service → http.ts → HTTP request to External Backend API
- Backend API → Business logic → PostgreSQL
- Response flows back through http.ts → service module → updates Context or component state → UI re‐renders

##### Architectural Patterns & Principles
- Component-based UI (atomic & composite components)
- Separation of concerns:
- Presentation (components, sections, pages)
- State (Context + Hooks)
- Data access (services + http client)
- Theming (theme directory)
- Declarative routing (React Router via src/routes)
- Mock data injection for dev/test (_mock)
- Standards: ESLint, Prettier, HMR

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Browser"
        Browser["User Browser"]:::external
    end

    %% Hosting
    Browser -->|requests index.html| Host["Static File Host (CDN/Vercel)"]:::external
    Host -->|serves JS/CSS bundles| Browser

    %% React App Bootstrap
    subgraph "React Application (SPA)" 
        direction TB
        AppBootstrap["app.tsx & main.tsx"]:::bootstrap
        subgraph "UI Layer"
            direction TB
            Components["Components"]:::ui
            Layouts["Layouts"]:::ui
            Pages["Pages"]:::ui
            Sections["Sections"]:::ui
            Routes["Routes"]:::ui
        end
        subgraph "State Layer"
            direction TB
            AuthContext["AuthContext"]:::state
            CartContext["CartContext"]:::state
            useAuth["useAuth Hook"]:::state
            useRole["useRole Hook"]:::state
            HooksIndex["Hooks Index"]:::state
        end
        subgraph "Service Layer"
            direction TB
            HTTPClient["HTTP Client"]:::service
            AuthService["authService"]:::service
            UsuariosAPI["usuarios API"]:::service
            InventarioAPI["inventario API"]:::service
            PedidosAPI["pedidos API"]:::service
            ComprasAPI["compras API"]:::service
            ProveedoresAPI["proveedores API"]:::service
            ReportesAPI["reportes API"]:::service
            RolesAPI["roles API"]:::service
            LegacyAPI["legacy API wrapper"]:::service
            APIConfig["generic API config"]:::service
        end
        subgraph "Theme Layer"
            direction TB
            ThemeProvider["Theme Provider"]:::theme
            ThemeConfig["Theme Config & Creation"]:::theme
            CoreDesignTokens["Core Design Tokens"]:::theme
            ThemeTypes["Theme Types & Extensions"]:::theme
        end
        subgraph "Utility Layer"
            direction TB
            FormatNumber["format-number"]:::util
            FormatTime["format-time"]:::util
        end
        MockData["Mock Data (_mock)"]:::dev
        ConfigFiles["Build & Config Files"]:::config
    end

    Browser -->|loads bundle| AppBootstrap
    AppBootstrap --> Components
    AppBootstrap --> Layouts
    AppBootstrap --> Pages
    AppBootstrap --> Sections
    AppBootstrap --> Routes
    Components --> AuthContext
    Components --> CartContext
    AuthContext --> useAuth
    AuthContext --> useRole
    useAuth --> HooksIndex
    useRole --> HooksIndex
    Components --> HTTPClient
    HTTPClient --> AuthService
    HTTPClient --> UsuariosAPI
    HTTPClient --> InventarioAPI
    HTTPClient --> PedidosAPI
    HTTPClient --> ComprasAPI
    HTTPClient --> ProveedoresAPI
    HTTPClient --> ReportesAPI
    HTTPClient --> RolesAPI
    HTTPClient --> LegacyAPI
    HTTPClient --> APIConfig
    AppBootstrap --> ThemeProvider
    ThemeProvider --> ThemeConfig
    ThemeConfig --> CoreDesignTokens
    ThemeConfig --> ThemeTypes
    Components --> FormatNumber
    Components --> FormatTime
    AppBootstrap --> MockData
    AppBootstrap --> ConfigFiles

    %% External Systems
    subgraph "External Backend APIs"
        direction TB
        AuthAPI["Auth API"]:::external
        InventoryAPI["Inventory API"]:::external
        OrdersAPI["Orders API"]:::external
        ReportsAPIExt["Reports API"]:::external
        UsersAPI["Users API"]:::external
    end
    subgraph "Database"
        DB[(PostgreSQL Database)]:::db
    end

    AuthService -->|calls| AuthAPI
    UsuariosAPI -->|calls| UsersAPI
    InventarioAPI -->|calls| InventoryAPI
    PedidosAPI -->|calls| OrdersAPI
    ReportesAPI -->|calls| ReportsAPIExt
    RolesAPI -->|calls| AuthAPI
    LegacyAPI -->|calls| InventoryAPI
    ComprasAPI -->|calls| OrdersAPI
    ProveedoresAPI -->|calls| UsersAPI
    APIConfig -->|configures| HTTPClient

    AuthAPI -->|queries| DB
    InventoryAPI -->|queries| DB
    OrdersAPI -->|queries| DB
    ReportsAPIExt -->|queries| DB
    UsersAPI -->|queries| DB

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        GitHub["GitHub Repo"]:::external
        VercelCI["Vercel Deployment"]:::external
    end
    GitHub -->|push| VercelCI
    VercelCI -->|deploy static assets| Host

    %% Click Events
    click AppBootstrap "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/app.tsx"
    click AppBootstrap "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/main.tsx"
    click Components "https://github.com/andresbaquiax/ecommerce-front/tree/main/src/components/"
    click Layouts "https://github.com/andresbaquiax/ecommerce-front/tree/main/src/layouts/"
    click Pages "https://github.com/andresbaquiax/ecommerce-front/tree/main/src/pages/"
    click Sections "https://github.com/andresbaquiax/ecommerce-front/tree/main/src/sections/"
    click Routes "https://github.com/andresbaquiax/ecommerce-front/tree/main/src/routes/"
    click AuthContext "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/context/AuthContext.jsx"
    click CartContext "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/context/CartContext.tsx"
    click useAuth "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/hooks/use-auth.ts"
    click useRole "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/hooks/use-role.ts"
    click HooksIndex "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/hooks/index.ts"
    click HTTPClient "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/http.ts"
    click AuthService "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/authService.js"
    click UsuariosAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/usuarios.ts"
    click InventarioAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/inventario.ts"
    click PedidosAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/pedidos.ts"
    click ComprasAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/compras.ts"
    click ProveedoresAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/proveedores.ts"
    click ReportesAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/reportes.ts"
    click RolesAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/roles.ts"
    click LegacyAPI "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/api.legacy.js"
    click APIConfig "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/services/api.ts"
    click ThemeProvider "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/theme/theme-provider.tsx"
    click ThemeConfig "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/theme/theme-config.ts"
    click CoreDesignTokens "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/theme/core/index.ts"
    click FormatNumber "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/utils/format-number.ts"
    click FormatTime "https://github.com/andresbaquiax/ecommerce-front/blob/main/src/utils/format-time.ts"
    click MockData "https://github.com/andresbaquiax/ecommerce-front/tree/main/src/_mock/"
    click ConfigFiles "https://github.com/andresbaquiax/ecommerce-front/blob/main/vite.config.ts"

    %% Styles
    classDef ui fill:#D6E8FF,stroke:#1E5BB8,color:#000
    classDef state fill:#E6F7FF,stroke:#1E90FF,color:#000
    classDef service fill:#E8F5E9,stroke:#2E7D32,color:#000
    classDef theme fill:#FFF3E0,stroke:#EF6C00,color:#000
    classDef util fill:#F5F5F5,stroke:#9E9E9E,color:#000
    classDef dev fill:#FCE4EC,stroke:#C2185B,color:#000
    classDef config fill:#ECEFF1,stroke:#455A64,color:#000
    classDef external fill:#FFF9C4,stroke:#F9A825,color:#000
    classDef db fill:#E0F7FA,stroke:#006064,color:#000
    classDef bootstrap fill:#E8EAF6,stroke:#3949AB,color:#000
```
