# darshan98solanki/paytm architecture

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

- Interactive diagram: https://gitdiagram.com/darshan98solanki/paytm
- Repository: https://github.com/darshan98solanki/paytm

## Overview

##### Project type and purpose
- This is a full-stack, single-page web application (“PayTM Clone”) that lets registered users sign up, receive demo money, search for other users, and transfer funds.
- Frontend: React.js (Vite + Tailwind).
- Backend: Node.js + Express.js, using JWT for auth and bcrypt for password hashing.
- Database: MongoDB.
- Hosted/deployed via Vercel (serverless).

a. Client / Browser (React SPA)
b. CDN / Edge (for serving static assets) – Vercel
c. API Layer – Express.js serverless functions (routes: /user, /account, /transaction)
d. Authentication Service – JWT issue/validation, bcrypt hashing
e. Database – MongoDB collections: Users, Transactions
f. External Payment Gateway (PayTM) – merchant API calls using merchant key & ID
g. DevOps / Deployment – Dockerfile (optional container), Vercel configuration

##### Relationships & data flow
- User opens the app in browser → requests index.html + JS/CSS from CDN/Edge.
- SPA boots and calls “/api/auth/signup” or “/api/auth/login” on the Express API → backend verifies credentials, uses bcrypt → issues JWT.
- Browser stores JWT (localStorage) → all subsequent API calls include JWT in Authorization header.
- For “Send Money”, SPA calls “/api/account/transfer” → backend middleware verifies JWT → backend writes Transaction record & updates User balances in MongoDB.
- Optionally backend calls external PayTM merchant API to simulate/validate payment.
- Responses flow back to SPA, which updates UI (Dashboard, Transactions, User Profile).

##### Architectural patterns & principles
- Separation of concerns:
- Frontend (UI layer) vs. Backend (API layer) vs. Database
- Backend uses MVC-style (routes/controllers, services, models in db.js/types.js)
- Stateless serverless functions on Vercel
- Secure by design: bcrypt for hashing, JWT for session, HTTPS assumed
- Modular code: routes under backend/routes, components under frontend/src/components

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        CDN["Vercel Edge/CDN"]:::gray
        StaticAssets["Static Assets\n(index.html, CSS)"]:::blue
        ReactSPA["React SPA"]:::blue
    end

    CDN -->|"serves\nindex.html, JS, CSS"| StaticAssets
    StaticAssets -->|"boots SPA"| ReactSPA

    %% Serverless API Layer
    subgraph "Serverless API (Vercel Serverless)" 
        direction TB
        ExpressAPI["Express API Server"]:::green
        subgraph "API Routes & Middleware"
            direction TB
            AuthMiddleware["JWT Auth & Bcrypt\nMiddleware"]:::green
            Config["Environment Config\n(JWT_SECRET, PAYTM keys)"]:::green
            subgraph "Routes"
                direction TB
                RootRoute["/ (Health)"]:::green
                UserRoute["/api/user"]:::green
                AccountRoute["/api/account"]:::green
            end
        end
    end

    ReactSPA -->|"POST /api/auth/signup\nPOST /api/auth/login"| ExpressAPI
    ExpressAPI --> AuthMiddleware
    AuthMiddleware --> Config
    AuthMiddleware --> Routes
    ExpressAPI -->|"GET / (Health)"| RootRoute
    ExpressAPI -->|"GET/POST /api/user"| UserRoute
    ExpressAPI -->|"GET/POST /api/account"| AccountRoute

    %% Database & External
    subgraph "Data & External Services"
        direction TB
        MongoDB["MongoDB\n(Users, Transactions)"]:::orange
        PayTM["PayTM Merchant API"]:::gray
    end

    AccountRoute -->|"read/write\nTransactions, Users"| MongoDB
    UserRoute -->|"read/write\nUsers"| MongoDB
    AccountRoute -->|"POST merchant API"| PayTM

    %% DevOps & Deployment
    subgraph "Deployment & DevOps"
        direction TB
        Docker["Dockerfile"]:::gray
        FrontendVercel["frontend/vercel.json"]:::gray
        BackendVercel["backend/vercel.json"]:::gray
    end

    Docker & FrontendVercel & BackendVercel --> ExpressAPI

    %% Click Events
    click ReactSPA "https://github.com/darshan98solanki/paytm/tree/main/frontend/"
    click StaticAssets "https://github.com/darshan98solanki/paytm/blob/main/frontend/index.html"
    click FrontendVercel "https://github.com/darshan98solanki/paytm/blob/main/frontend/vercel.json"
    click ExpressAPI "https://github.com/darshan98solanki/paytm/blob/main/backend/index.js"
    click RootRoute "https://github.com/darshan98solanki/paytm/blob/main/backend/routes/index.js"
    click UserRoute "https://github.com/darshan98solanki/paytm/blob/main/backend/routes/user.js"
    click AccountRoute "https://github.com/darshan98solanki/paytm/blob/main/backend/routes/account.js"
    click AuthMiddleware "https://github.com/darshan98solanki/paytm/blob/main/backend/middlewear.js"
    click Config "https://github.com/darshan98solanki/paytm/blob/main/backend/config.js"
    click MongoDB "https://github.com/darshan98solanki/paytm/blob/main/backend/db.js"
    click MongoDB "https://github.com/darshan98solanki/paytm/blob/main/backend/types.js"
    click BackendVercel "https://github.com/darshan98solanki/paytm/blob/main/backend/vercel.json"
    click Docker "https://github.com/darshan98solanki/paytm/tree/main/Dockerfile"

    %% Styles
    classDef blue fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef green fill:#DFFFE0,stroke:#28A745,color:#28A745
    classDef orange fill:#FFE8D0,stroke:#D97706,color:#D97706
    classDef gray fill:#F0F0F0,stroke:#6C757D,color:#6C757D
```
