How okoyecharles/amazon-clone works
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