How raunakgurud09/payments works
This is a two-tier full-stack demo app showing Razorpay payment gateway integration:
• Frontend: React + TypeScript (Vite) UI for selecting products/amount and initiating payment.
• Backend: Node.js + TypeScript API (very likely Express) that talks to Razorpay APIs and persists Order data via a small DB layer.
• External: Razorpay Checkout + Razorpay Orders/Payments APIs.
Frontend (client/)
Key architecture signals from the tree:
• client/src/pages/Products.tsx, Success.tsx, Failure.tsx
→ page-level routing/views (even if not using react-router, these are “screens”).
• client/src/components/Card.tsx
→ reusable UI components for product display.
• client/src/api/products.json
• vite.config.ts, tailwind.config.js, postcss.config.js
• Collect amount / choose product
• Call backend to create payment/order
• Invoke Razorpay Checkout (client-side integration)
• Handle redirect to Success/Failure
Backend (server/)
Key architecture signals:
• server/src/index.ts + server/src/app.ts
→ entrypoint and app composition (Express-style bootstrapping, middleware, routes).
• server/src/routes/*
• payment.routes.ts
• healthcheck.routes.ts
→ HTTP route modules; represent as API surface.
• server/src/controllers/payment/* and controllers/healthcheck.controllers.ts
→ request handling / orchestration logic.
• server/src/model/order.ts
• server/src/db/index.ts
• .env.sample includes RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET
→ critical security boundary: secrets live only on server.
Backend responsibilities to represent:
• Create Razorpay Order (server-to-Razorpay)
• Verify payment (signature verification typically server-side)
• Persist order/payment state
• Provide healthcheck endpoint
External system
• Razorpay APIs (Orders/Payments)
• Razorpay Checkout (hosted/payment UI invoked from browser)
Shows: Browser (React app), Node API server, DB, Razorpay.
Shows: User → React → Backend → Razorpay → React → Backend → DB.
Shows internal server structure: Routes → Controllers → Services (if present) → Razorpay client + DB adapter → Order model.
Node API → React: returns data needed to open Checkout
• e.g., order_id, key_id, amount, etc.
React → Razorpay Checkout (JS): opens checkout widget (external UI)
7. Razorpay Checkout → React: returns payment_id, order_id, signature (or error/cancel)
Supporting flow
• React / Monitor → Node API: GET /healthcheck (from healthcheck.routes.ts)
If your backend uses webhooks (not visible in the tree), add:
• Razorpay → Node API: webhook events (payment.captured, payment.failed)
Important architectural patterns to highlight (specific to this repo)
• Separation of concerns in backend: routes/ → controllers/ → db/ + model/
• Frontend UI composition: pages vs components, with local static products.json
• Security pattern: Razorpay secret never leaves server; verification happens server-side
• State model: “Order” is the core domain entity persisted via db/index.ts
“Don’t overthink it” checklist (separate into as many components as possible)
To maximize detail without inventing things:
• In frontend: separate Pages, Components, Static Catalog, Razorpay Checkout JS
• In backend: separate Routes, Controllers, Order Model, DB Adapter, Razorpay API Client, Config/Constants
• External: split Razorpay into Checkout UI and REST APIs