How darshankparmar/upi-payment-gateway works
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.