# eshang2006/p2p-lending-platform architecture

> Architecture diagram of the GitHub repository eshang2006/p2p-lending-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eshang2006/p2p-lending-platform
- Repository: https://github.com/eshang2006/p2p-lending-platform

## Overview

CredFlow is a P2P micro-lending platform. Borrowers register and create scored loan campaigns; investors browse campaigns and fund them through Razorpay; borrowers release fully funded escrow into repayment, then track repayments. The React client calls an Express API, which applies JWT and role checks and persists lending records in MongoDB. The README also documents email and real-time updates. Some repayment and frontend integrations are only documented or indexed, so their links are cited to the README or left out where wiring is not shown.

Main entry points: [`frontend/src/App.jsx`](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/App.jsx) (Route shell), [`backend/controllers/investmentController.js`](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/investmentController.js) (Investment and escrow), [`frontend/src/utils/api.js`](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/utils/api.js) (API client), [`backend/server.js`](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/server.js) (Express and sockets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["Route shell<br/>[App.jsx]"]
  node_authui["Auth state<br/>[AuthContext.jsx]"]
  node_authpages["Login and register<br/>[Login.jsx]"]
  node_home["Home page<br/>[Home.jsx]"]
  node_borrowerdash["Borrower dashboard"]
  node_createcampaign["Create campaign<br/>[CreateLoan.jsx]"]
  node_campaignlist["Campaign listing<br/>[CampaignList.jsx]"]
  node_campaigndetail["Campaign detail<br/>[CampaignDetail.jsx]"]
  node_investordash["Investor dashboard"]
  node_api["API client<br/>[api.js]"]
end

subgraph group_identity["Identity and access"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_authcontroller["Auth service<br/>[authController.js]"]
  node_authmiddleware["JWT and role checks<br/>[authMiddleware.js]"]
  node_user[("User records<br/>[User.js]")]
end

subgraph group_lending["Campaign and credit"]
  node_loanroutes["Loan routes<br/>[loanRoutes.js]"]
  node_loancontroller["Campaign service<br/>[loanController.js]"]
  node_credit["Credit scoring<br/>[creditScore.js]"]
  node_loan[("Loan records<br/>[Loan.js]")]
end

subgraph group_funding["Funding and repayment"]
  node_investmentroutes["Investment routes"]
  node_investmentcontroller["Investment and escrow"]
  node_investment[("Investment records<br/>[Investment.js]")]
  node_transaction[("Transaction records<br/>[Transaction.js]")]
  node_repaymentroutes["Repayment routes<br/>[repaymentRoutes.js]"]
  node_repayment[("Repayment records<br/>[Repayment.js]")]
end

subgraph group_platform["API and persistence"]
  node_server["Express and sockets<br/>[server.js]"]
  node_database[("MongoDB<br/>[db.js]")]
end

node_borrower(("Borrower"))
node_investor(("Investor"))
node_razorpay["Razorpay"]
node_email["Email service"]
node_socket(("Socket.io clients"))

node_borrower -->|"uses"| node_app
node_investor -->|"uses"| node_app
node_app -->|"provides auth"| node_authui
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_authpages
node_app -->|"routes to"| node_borrowerdash
node_app -->|"routes to"| node_createcampaign
node_app -->|"routes to"| node_campaignlist
node_app -->|"routes to"| node_campaigndetail
node_app -->|"routes to"| node_investordash
node_authpages -->|"updates"| node_authui
node_authpages -->|"calls"| node_api
node_borrowerdash -->|"calls"| node_api
node_createcampaign -->|"calls"| node_api
node_campaignlist -->|"calls"| node_api
node_campaigndetail -->|"calls"| node_api
node_investordash -->|"calls"| node_api
node_api -->|"HTTP requests"| node_server
node_server -->|"connects"| node_database
node_server -->|"mounts"| node_authroutes
node_server -->|"mounts"| node_loanroutes
node_server -->|"mounts"| node_investmentroutes
node_server -->|"mounts"| node_repaymentroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authroutes -->|"protects"| node_authmiddleware
node_authcontroller -->|"reads and writes"| node_user
node_authmiddleware -->|"loads user"| node_user
node_loanroutes -->|"dispatches"| node_loancontroller
node_loanroutes -->|"protects"| node_authmiddleware
node_loancontroller -->|"calculates score"| node_credit
node_loancontroller -->|"reads and writes"| node_loan
node_credit -->|"reads history"| node_loan
node_investmentroutes -->|"dispatches"| node_investmentcontroller
node_investmentroutes -->|"checks roles"| node_authmiddleware
node_investmentcontroller -->|"creates orders"| node_razorpay
node_investmentcontroller -->|"reads and updates"| node_loan
node_investmentcontroller -->|"creates and reads"| node_investment
node_investmentcontroller -->|"records payment"| node_transaction
node_investmentcontroller -->|"loads parties"| node_user
node_investmentcontroller -->|"creates schedule"| node_repayment
node_investmentcontroller -->|"sends notice"| node_email
node_investmentcontroller -->|"emits update"| node_socket
node_repaymentroutes -->|"protects"| node_authmiddleware
node_repaymentroutes -->|"reads and updates"| node_repayment
node_repaymentroutes -->|"completes loan"| node_loan
node_loancontroller -->|"emits campaign"| node_socket

click node_app "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/context/AuthContext.jsx"
click node_authpages "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/Login.jsx"
click node_home "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/Home.jsx"
click node_borrowerdash "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/BorrowerDashboard.jsx"
click node_createcampaign "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/CreateLoan.jsx"
click node_campaignlist "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/CampaignList.jsx"
click node_campaigndetail "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/CampaignDetail.jsx"
click node_investordash "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/InvestorDashboard.jsx"
click node_api "https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/utils/api.js"
click node_authroutes "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/authRoutes.js"
click node_authcontroller "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/authController.js"
click node_authmiddleware "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/middleware/authMiddleware.js"
click node_user "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/User.js"
click node_loanroutes "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/loanRoutes.js"
click node_loancontroller "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/loanController.js"
click node_credit "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/utils/creditScore.js"
click node_loan "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Loan.js"
click node_investmentroutes "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/investmentRoutes.js"
click node_investmentcontroller "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/investmentController.js"
click node_investment "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Investment.js"
click node_transaction "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Transaction.js"
click node_repaymentroutes "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/repaymentRoutes.js"
click node_repayment "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Repayment.js"
click node_server "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/server.js"
click node_database "https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/config/db.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_authui,node_authpages,node_home,node_borrowerdash,node_createcampaign,node_campaignlist,node_campaigndetail,node_investordash,node_api,node_socket toneBlue
class node_authroutes,node_authcontroller,node_authmiddleware,node_user toneAmber
class node_loanroutes,node_loancontroller,node_credit,node_loan toneMint
class node_investmentroutes,node_investmentcontroller,node_investment,node_transaction,node_repaymentroutes,node_repayment toneRose
class node_server,node_database,node_borrower,node_investor,node_razorpay,node_email toneIndigo
```

## Components

### Web client

- [Route shell](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Auth state](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Login and register](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Home page](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Borrower dashboard](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/BorrowerDashboard.jsx): `frontend/src/pages/BorrowerDashboard.jsx`
- [Create campaign](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/CreateLoan.jsx): `frontend/src/pages/CreateLoan.jsx`
- [Campaign listing](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/CampaignList.jsx): `frontend/src/pages/CampaignList.jsx`
- [Campaign detail](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/CampaignDetail.jsx): `frontend/src/pages/CampaignDetail.jsx`
- [Investor dashboard](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/pages/InvestorDashboard.jsx): `frontend/src/pages/InvestorDashboard.jsx`
- [API client](https://github.com/eshang2006/p2p-lending-platform/blob/main/frontend/src/utils/api.js): `frontend/src/utils/api.js`

### Identity and access

- [Auth routes](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Auth service](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [JWT and role checks](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [User records](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/User.js): `backend/models/User.js`

### Campaign and credit

- [Loan routes](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/loanRoutes.js): `backend/routes/loanRoutes.js`
- [Campaign service](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/loanController.js): `backend/controllers/loanController.js`
- [Credit scoring](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/utils/creditScore.js): `backend/utils/creditScore.js`
- [Loan records](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Loan.js): `backend/models/Loan.js`

### Funding and repayment

- [Investment routes](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/investmentRoutes.js): `backend/routes/investmentRoutes.js`
- [Investment and escrow](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/controllers/investmentController.js): `backend/controllers/investmentController.js`
- [Investment records](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Investment.js): `backend/models/Investment.js`
- [Transaction records](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Transaction.js): `backend/models/Transaction.js`
- [Repayment routes](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/routes/repaymentRoutes.js): `backend/routes/repaymentRoutes.js`
- [Repayment records](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/models/Repayment.js): `backend/models/Repayment.js`

### API and persistence

- [Express and sockets](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/server.js): `backend/server.js`
- [MongoDB](https://github.com/eshang2006/p2p-lending-platform/blob/main/backend/config/db.js): `backend/config/db.js`

### Other components

- **Borrower**
- **Investor**
- **Razorpay**
- **Email service**
- **Socket.io clients**

## Connections

- Borrower → Route shell: uses (evidence: `README.md`)
- Investor → Route shell: uses (evidence: `README.md`)
- Route shell → Auth state: provides auth (evidence: `frontend/src/App.jsx`)
- Route shell → Home page: routes to (evidence: `frontend/src/App.jsx`)
- Route shell → Login and register: routes to (evidence: `frontend/src/App.jsx`)
- Route shell → Borrower dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Route shell → Create campaign: routes to (evidence: `frontend/src/App.jsx`)
- Route shell → Campaign listing: routes to (evidence: `frontend/src/App.jsx`)
- Route shell → Campaign detail: routes to (evidence: `frontend/src/App.jsx`)
- Route shell → Investor dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Login and register → Auth state: updates (evidence: `frontend/src/pages/Login.jsx`)
- Login and register → API client: calls (evidence: `frontend/src/pages/Login.jsx`)
- Borrower dashboard → API client: calls (evidence: `frontend/src/pages/BorrowerDashboard.jsx`)
- Create campaign → API client: calls (evidence: `frontend/src/pages/CreateLoan.jsx`)
- Campaign listing → API client: calls (evidence: `frontend/src/pages/CampaignList.jsx`)
- Campaign detail → API client: calls (evidence: `frontend/src/pages/CampaignDetail.jsx`)
- Investor dashboard → API client: calls (evidence: `frontend/src/pages/InvestorDashboard.jsx`)
- API client → Express and sockets: HTTP requests (evidence: `README.md`)
- Express and sockets → MongoDB: connects (evidence: `backend/server.js`)
- Express and sockets → Auth routes: mounts (evidence: `backend/server.js`)
- Express and sockets → Loan routes: mounts (evidence: `backend/server.js`)
- Express and sockets → Investment routes: mounts (evidence: `backend/server.js`)
- Express and sockets → Repayment routes: mounts (evidence: `backend/server.js`)
- Auth routes → Auth service: dispatches (evidence: `backend/routes/authRoutes.js`)
- Auth routes → JWT and role checks: protects (evidence: `backend/routes/authRoutes.js`)
- Auth service → User records: reads and writes (evidence: `backend/controllers/authController.js`)
- JWT and role checks → User records: loads user (evidence: `backend/middleware/authMiddleware.js`)
- Loan routes → Campaign service: dispatches (evidence: `backend/routes/loanRoutes.js`)
- Loan routes → JWT and role checks: protects (evidence: `backend/routes/loanRoutes.js`)
- Campaign service → Credit scoring: calculates score (evidence: `backend/controllers/loanController.js`)
- Campaign service → Loan records: reads and writes (evidence: `backend/controllers/loanController.js`)
- Credit scoring → Loan records: reads history (evidence: `backend/utils/creditScore.js`)
- Investment routes → Investment and escrow: dispatches (evidence: `backend/routes/investmentRoutes.js`)
- Investment routes → JWT and role checks: checks roles (evidence: `backend/routes/investmentRoutes.js`)
- Investment and escrow → Razorpay: creates orders (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → Loan records: reads and updates (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → Investment records: creates and reads (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → Transaction records: records payment (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → User records: loads parties (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → Repayment records: creates schedule (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → Email service: sends notice (evidence: `backend/controllers/investmentController.js`)
- Investment and escrow → Socket.io clients: emits update (evidence: `backend/controllers/investmentController.js`)
- Repayment routes → JWT and role checks: protects (evidence: `backend/routes/repaymentRoutes.js`)
- Repayment routes → Repayment records: reads and updates (evidence: `backend/routes/repaymentRoutes.js`)
- Repayment routes → Loan records: completes loan (evidence: `backend/routes/repaymentRoutes.js`)
- Campaign service → Socket.io clients: emits campaign (evidence: `backend/controllers/loanController.js`)
