# jgudo/ecommerce-react architecture

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

- Interactive diagram: https://gitdiagram.com/jgudo/ecommerce-react
- Repository: https://github.com/jgudo/ecommerce-react

## Overview

##### Main Components
- Frontend (React Application):
- Located in the “src” folder along with “public” assets.
- Contains views (pages for home, shop, product display, admin, checkout, authentication, error pages), components (both common UI elements and domain-specific elements like basket and product listings), and routing files (AdminRoute, ClientRoute, PublicRoute, etc.).
- Manages state using Redux (actions, reducers, sagas, store) and uses custom hooks and utilities.
- Backend (Firebase and Cloud Functions):
- Firebase configuration files such as firebase.json, .firebaserc, firestore.rules, database.rules.json indicate that Firebase is used for hosting, authentication, and database management.
- The “functions” directory contains Firebase Cloud Functions (index.js) that might be used for server-side business logic or processing webhooks.
- Database:
- Cloud Firestore is the primary database (referenced by firestore rules, indexes, and configuration in the README).
- External Services and Infrastructure:
- Firebase Authentication is in place to handle user sign up, login, and possibly role assignment (e.g., distinguishing ADMIN and USER roles).
- Deployment and CI/CD pipelines are available through GitHub Actions (see .github/workflows/main.yml) and Firebase Hosting.

##### Architecture Flow and Interactions
- The React frontend interacts directly with Firebase services through the “src/services/firebase.js” for authentication, Firestore CRUD operations, and potentially storage.
- Redux (with actions, reducers, sagas) acts as the business logic layer in the frontend, handling asynchronous calls to Firebase (via sagas such as authSaga, productSaga, etc.).
- Cloud Functions provide additional server-side operations when needed. They are triggered by events or called directly from the frontend.
- The e-commerce admin functionality is achieved by granting ADMIN privileges (manually toggled via Firestore user collection) and subsequently exposing additional CRUD operations.

##### Architectural Patterns and Principles
- Component-based Architecture: The application is separated into reusable components (organized in folders like components/basket, components/common, components/product, etc.) and pages (under views).
- Separation of Concerns: There is a clear distinction between the presentation layer (React views/components), the state management layer (Redux, sagas), and the backend services (Firebase Authentication, Firestore, and Cloud Functions).
- Routing & Access Control: With different route types (AdminRoute, ClientRoute, PublicRoute), the design captures different access levels within the app.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F1["React App (src/)"]:::frontend
        F2["Static Assets (public/)"]:::frontend
        F3["Views (src/views/)"]:::frontend
        F4["Components (src/components/)"]:::frontend
        F5["Routing (src/routers/)"]:::frontend
        F6["Redux State Management (src/redux/)"]:::frontend
        F7["Firebase Service (src/services/firebase.js)"]:::service
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1["Firebase Config & Hosting"]:::backend
        B2["Cloud Functions (functions/)"]:::backend
        B3["Firebase Auth & Services"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB1["Cloud Firestore Database"]:::database
    end

    %% CI/CD and Deployment
    subgraph "CI/CD"
        CI1["GitHub Actions (.github/workflows/main.yml)"]:::cicd
    end

    %% Interconnections
    F1 -->|"dispatches"| F6
    F1 -->|"renders"| F3
    F1 -->|"includes"| F4
    F1 -->|"routes via"| F5
    F6 -->|"triggers async"| F7
    F7 -->|"APIcalls"| B3
    B3 -->|"CRUDops"| DB1
    B2 <-->|"triggers/updates"| DB1
    CI1 -->|"deploys"| B1
    B1 -->|"configures"| B3

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef database fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef cicd fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
    classDef service fill:#D1C4E9,stroke:#4A148C,stroke-width:2px;

    %% Click Events
    click F1 "https://github.com/jgudo/ecommerce-react/tree/master/src/"
    click F2 "https://github.com/jgudo/ecommerce-react/tree/master/public/"
    click F3 "https://github.com/jgudo/ecommerce-react/tree/master/src/views/"
    click F4 "https://github.com/jgudo/ecommerce-react/tree/master/src/components/"
    click F5 "https://github.com/jgudo/ecommerce-react/tree/master/src/routers/"
    click F6 "https://github.com/jgudo/ecommerce-react/tree/master/src/redux/"
    click F7 "https://github.com/jgudo/ecommerce-react/blob/master/src/services/firebase.js"
    click B2 "https://github.com/jgudo/ecommerce-react/tree/master/functions/"
    click B1 "https://github.com/jgudo/ecommerce-react/blob/master/firebase.json"
    click CI1 "https://github.com/jgudo/ecommerce-react/blob/master/.github/workflows/main.yml"
```
