# iamamanrajput/neomart architecture

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

- Interactive diagram: https://gitdiagram.com/iamamanrajput/neomart
- Repository: https://github.com/iamamanrajput/neomart

## Overview

##### Main Components
- Frontend Application
- Built with React, Vite, and Tailwind CSS.
- Consists of pages (e.g., Home, Login, Signup, Product, Checkout), components (UI, custom components), state management via Redux, and routing (React Router).
- Includes admin-specific layouts and dashboards.
- Backend Application
- Built using Node.js and Express.js.
- Organized into a structured MVC-like pattern:
◦ Config: Configuration files for database and Cloudinary.
◦ Controllers: Business logic for authentication, orders, payments, reviews, products, pincode checking, etc.
◦ Models: Schemas for MongoDB (user, product, order, etc.).
◦ Routes: API endpoints that connect to controllers.
◦ Middlewares: JWT verification for secured routes.
◦ Utils: Helper functions (e.g., constants, image uploading).
- Database
- MongoDB is used as the primary data store for persisting users, products, orders, reviews, etc.
- External Services
- Cloudinary for managing images.
- Payment gateway integration (as indicated in the payment controller and routes).
- Environment Configuration
- Environment variables for both frontend and backend guide the configuration (e.g., API URLs, JWT secrets, Cloudinary credentials).

##### Relationships & Data Flow
- The frontend communicates with the backend via RESTful API calls (using endpoints defined in the routes).
- The backend, acting as the API server, processes requests through middlewares (for token verification) and controllers, then interacts with the MongoDB database.
- Certain operations (like image uploads) rely on external services (Cloudinary) or payment gateways.
- For administration tasks, separate panels (admin-specific pages in the frontend) call different backend APIs.

##### Architectural Patterns and Design Principles
- The backend uses a modular structure (controllers, routes, models, middlewares) that aligns with an MVC (Model-View-Controller)-inspired pattern.
- In the frontend, a component-based architecture is evident along with state management using Redux and Context for theming.
- Separation of concerns is maintained: the backend focuses on data processing and API logic while the frontend focuses on UI and user interactions.
- Security is incorporated via JWT authentication.

- Frontend:
- Pages/routes and where admin vs. customer views are handled.
- Backend:
- Subdivide into:
▪ “Config” (database and cloud configurations)
▪ “Controllers” (for auth, product, order, payment, review, pincode, settings)
▪ “Models” (MongoDB schemas for users, orders, products, reviews, etc.)
▪ “Routes” (mapping API endpoints to controllers)
▪ “Middlewares” (JWT verification)
▪ “Utils” (constants, image uploader helper)
- Database:
- MongoDB as a central datastore.
- External Services:
- Cloudinary for image management.
- Payment Gateways if applicable.
- Environment Variables:
- You may include a small section for configuration dependencies that illustrate how the system gets its configuration at runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Subgraph
    subgraph "Frontend"
        FE_Frontend("React Frontend (Vite, Tailwind, React Router, Redux)"):::frontend
        FE_Pages("Pages (Home,Login,Signup,Product,Checkout)"):::frontend
        FE_Components("Custom & UI Components"):::frontend
        FE_State("Redux State Management"):::frontend
        FE_Routing("Layouts & Routing"):::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        BE_Backend("Node.js/Express Backend"):::backend
        BE_Config("Config (database,cloudinary)"):::backend
        BE_Controllers("Controllers (auth,order,payment,pincode,product,review,setting,user)"):::backend
        BE_Models("Models (user,product,order,review,pincode,admin)"):::backend
        BE_Routes("Routes (admin,auth,order,payment,pincode,product,profile,review,setting)"):::backend
        BE_Middlewares("Middlewares (JWT verification)"):::backend
        BE_Utils("Utils (constants,imageUploader)"):::backend
    end

    %% External Services Subgraph
    subgraph "External Services"
        ES_Cloudinary("Cloudinary Service"):::external
        ES_Payment("Payment Gateway"):::external
    end

    %% Database Node
    DB("MongoDB Database"):::database

    %% Environment Configuration Node
    ENV("Environment Config Variables"):::config

    %% Relationships
    FE_Frontend -->|"APICall"| BE_Routes
    FE_Pages --> FE_Frontend
    FE_Components --> FE_Frontend
    FE_State --> FE_Frontend
    FE_Routing --> FE_Frontend

    BE_Routes -->|"routes_to"| BE_Controllers
    BE_Controllers -->|"processes"| BE_Models
    BE_Controllers -->|"uses"| BE_Middlewares
    BE_Config --> BE_Controllers
    BE_Utils --> BE_Controllers
    BE_Controllers -->|"payment"| ES_Payment
    BE_Controllers -->|"image"| ES_Cloudinary

    BE_Controllers --> DB
    DB --> BE_Models

    ENV --> FE_Frontend
    ENV --> BE_Config

    %% Click Events for Frontend
    click FE_Pages "https://github.com/iamamanrajput/neomart/tree/main/FRONTEND/src/pages"
    click FE_Components "https://github.com/iamamanrajput/neomart/tree/main/FRONTEND/src/components/custom"
    click FE_State "https://github.com/iamamanrajput/neomart/tree/main/FRONTEND/src/redux"
    click FE_Routing "https://github.com/iamamanrajput/neomart/tree/main/FRONTEND/src/layouts"

    %% Click Events for Backend
    click BE_Config "https://github.com/iamamanrajput/neomart/tree/main/BACKEND/config"
    click BE_Controllers "https://github.com/iamamanrajput/neomart/tree/main/BACKEND/controllers"
    click BE_Models "https://github.com/iamamanrajput/neomart/tree/main/BACKEND/models"
    click BE_Routes "https://github.com/iamamanrajput/neomart/tree/main/BACKEND/routes"
    click BE_Middlewares "https://github.com/iamamanrajput/neomart/tree/main/BACKEND/middlewares"
    click BE_Utils "https://github.com/iamamanrajput/neomart/tree/main/BACKEND/utils"

    %% Click Events for External Services
    click ES_Cloudinary "https://github.com/iamamanrajput/neomart/blob/main/BACKEND/config/cloudinary.js"
    click ES_Cloudinary "https://github.com/iamamanrajput/neomart/blob/main/BACKEND/utils/imageUploader.js"
    click ES_Payment "https://github.com/iamamanrajput/neomart/blob/main/BACKEND/controllers/paymentController.js"
    click ES_Payment "https://github.com/iamamanrajput/neomart/blob/main/BACKEND/routes/paymentRoutes.js"

    %% Style Definitions
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef config fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
