# okoyecharles/amazon-clone architecture

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

- Interactive diagram: https://gitdiagram.com/okoyecharles/amazon-clone
- Repository: https://github.com/okoyecharles/amazon-clone

## Overview

##### Project Type and Purpose
- This is a full-stack, single-page e-commerce application (“Amazon-Clone”) built with React (UI), Redux (state management), Firebase (auth, hosting, database, cloud functions) and Stripe (payment processing).
- The user interacts with a responsive React SPA hosted on Firebase Hosting. All data persistence (users, carts, orders) and authentication are handled by Firebase services. Payments are routed through Stripe via a lightweight backend (Firebase Cloud Functions or a proxy).

##### High-Level File Structure Insights
- src/components: React UI organized by feature (auth, home, checkout, orders, payment).
- src/redux: Redux store and feature slices (cartSlice, userSlice).
- src/config: SDK and HTTP client configuration (firebase.js, axios.js).
- src/logic & src/data: Utility functions and static data.
- public: Static assets and index.html for the SPA.
- Root contains Firebase config files (`firebase.json`, `.firebaserc`) and package manifests.

##### Key System Components
a. Frontend Client
- Browser running the React SPA
- React Router for navigation
- Redux Store managing global state (cart, user)
- UI Components (Login, SignUp, Home, Product, Checkout, Orders, Payment)
b. Backend Services
- Firebase Authentication (user sign-up/sign-in)
- Firestore Database (collections: users, orders, cart items)
- Firebase Hosting (serving static assets)
- Firebase Cloud Functions (server-side payment endpoint)
c. External Service
- Stripe API (payment processing)

##### Component Relationships and Data Flows
1) User → Browser → React SPA: user actions trigger React events and Redux dispatches.
2) React SPA → Firebase Auth SDK: sign-in/up, retrieve user tokens.
3) React SPA → Firestore SDK: read/write user profile, cart, orders.
4) React SPA (Payment) → Axios → Cloud Function endpoint → Stripe API: process payment, return client secret.
5) Cloud Function → Firestore: records successful transactions (orders).

##### Architectural Patterns and Design Principles
- Single-Page Application: client-side routing and rendering.
- Redux for predictable state container and unidirectional data flow.
- Micro-services style for payment: isolated cloud function.
- BaaS (Backend as a Service): Firebase handles core backend functions.
- Separation of concerns: UI components, data layer (redux slices), business logic (utils), configuration (firebase, axios).

- Routing Layer (React Router)
- UI Components (auth, home, checkout, orders, payment)
- State Layer (Redux store with cartSlice, userSlice)
2) To the right of the SPA, place a “Firebase Backend” cluster containing:
- Auth (user management)
- Firestore DB (users, carts, orders)
- Hosting (static asset delivery)
- Cloud Functions (payment endpoint)
- From SPA → Auth (sign-in/up requests and tokens).
- From SPA → Firestore (CRUD operations on cart, orders, user profile).
- From SPA → Cloud Function (POST payment request) → Stripe.
- From Cloud Function → Firestore (write order record).
- Client-side vs. server-side
- Third-party services vs. in-house modules

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client
    subgraph "Frontend Client"
        direction TB
        Browser["Browser"]:::frontend
        ReactSPA["React SPA (React 18)"]:::frontend
        subgraph "Routing & State"
            direction TB
            Router["Routing Layer (React Router)"]:::frontend
            Store["Redux Store (Redux Toolkit)"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            Login["Login"]:::frontend
            SignUp["SignUp"]:::frontend
            Home["Home"]:::frontend
            Product["Product"]:::frontend
            Checkout["Checkout"]:::frontend
            CheckoutProd["CheckoutProduct"]:::frontend
            Subtotal["Subtotal"]:::frontend
            Orders["Orders"]:::frontend
            Order["Order"]:::frontend
            Payment["Payment"]:::frontend
        end
    end

    %% Configuration
    subgraph "Config Layer"
        direction TB
        FirebaseConfig["Firebase SDK Config"]:::backend
        AxiosClient["Axios HTTP Client"]:::backend
    end

    %% Backend (Firebase)
    subgraph "Backend (Firebase)"
        direction TB
        Auth["Firebase Auth"]:::backend
        Firestore["Firestore DB"]:::database
        Hosting["Firebase Hosting"]:::backend
        CloudFunc["Cloud Function: createPaymentIntent"]:::backend
    end

    %% External Service
    Stripe["Stripe API"]:::external

    %% Connections
    Browser --> ReactSPA
    ReactSPA -->|"/ (load App)"| Router
    ReactSPA -->|"dispatch actions"| Store
    ReactSPA -->|"auth.signInWithEmailAndPassword() / auth.createUserWithEmailAndPassword()"| Auth
    ReactSPA -->|"firestore.get()/firestore.set()"| Firestore
    ReactSPA -->|"axios.post('/payments/create')"| AxiosClient
    AxiosClient -->|"HTTPS POST"| CloudFunc
    CloudFunc -->|"createPaymentIntent()"| Stripe
    Stripe -->|"clientSecret response"| CloudFunc
    CloudFunc -->|"firestore.set(order)"| Firestore
    FirebaseConfig --> Auth
    FirebaseConfig --> Firestore
    FirebaseConfig --> Hosting

    %% Click Events
    click ReactSPA "https://github.com/okoyecharles/amazon-clone/blob/main/src/index.js"
    click Router "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/App.js"
    click Store "https://github.com/okoyecharles/amazon-clone/blob/main/src/redux/store.js"
    click Login "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/auth/Login.js"
    click SignUp "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/auth/SignUp.js"
    click Home "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/home/Home.js"
    click Product "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/home/Product.js"
    click Checkout "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/checkout/Checkout.js"
    click CheckoutProd "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/checkout/CheckoutProduct.js"
    click Subtotal "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/checkout/Subtotal.js"
    click Orders "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/orders/Orders.js"
    click Order "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/orders/Order.js"
    click Payment "https://github.com/okoyecharles/amazon-clone/blob/main/src/components/payment/Payment.js"
    click FirebaseConfig "https://github.com/okoyecharles/amazon-clone/blob/main/src/config/firebase.js"
    click AxiosClient "https://github.com/okoyecharles/amazon-clone/blob/main/src/config/axios.js"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1;
    classDef backend fill:#C8E6C9,stroke:#1B5E20;
    classDef database fill:#FFF59D,stroke:#F9A825,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#B71C1C,stroke-dasharray: 5 5;
```
