# iloveflo/mobile_programming_api architecture

> Architecture diagram of the GitHub repository iloveflo/mobile_programming_api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iloveflo/mobile_programming_api
- Repository: https://github.com/iloveflo/mobile_programming_api

## Overview

FinCredit is a personal-debt amortization and credit-health API. The main workflow runs from a mobile client through Express routing and authentication into domain handlers, which read and mutate PostgreSQL and return finance data; loan schedules, credit health, debt strategies, and simulations are distinct product stages. Other documented capabilities include file storage, PDF dossiers, provider-based eKYC, and notifications. The map uses the README and indexed references; unsampled subsystem internals and event wiring are not asserted beyond documented relationships.

Main entry points: [`src/app.js`](https://github.com/iloveflo/mobile_programming_api/blob/main/src/app.js) (Express API), [`src/config/db.js`](https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/db.js) (PostgreSQL), [`src/services/notification.service.js`](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/notification.service.js) (Notification worker), [`src/services/loan.service.js`](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/loan.service.js) (Loan rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_app["Express API<br/>[app.js]"]
  node_authmw["Bearer authentication<br/>[auth.middleware.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_authctrl["Authentication<br/>[auth.controller.js]"]
  node_authsvc["OTP and sessions<br/>[auth.service.js]"]
  node_userroutes["User routes<br/>[user.routes.js]"]
  node_userctrl["User profile<br/>[user.controller.js]"]
end

subgraph group_finance["Finance domains"]
  node_loanroutes["Loan routes<br/>[loan.routes.js]"]
  node_loanctrl["Loan handling<br/>[loan.controller.js]"]
  node_loansvc["Loan rules<br/>[loan.service.js]"]
  node_scheduleroutes["Schedule routes<br/>[schedule.routes.js]"]
  node_schedulectrl["Payment schedules"]
  node_creditroutes["Credit routes<br/>[credit.routes.js]"]
  node_creditctrl["Credit reports"]
  node_creditsvc["Credit scoring<br/>[credit.service.js]"]
  node_debtroutes["Debt routes<br/>[debt.routes.js]"]
  node_debtctrl["Debt strategies<br/>[debt.controller.js]"]
  node_simroutes["Simulation routes"]
  node_simctrl["Repayment scenarios"]
end

subgraph group_integrations["Documents and messaging"]
  node_storageroutes["Storage routes<br/>[storage.routes.js]"]
  node_storagectrl["Upload verification"]
  node_r2["R2 storage<br/>[r2.js]"]
  node_pdf["Financial PDF<br/>[pdf.service.js]"]
  node_provider["eKYC providers"]
  node_notifications["Notification worker"]
  node_push["Push delivery<br/>[push.service.js]"]
  node_email["Email templates<br/>[email-templates.js]"]
end

subgraph group_platform["Persistence and realtime"]
  node_db[("PostgreSQL<br/>[db.js]")]
  node_socket["Realtime sockets<br/>[socket.server.js]"]
  node_apiutil["API and SQL helpers<br/>[api.js]"]
  node_dto["Finance DTOs<br/>[dto.js]"]
  node_constants["Finance rules<br/>[constants.js]"]
end

node_client(("Mobile client"))
node_cloud{{"Cloud services"}}

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_authroutes
node_app -->|"mounts routes"| node_userroutes
node_app -->|"mounts routes"| node_loanroutes
node_app -->|"mounts routes"| node_scheduleroutes
node_app -->|"mounts routes"| node_creditroutes
node_app -->|"mounts routes"| node_debtroutes
node_app -->|"mounts routes"| node_simroutes
node_app -->|"mounts routes"| node_storageroutes
node_authroutes -->|"guards endpoints"| node_authmw
node_authroutes -->|"dispatches to"| node_authctrl
node_authmw -->|"authenticates with"| node_authsvc
node_authctrl -->|"calls"| node_authsvc
node_authsvc -->|"stores credentials"| node_db
node_authsvc -->|"renders OTP mail"| node_email
node_userroutes -->|"dispatches to"| node_userctrl
node_userctrl -->|"requests verification"| node_provider
node_userctrl -->|"requests credit data"| node_creditsvc
node_userctrl -->|"generates dossier"| node_pdf
node_loanroutes -->|"dispatches to"| node_loanctrl
node_loanctrl -->|"delegates loan rules"| node_loansvc
node_loanctrl -->|"queries loans"| node_db
node_loansvc -->|"reads and writes"| node_db
node_loanctrl -->|"requests alerts"| node_notifications
node_scheduleroutes -->|"dispatches to"| node_schedulectrl
node_schedulectrl -->|"reads and updates"| node_db
node_schedulectrl -->|"uses loan rules"| node_loansvc
node_schedulectrl -->|"requests alerts"| node_notifications
node_creditroutes -->|"dispatches to"| node_creditctrl
node_creditctrl -->|"delegates scoring"| node_creditsvc
node_creditsvc -->|"reads and writes"| node_db
node_debtroutes -->|"dispatches to"| node_debtctrl
node_debtctrl -->|"persists strategies"| node_db
node_simroutes -->|"dispatches to"| node_simctrl
node_simctrl -->|"uses loan rules"| node_loansvc
node_storageroutes -->|"dispatches to"| node_storagectrl
node_storagectrl -->|"signs and checks files"| node_r2
node_storagectrl -->|"checks loan ownership"| node_loansvc
node_storagectrl -->|"records uploads"| node_db
node_pdf -->|"reads stored files"| node_r2
node_provider -.->|"calls verification"| node_cloud
node_notifications -->|"dispatches push"| node_push
node_notifications -->|"renders mail"| node_email
node_notifications -->|"queries notifications"| node_db
node_notifications -.->|"sends messages"| node_cloud
node_push -->|"sends FCM"| node_cloud
node_db -->|"notifies changes"| node_socket
node_socket -->|"pushes updates"| node_client

click node_app "https://github.com/iloveflo/mobile_programming_api/blob/main/src/app.js"
click node_authmw "https://github.com/iloveflo/mobile_programming_api/blob/main/src/middlewares/auth.middleware.js"
click node_authroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/auth.routes.js"
click node_authctrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/auth.controller.js"
click node_authsvc "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/auth.service.js"
click node_userroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/user.routes.js"
click node_userctrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/user.controller.js"
click node_loanroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/loan.routes.js"
click node_loanctrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/loan.controller.js"
click node_loansvc "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/loan.service.js"
click node_scheduleroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/schedule.routes.js"
click node_schedulectrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/schedule.controller.js"
click node_creditroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/credit.routes.js"
click node_creditctrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/credit.controller.js"
click node_creditsvc "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/credit.service.js"
click node_debtroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/debt.routes.js"
click node_debtctrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/debt.controller.js"
click node_simroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/simulation.routes.js"
click node_simctrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/simulation.controller.js"
click node_storageroutes "https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/storage.routes.js"
click node_storagectrl "https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/storage.controller.js"
click node_r2 "https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/r2.js"
click node_pdf "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/pdf.service.js"
click node_provider "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/provider.service.js"
click node_notifications "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/notification.service.js"
click node_push "https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/push.service.js"
click node_email "https://github.com/iloveflo/mobile_programming_api/blob/main/src/utils/email-templates.js"
click node_db "https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/db.js"
click node_socket "https://github.com/iloveflo/mobile_programming_api/blob/main/src/sockets/socket.server.js"
click node_apiutil "https://github.com/iloveflo/mobile_programming_api/blob/main/src/utils/api.js"
click node_dto "https://github.com/iloveflo/mobile_programming_api/blob/main/src/utils/dto.js"
click node_constants "https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/constants.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_authmw,node_authroutes,node_authctrl,node_authsvc,node_userroutes,node_userctrl,node_client toneBlue
class node_loanroutes,node_loanctrl,node_loansvc,node_scheduleroutes,node_schedulectrl,node_creditroutes,node_creditctrl,node_creditsvc,node_debtroutes,node_debtctrl,node_simroutes,node_simctrl toneAmber
class node_storageroutes,node_storagectrl,node_r2,node_pdf,node_provider,node_notifications,node_push,node_email toneMint
class node_db,node_socket,node_apiutil,node_dto,node_constants toneRose
class node_cloud toneIndigo
```

## Components

### API and identity

- [Express API](https://github.com/iloveflo/mobile_programming_api/blob/main/src/app.js): `src/app.js`
- [Bearer authentication](https://github.com/iloveflo/mobile_programming_api/blob/main/src/middlewares/auth.middleware.js): `src/middlewares/auth.middleware.js`
- [Auth routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/auth.routes.js): `src/routes/auth.routes.js`
- [Authentication](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/auth.controller.js): `src/controllers/auth.controller.js`
- [OTP and sessions](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/auth.service.js): `src/services/auth.service.js`
- [User routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/user.routes.js): `src/routes/user.routes.js`
- [User profile](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/user.controller.js): `src/controllers/user.controller.js`

### Finance domains

- [Loan routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/loan.routes.js): `src/routes/loan.routes.js`
- [Loan handling](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/loan.controller.js): `src/controllers/loan.controller.js`
- [Loan rules](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/loan.service.js): `src/services/loan.service.js`
- [Schedule routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/schedule.routes.js): `src/routes/schedule.routes.js`
- [Payment schedules](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/schedule.controller.js): `src/controllers/schedule.controller.js`
- [Credit routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/credit.routes.js): `src/routes/credit.routes.js`
- [Credit reports](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/credit.controller.js): `src/controllers/credit.controller.js`
- [Credit scoring](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/credit.service.js): `src/services/credit.service.js`
- [Debt routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/debt.routes.js): `src/routes/debt.routes.js`
- [Debt strategies](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/debt.controller.js): `src/controllers/debt.controller.js`
- [Simulation routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/simulation.routes.js): `src/routes/simulation.routes.js`
- [Repayment scenarios](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/simulation.controller.js): `src/controllers/simulation.controller.js`

### Documents and messaging

- [Storage routes](https://github.com/iloveflo/mobile_programming_api/blob/main/src/routes/storage.routes.js): `src/routes/storage.routes.js`
- [Upload verification](https://github.com/iloveflo/mobile_programming_api/blob/main/src/controllers/storage.controller.js): `src/controllers/storage.controller.js`
- [R2 storage](https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/r2.js): `src/config/r2.js`
- [Financial PDF](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/pdf.service.js): `src/services/pdf.service.js`
- [eKYC providers](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/provider.service.js): `src/services/provider.service.js`
- [Notification worker](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/notification.service.js): `src/services/notification.service.js`
- [Push delivery](https://github.com/iloveflo/mobile_programming_api/blob/main/src/services/push.service.js): `src/services/push.service.js`
- [Email templates](https://github.com/iloveflo/mobile_programming_api/blob/main/src/utils/email-templates.js): `src/utils/email-templates.js`

### Persistence and realtime

- [PostgreSQL](https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/db.js): `src/config/db.js`
- [Realtime sockets](https://github.com/iloveflo/mobile_programming_api/blob/main/src/sockets/socket.server.js): `src/sockets/socket.server.js`
- [API and SQL helpers](https://github.com/iloveflo/mobile_programming_api/blob/main/src/utils/api.js): `src/utils/api.js`
- [Finance DTOs](https://github.com/iloveflo/mobile_programming_api/blob/main/src/utils/dto.js): `src/utils/dto.js`
- [Finance rules](https://github.com/iloveflo/mobile_programming_api/blob/main/src/config/constants.js): `src/config/constants.js`

### Other components

- **Mobile client**
- **Cloud services**

## Connections

- Mobile client → Express API: sends requests
- Express API → Auth routes: mounts routes (evidence: `src/app.js`)
- Express API → User routes: mounts routes (evidence: `src/app.js`)
- Express API → Loan routes: mounts routes (evidence: `src/app.js`)
- Express API → Schedule routes: mounts routes (evidence: `src/app.js`)
- Express API → Credit routes: mounts routes (evidence: `src/app.js`)
- Express API → Debt routes: mounts routes (evidence: `src/app.js`)
- Express API → Simulation routes: mounts routes (evidence: `src/app.js`)
- Express API → Storage routes: mounts routes (evidence: `src/app.js`)
- Auth routes → Bearer authentication: guards endpoints (evidence: `src/routes/auth.routes.js`)
- Auth routes → Authentication: dispatches to (evidence: `src/routes/auth.routes.js`)
- Bearer authentication → OTP and sessions: authenticates with (evidence: `src/middlewares/auth.middleware.js`)
- Authentication → OTP and sessions: calls (evidence: `src/controllers/auth.controller.js`)
- OTP and sessions → PostgreSQL: stores credentials (evidence: `src/services/auth.service.js`)
- OTP and sessions → Email templates: renders OTP mail (evidence: `src/services/auth.service.js`)
- User routes → User profile: dispatches to (evidence: `src/routes/user.routes.js`)
- User profile → eKYC providers: requests verification (evidence: `src/controllers/user.controller.js`)
- User profile → Credit scoring: requests credit data (evidence: `src/controllers/user.controller.js`)
- User profile → Financial PDF: generates dossier (evidence: `src/controllers/user.controller.js`)
- Loan routes → Loan handling: dispatches to (evidence: `src/routes/loan.routes.js`)
- Loan handling → Loan rules: delegates loan rules (evidence: `src/controllers/loan.controller.js`)
- Loan handling → PostgreSQL: queries loans (evidence: `src/controllers/loan.controller.js`)
- Loan rules → PostgreSQL: reads and writes (evidence: `src/services/loan.service.js`)
- Loan handling → Notification worker: requests alerts (evidence: `src/controllers/loan.controller.js`)
- Schedule routes → Payment schedules: dispatches to (evidence: `src/routes/schedule.routes.js`)
- Payment schedules → PostgreSQL: reads and updates (evidence: `src/controllers/schedule.controller.js`)
- Payment schedules → Loan rules: uses loan rules (evidence: `src/controllers/schedule.controller.js`)
- Payment schedules → Notification worker: requests alerts (evidence: `src/controllers/schedule.controller.js`)
- Credit routes → Credit reports: dispatches to (evidence: `src/routes/credit.routes.js`)
- Credit reports → Credit scoring: delegates scoring (evidence: `src/controllers/credit.controller.js`)
- Credit scoring → PostgreSQL: reads and writes (evidence: `src/services/credit.service.js`)
- Debt routes → Debt strategies: dispatches to (evidence: `src/routes/debt.routes.js`)
- Debt strategies → PostgreSQL: persists strategies (evidence: `src/controllers/debt.controller.js`)
- Simulation routes → Repayment scenarios: dispatches to (evidence: `src/routes/simulation.routes.js`)
- Repayment scenarios → Loan rules: uses loan rules (evidence: `src/controllers/simulation.controller.js`)
- Storage routes → Upload verification: dispatches to (evidence: `src/routes/storage.routes.js`)
- Upload verification → R2 storage: signs and checks files (evidence: `src/controllers/storage.controller.js`)
- Upload verification → Loan rules: checks loan ownership (evidence: `src/controllers/storage.controller.js`)
- Upload verification → PostgreSQL: records uploads (evidence: `src/controllers/storage.controller.js`)
- Financial PDF → R2 storage: reads stored files (evidence: `src/services/pdf.service.js`)
- eKYC providers → Cloud services: calls verification
- Notification worker → Push delivery: dispatches push (evidence: `src/services/notification.service.js`)
- Notification worker → Email templates: renders mail (evidence: `src/services/notification.service.js`)
- Notification worker → PostgreSQL: queries notifications (evidence: `src/services/notification.service.js`)
- Notification worker → Cloud services: sends messages
- Push delivery → Cloud services: sends FCM
- PostgreSQL → Realtime sockets: notifies changes
- Realtime sockets → Mobile client: pushes updates
