# sivaprasathm93/amazon-clone architecture

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

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

## Overview

##### Main Components
- Frontend:
- Built primarily with React and TypeScript.
- Contains pages (Home, ProductDetail, Cart, Login) and shared components (Navbar, Footer, ProductSlider, TrendingProducts, UpcomingProducts).
- Uses state management (with Context or Redux as indicated in the README) for managing the shopping cart.
- Employs routing (React Router) and integrates styling with Tailwind CSS and SCSS.
- Backend:
- A Node.js + Express server (located in the “server” directory with TypeScript in server/src/server.ts).
- Uses middleware and routing to handle API endpoints for authentication and data retrieval.
- Leverages libraries such as Mongoose for MongoDB operations, JSON Web Tokens (JWT) for authentication, bcryptjs for password hashing, and dotenv for configuration.
- Manages environment-specific details via a .env file.
- Database & External Services:
- MongoDB (the project uses MongoDB via Mongoose for storing user data).
- External integrations like Stripe.js are used in the checkout process.
- Firebase is also mentioned in the README as a backend service for authentication and database, so if that is active, it should be highlighted as an alternative integration or supplemental service.
- Additional Elements:
- Product data is partly fed by local JSON files.
- The checkout process integration with Stripe.

##### Relationships and Interactions
- Frontend to Backend:
- Use API calls (via Axios) from the React frontend to the Express server.
- Use JWT tokens to secure routes; the client stores these tokens (through cookies or local storage) and sends them with HTTP requests.
- Backend to Database:
- The Express server communicates with MongoDB through Mongoose.
- CRUD operations for user data, order management, and other backend services take place here.
- External Services:
- During the checkout process, the backend connects with Stripe.
- Firebase (if enabled) may be used as an additional authentication or database service.

##### Architectural Patterns and Principles
- Separation of Concerns:
- Distinct separation between frontend and backend responsibilities.
- Modular Design:
- Frontend: Organized into components, pages, contexts, and assets.
- Backend: Organized into TypeScript files and configurations that support scalability.
- Dependency Management & Security:
- Use of JWT for authentication.
- Usage of environment variables to secure sensitive credentials (via dotenv).
- API Layer:
- Clearly defined endpoints which communicate between the client and server.

##### Relevant Technologies and Frameworks
- Frontend: React, TypeScript, Tailwind CSS, SCSS, React Router, Redux (or Context as applicable), Axios.
- Backend: Node.js, Express, Mongoose (MongoDB), JWT, bcryptjs, dotenv, cors.
- Other: Possibly Firebase (as indicated) for some backend services, and external payment integration via Stripe.js.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend"
        A1("Home Page"):::frontend
        A2("Product Detail Page"):::frontend
        A3("Cart Page"):::frontend
        A4("Login Page"):::frontend
        B1("Navbar"):::frontend
        B2("Footer"):::frontend
        B3("ProductSlider"):::frontend
        B4("TrendingProducts"):::frontend
        B5("UpcomingProducts"):::frontend
        C1("Login Component"):::frontend
        D1("Shopping Cart Context"):::frontend
        D2("Product Data (Local JSON)"):::frontend
        E1("App Initialization"):::frontend
    end

    %% Backend Section
    subgraph "Backend"
        F1("Express Server"):::backend
        F2("Environment Config (.env)"):::backend
        F3("Server Package Config"):::backend
        F4("Server TSConfig"):::backend
    end

    %% Database and External Services Section
    subgraph "Database & External"
        G1("MongoDB Database"):::database
        subgraph "External Services"
            H1("Stripe Checkout"):::external
            H2("Firebase Service"):::external
        end
    end

    %% Build & Config Files Section
    subgraph "Build & Config Files"
        I1("package.json")
        I2("tsconfig.json")
        I3("tsconfig.app.json")
        I4("tsconfig.node.json")
        I5("vite.config.ts")
        I6("postcss.config.js")
        I7("tailwind.config.js")
        I8("eslint.config.js")
    end

    %% Connections from Frontend to Backend
    A1 -->|"AxiosHTTPCalls"| F1
    A2 -->|"AxiosHTTPCalls"| F1
    A3 -->|"AxiosHTTPCalls"| F1
    A4 -->|"JWTAuth"| F1
    C1 -->|"TriggersLogin"| A4
    D1 -->|"ManagesCart"| A3
    E1 -->|"APIInitialization"| F1

    %% Connection from Product Data to UI Components
    D2 -->|"ProvidesData"| B3
    D2 -->|"ProvidesData"| A2

    %% Backend connections to Database and External Services
    F1 -->|"MongooseODM"| G1
    F1 -->|"StripePayment"| H1
    F1 -->|"FirebaseIntegration"| H2

    %% Class Definitions for Colors
    classDef frontend fill:#B3E5FC,stroke:#039BE5,stroke-width:2px;
    classDef backend fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef database fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef external fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;

    %% Click Events for Frontend Components
    click A1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/pages/Home.tsx"
    click A2 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/pages/ProductDetail.tsx"
    click A3 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/pages/Cart.tsx"
    click A4 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/pages/Login.tsx"
    click B1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/components/Navbar.tsx"
    click B2 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/components/Footer.tsx"
    click B3 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/components/ProductSlider.tsx"
    click B4 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/components/TrendingProducts.tsx"
    click B5 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/components/UpcomingProducts.tsx"
    click C1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/components/Login/Login.tsx"
    click D1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/context/CartContext.tsx"
    click D2 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/data/products.ts"
    click E1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/src/App.tsx"

    %% Click Events for Backend Components
    click F1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/server/src/server.ts"
    click F2 "https://github.com/sivaprasathm93/amazon-clone/blob/main/server/.env"
    click F3 "https://github.com/sivaprasathm93/amazon-clone/blob/main/server/package.json"
    click F4 "https://github.com/sivaprasathm93/amazon-clone/blob/main/server/tsconfig.json"

    %% Click Events for Build & Config Files
    click I1 "https://github.com/sivaprasathm93/amazon-clone/blob/main/package.json"
    click I2 "https://github.com/sivaprasathm93/amazon-clone/blob/main/tsconfig.json"
    click I3 "https://github.com/sivaprasathm93/amazon-clone/blob/main/tsconfig.app.json"
    click I4 "https://github.com/sivaprasathm93/amazon-clone/blob/main/tsconfig.node.json"
    click I5 "https://github.com/sivaprasathm93/amazon-clone/blob/main/vite.config.ts"
    click I6 "https://github.com/sivaprasathm93/amazon-clone/blob/main/postcss.config.js"
    click I7 "https://github.com/sivaprasathm93/amazon-clone/blob/main/tailwind.config.js"
    click I8 "https://github.com/sivaprasathm93/amazon-clone/blob/main/eslint.config.js"
```
