# naitikmangal/ecommerce architecture

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

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

## Overview

##### Main Components
- Frontend (Customer-Facing): This is located in the "frontend" directory and contains all the React components, pages (e.g., Home, Product, Cart, Checkout), assets, context for state management (ShopContext), and styling using Tailwind CSS.
- Admin Panel: Found in the "admin" directory, it includes its own set of React components and pages (e.g., Login, List, Add, Order, PaymentTracking) designed for shop administration tasks like adding products, managing orders, and handling users.
- Backend API: Located in the "backend" directory. It’s a Node.js/Express server that handles RESTful API endpoints for products, users, orders, and carts. This module also contains configuration for MongoDB, middleware for authentication and file uploads, and controllers for business logic.
- Database: Integrated via MongoDB, as suggested by the configuration file “mongodb.js” under backend/config.
- External Services: While not extensive, the project integrates with Cloudinary for image storage (see cloudinary.js) and payment integration as mentioned in the README.

##### Relationships and Interactions
- The Frontend and Admin Panel are separate React applications communicating with the Backend.
- The Backend exposes RESTful endpoints for CRUD operations on products, users, orders, and carts.
- Both frontend applications will interact with the backend using API calls, with authentication relying on JWT tokens.
- The Backend communicates with MongoDB for database operations.
- Optionally, the backend may also interact with external services like Cloudinary for asset management.

##### Architectural Patterns and Technologies
- The project leverages the MERN stack (MongoDB, Express, React, Node.js) with Tailwind CSS for styling.
- The backend follows RESTful conventions and uses middleware for authentication and file handling.
- The frontend applications are structured around reusable React components and utilize context (e.g., ShopContext) for state management.
- The clear separation between admin and customer-facing modules is an important design decision ensuring distinct user experiences and responsibilities.

##### Additional Details
- Labels and descriptions for tools and libraries such as React, Express, Tailwind CSS, and JWT.
- Configuration or build scripts like Vite configurations, Tailwind configs, and ESLint settings that are relevant for the context but keep the overall focus on runtime components.
- To capture the fact that the system is split into two distinct frontends (for customers and admins) that communicate with a shared backend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Customer Frontend Subgraph
    subgraph "Customer Frontend"
        FE1["React Components"]:::frontend
        FE2["Pages"]:::frontend
        FE3["ShopContext (State Mgmt)"]:::frontend
        FE4["Tailwind Config"]:::frontend
        FE5["CSS Files"]:::frontend
        FE1 --> FE2
        FE2 --> FE3
        FE3 --> FE4
        FE4 --> FE5
    end

    %% Admin Panel Subgraph
    subgraph "Admin Panel"
        AD1["React Components"]:::admin
        AD2["Pages"]:::admin
        AD3["Tailwind Config"]:::admin
        AD4["HTML Shell"]:::admin
        AD5["CSS Files"]:::admin
        AD1 --> AD2
        AD2 --> AD3
        AD3 --> AD4
        AD4 --> AD5
    end

    %% Backend API Subgraph
    subgraph "Backend API"
        BE1["Server Setup (Express)"]:::backend
        BE2["Routes (RESTful)"]:::backend
        BE3["Controllers"]:::backend
        BE4["Middleware (Auth & File Upload)"]:::backend
        BE1 --> BE2
        BE2 --> BE3
        BE3 --> BE4
    end

    %% External Components
    DB["MongoDB Config"]:::database
    EXT["Cloudinary Config"]:::external

    %% Interactions
    FE5 -->|"API_call"| BE1
    AD5 -->|"Admin_API_call"| BE1
    BE1 -->|"DB_Ops"| DB
    BE1 -->|"Asset_Storage"| EXT

    %% Click Events - Frontend
    click FE1 "https://github.com/naitikmangal/ecommerce/tree/main/frontend/src/components"
    click FE2 "https://github.com/naitikmangal/ecommerce/tree/main/frontend/src/pages"
    click FE3 "https://github.com/naitikmangal/ecommerce/blob/main/frontend/src/context/ShopContext.jsx"
    click FE4 "https://github.com/naitikmangal/ecommerce/blob/main/frontend/tailwind.config.js"
    click FE5 "https://github.com/naitikmangal/ecommerce/blob/main/frontend/src/App.css"

    %% Click Events - Admin Panel
    click AD1 "https://github.com/naitikmangal/ecommerce/tree/main/admin/src/components"
    click AD2 "https://github.com/naitikmangal/ecommerce/tree/main/admin/src/pages"
    click AD3 "https://github.com/naitikmangal/ecommerce/blob/main/admin/tailwind.config.js"
    click AD4 "https://github.com/naitikmangal/ecommerce/blob/main/admin/index.html"
    click AD5 "https://github.com/naitikmangal/ecommerce/blob/main/admin/src/App.css"

    %% Click Events - Backend API
    click BE1 "https://github.com/naitikmangal/ecommerce/blob/main/backend/server.js"
    click BE2 "https://github.com/naitikmangal/ecommerce/tree/main/backend/routes"
    click BE3 "https://github.com/naitikmangal/ecommerce/tree/main/backend/controllers"
    click BE4 "https://github.com/naitikmangal/ecommerce/tree/main/backend/middleware"

    %% Click Events - Database & External Services
    click DB "https://github.com/naitikmangal/ecommerce/blob/main/backend/config/mongodb.js"
    click EXT "https://github.com/naitikmangal/ecommerce/blob/main/backend/config/cloudinary.js"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef admin fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
