# darshankparmar/upi-payment-gateway architecture

> Architecture diagram of the GitHub repository darshankparmar/upi-payment-gateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darshankparmar/upi-payment-gateway
- Repository: https://github.com/darshankparmar/upi-payment-gateway

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) application called “UPI Payment Gateway.”
- It provides a client-side React UI for initiating UPI payments, viewing a list of transactions, and rendering receipts.
- The server-side Express app accepts payment requests, interacts with MongoDB to persist transactions, and calls an external UPI Gateway API using a merchant key.

##### File structure
- Top level:
- README.md (project overview)
- client/upi-payment-gateway (React front end)
- server (Node.js back end)
- client/upi-payment-gateway:
- public & index.html (static entrypoint)
- src/
– pages (Home.jsx, ListOfTransaction.jsx, Receipt.jsx)
– services/service.js (API calls)
– helper/ (auth headers, response handling)
– config.js (baseUrl for backend)
- vite.config.js (build config)
- server:
- index.js (Express app configuration, route definitions)
- user.model.js (Mongoose schema for users/transactions)
- .env.sample (PORT, merchant_key, frontend_url, connectionString)
- Key patterns:
- Clear separation of concerns: frontend vs backend
- REST API layer on Express
- MongoDB persistence via Mongoose
- External UPI API integration

##### README for additional insights
- It instructs on setting baseUrl in client config.js, environment variables in server/.env for MongoDB URL and merchant_key.
- Provides startup commands (npm run dev for client, npm start for server).
- Highlights that frontend_url is a redirect target after payment.

##### Main components
a. React Frontend
- Built with Vite
- Pages: Home, Transaction List, Receipt
- service.js invokes backend REST endpoints
b. Node.js/Express Backend
- Exposes REST API routes (e.g., /api/pay, /api/transactions)
- Uses Mongoose models to talk to MongoDB
- Implements UPI Gateway integration using merchant_key
c. MongoDB Database
- Stores transaction records and user information
d. External UPI Payment Gateway
- Third-party API for payment processing
e. (Optional) Browser as client environment

##### Relationships and interactions
- User → React Frontend (HTTP requests via browser)
- React Frontend → Express Backend (REST calls via fetch/axios, using auth-header.js)
- Express Backend → MongoDB (CRUD via Mongoose)
- Express Backend → External UPI Gateway API (HTTP calls using merchant_key)
- UPI Gateway → Express Backend (payment callbacks or webhook responses)
- After success, Backend → React Frontend (redirect to Receipt page via frontend_url)

##### Architectural patterns and design principles
- MVC-style on backend (Express controllers & Mongoose models)
- Component-based UI in React
- Single Page Application (SPA) delivered by Vite dev server
- Environment-driven configuration (config.js for client, .env for server)
- Separation of concerns: UI, business logic, data persistence, external integration

##### Essential architectural elements
- Don’t over-decompose; focus on core flows: “Initiate Payment,” “Persist Transaction,” “Get Transaction List,” “Render Receipt.”
- Environment configuration as a note (merchant_key, frontend_url).
- Fallback or error flows lightly (e.g., handle-response.js logic) if desired.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (React SPA)"
        direction TB
        Browser["Browser"]:::external
        ReactSPA["React SPA :5173"]:::frontend
        Browser --> ReactSPA
        subgraph "Source Files"
            direction TB
            Config["config.js"]:::frontend
            IndexHTML["index.html"]:::frontend
            ViteConfig["vite.config.js"]:::frontend
            App["App.jsx"]:::frontend
            Main["main.jsx"]:::frontend
            Home["Home.jsx"]:::frontend
            ListPage["ListOfTransaction.jsx"]:::frontend
            ReceiptPage["Receipt.jsx"]:::frontend
            Service["service.js"]:::frontend
            AuthHeader["auth-header.js"]:::frontend
            HandleResponse["handle-response.js"]:::frontend
        end
        ReactSPA --> Config
        ReactSPA --> IndexHTML
        ReactSPA --> ViteConfig
        ReactSPA --> App
        ReactSPA --> Main
        ReactSPA --> Home
        ReactSPA --> ListPage
        ReactSPA --> ReceiptPage
        ReactSPA --> Service
        ReactSPA --> AuthHeader
        ReactSPA --> HandleResponse
    end

    subgraph "Server (Express API)"
        direction TB
        ExpressAPI["Express API :10000"]:::backend
        ExpressAPI --> UserModel
        ExpressAPI --> EnvSample
        ExpressAPI --> PackageJSON
        ExpressAPI --> PackageLock
    end

    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB\nmongodb://localhost:27017/upiPaymentGateway"]:::db
    end

    subgraph "External Services"
        direction TB
        UPI["UPI Payment Gateway API"]:::external
    end

    ReactSPA -->|"REST calls(fetch/axios)"| ExpressAPI
    ExpressAPI -->|"CRUD via Mongoose"| MongoDB
    ExpressAPI -->|"Payment request(merchant_key)"| UPI
    UPI -.->|"webhook/callback"| ExpressAPI

    Readme["README.md"]:::external
    Readme -.-> ReactSPA
    Readme -.-> ExpressAPI

    click Config "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/config.js"
    click IndexHTML "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/index.html"
    click ViteConfig "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/vite.config.js"
    click App "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/App.jsx"
    click Main "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/main.jsx"
    click Home "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/pages/Home.jsx"
    click ListPage "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/pages/ListOfTransaction.jsx"
    click ReceiptPage "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/pages/Receipt.jsx"
    click Service "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/services/service.js"
    click AuthHeader "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/helper/auth-header.js"
    click HandleResponse "https://github.com/darshankparmar/upi-payment-gateway/blob/main/client/upi-payment-gateway/src/helper/handle-response.js"
    click ExpressAPI "https://github.com/darshankparmar/upi-payment-gateway/blob/main/server/index.js"
    click EnvSample "https://github.com/darshankparmar/upi-payment-gateway/blob/main/server/.env.sample"
    click PackageJSON "https://github.com/darshankparmar/upi-payment-gateway/blob/main/server/package.json"
    click PackageLock "https://github.com/darshankparmar/upi-payment-gateway/blob/main/server/package-lock.json"
    click UserModel "https://github.com/darshankparmar/upi-payment-gateway/blob/main/server/user.model.js"
    click Readme "https://github.com/darshankparmar/upi-payment-gateway/blob/main/README.md"

    classDef frontend fill:#b2f5ea,stroke:#02735e,color:#025047
    classDef backend fill:#bee3f8,stroke:#2b6cb0,color:#2c5282
    classDef db fill:#fed7d7,stroke:#e53e3e,color:#9b2c2c
    classDef external fill:#faf089,stroke:#d69e2e,color:#975a16
```
