# aiyow/rsgfinancial_cap architecture

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

- Interactive diagram: https://gitdiagram.com/aiyow/rsgfinancial_cap
- Repository: https://github.com/aiyow/rsgfinancial_cap

## Overview

RSG Condo is a role-based condominium water-billing and management system. Residents, collectors, and admins use role-specific screens; collectors import readings and generate SOAs, residents submit payment proofs, and staff review bills and payments. Billing-period processing also updates forecasts and recommendations. The backend exposes these workflows through Express routes backed by PostgreSQL, with receipt storage and email delivery integrations. The graph preserves documented analytics, reporting, audit, notification, and administration capabilities. Some route and page implementations were not sampled, so their internal calls are omitted where the available evidence does not establish them.

Main entry points: [`backend/routes/billingPeriodRoutes.js`](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/billingPeriodRoutes.js) (Billing period workflow), [`backend/routes/paymentRoutes.js`](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/paymentRoutes.js) (Payment review), [`frontend/src/App.jsx`](https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/App.jsx) (Route application), [`backend/services/paymentLedger.js`](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/paymentLedger.js) (Payment ledger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Role-based frontend"]
  node_app["Route application<br/>[App.jsx]"]
  node_rolepages["Role workspaces"]
  node_authui["Authentication screens<br/>[Login.jsx]"]
  node_apiclient["API client<br/>[api.js]"]
end

subgraph group_billing["Billing and payments"]
  node_billingperiod["Billing period workflow"]
  node_bills["SOA and bills<br/>[billRoutes.js]"]
  node_payments["Payment review<br/>[paymentRoutes.js]"]
  node_ledger["Payment ledger<br/>[paymentLedger.js]"]
  node_receipt["Receipt OCR and storage<br/>[receiptOcr.js]"]
end

subgraph group_insights["Analytics and reporting"]
  node_forecast["Water forecasts"]
  node_recommend["Prescriptive insights"]
  node_analytics["Analytics routes<br/>[analyticsRoutes.js]"]
  node_history["Historical imports"]
  node_reports["Financial reports"]
end

subgraph group_platform["API and shared services"]
  node_server["Express API server<br/>[server.js]"]
  node_routes["Domain API routes"]
  node_auth["JWT authorization<br/>[authMiddleware.js]"]
  node_dbpool["Database connection pool<br/>[db.js]"]
  node_audit["Audit logging<br/>[auditLog.js]"]
  node_notifications["User notifications<br/>[notifications.js]"]
  node_email["SOA email delivery"]
end

node_user(("Admin, collector, resident"))
node_cloudinary["Cloudinary"]
node_database[("PostgreSQL")]
node_smtp["SMTP service"]

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_rolepages
node_app -->|"routes to"| node_authui
node_app -.-> node_apiclient
node_server -->|"mounts"| node_routes
node_server -->|"queries"| node_dbpool
node_routes -->|"uses"| node_auth
node_routes -->|"queries"| node_dbpool
node_billingperiod -->|"regenerates"| node_forecast
node_billingperiod -->|"regenerates"| node_recommend
node_billingperiod -->|"applies credits"| node_ledger
node_billingperiod -->|"notifies users"| node_notifications
node_billingperiod -->|"delivers SOAs"| node_email
node_bills -->|"applies payments"| node_ledger
node_bills -->|"notifies residents"| node_notifications
node_payments -->|"analyzes receipt"| node_receipt
node_payments -->|"uploads receipt"| node_cloudinary
node_payments -->|"allocates credits"| node_ledger
node_payments -->|"regenerates"| node_recommend
node_payments -->|"notifies staff"| node_notifications
node_billingperiod -->|"reads and writes"| node_database
node_ledger -->|"reads and writes"| node_database
node_auth -->|"checks account"| node_database
node_audit -->|"writes entries"| node_database
node_recommend -->|"uses forecasts"| node_forecast
node_analytics -.-> node_forecast
node_history -.-> node_analytics
node_reports -.->|"queries"| node_database
node_email -.->|"sends email"| node_smtp

click node_app "https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/App.jsx"
click node_rolepages "https://github.com/aiyow/rsgfinancial_cap/tree/main/frontend/src/pages"
click node_authui "https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/pages/Login.jsx"
click node_apiclient "https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/services/api.js"
click node_billingperiod "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/billingPeriodRoutes.js"
click node_bills "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/billRoutes.js"
click node_payments "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/paymentRoutes.js"
click node_ledger "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/paymentLedger.js"
click node_receipt "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/receiptOcr.js"
click node_forecast "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/predictiveAnalytics.js"
click node_recommend "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/prescriptiveAnalytics.js"
click node_analytics "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/analyticsRoutes.js"
click node_history "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/analyticsImportRoutes.js"
click node_reports "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/financialReports.js"
click node_server "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/server.js"
click node_routes "https://github.com/aiyow/rsgfinancial_cap/tree/main/backend/routes"
click node_auth "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/middleware/authMiddleware.js"
click node_dbpool "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/config/db.js"
click node_audit "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/auditLog.js"
click node_notifications "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/notifications.js"
click node_email "https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/soaEmailDeliveries.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_rolepages,node_authui,node_apiclient toneBlue
class node_billingperiod,node_bills,node_payments,node_ledger,node_receipt,node_database toneAmber
class node_forecast,node_recommend,node_analytics,node_history,node_reports toneMint
class node_server,node_routes,node_auth,node_dbpool,node_audit,node_notifications,node_email toneRose
class node_user,node_cloudinary,node_smtp toneIndigo
```

## Components

### Role-based frontend

- [Route application](https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Role workspaces](https://github.com/aiyow/rsgfinancial_cap/tree/main/frontend/src/pages): `frontend/src/pages`
- [Authentication screens](https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [API client](https://github.com/aiyow/rsgfinancial_cap/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Billing and payments

- [Billing period workflow](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/billingPeriodRoutes.js): `backend/routes/billingPeriodRoutes.js`
- [SOA and bills](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/billRoutes.js): `backend/routes/billRoutes.js`
- [Payment review](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/paymentRoutes.js): `backend/routes/paymentRoutes.js`
- [Payment ledger](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/paymentLedger.js): `backend/services/paymentLedger.js`
- [Receipt OCR and storage](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/receiptOcr.js): `backend/services/receiptOcr.js`

### Analytics and reporting

- [Water forecasts](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/predictiveAnalytics.js): `backend/services/predictiveAnalytics.js`
- [Prescriptive insights](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/prescriptiveAnalytics.js): `backend/services/prescriptiveAnalytics.js`
- [Analytics routes](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/analyticsRoutes.js): `backend/routes/analyticsRoutes.js`
- [Historical imports](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/routes/analyticsImportRoutes.js): `backend/routes/analyticsImportRoutes.js`
- [Financial reports](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/financialReports.js): `backend/services/financialReports.js`

### API and shared services

- [Express API server](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/server.js): `backend/server.js`
- [Domain API routes](https://github.com/aiyow/rsgfinancial_cap/tree/main/backend/routes): `backend/routes`
- [JWT authorization](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [Database connection pool](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/config/db.js): `backend/config/db.js`
- [Audit logging](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/auditLog.js): `backend/services/auditLog.js`
- [User notifications](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/notifications.js): `backend/services/notifications.js`
- [SOA email delivery](https://github.com/aiyow/rsgfinancial_cap/blob/main/backend/services/soaEmailDeliveries.js): `backend/services/soaEmailDeliveries.js`

### Other components

- **Admin, collector, resident**
- **Cloudinary**
- **PostgreSQL**
- **SMTP service**

## Connections

- Admin, collector, resident → Route application: uses (evidence: `README.md`)
- Route application → Role workspaces: routes to (evidence: `frontend/src/App.jsx`)
- Route application → Authentication screens: routes to (evidence: `frontend/src/App.jsx`)
- Route application → API client
- Express API server → Domain API routes: mounts (evidence: `backend/server.js`)
- Express API server → Database connection pool: queries (evidence: `backend/server.js`)
- Domain API routes → JWT authorization: uses (evidence: `backend/routes/billingPeriodRoutes.js`)
- Domain API routes → Database connection pool: queries (evidence: `backend/routes/billingPeriodRoutes.js`)
- Billing period workflow → Water forecasts: regenerates (evidence: `backend/routes/billingPeriodRoutes.js`)
- Billing period workflow → Prescriptive insights: regenerates (evidence: `backend/routes/billingPeriodRoutes.js`)
- Billing period workflow → Payment ledger: applies credits (evidence: `backend/routes/billingPeriodRoutes.js`)
- Billing period workflow → User notifications: notifies users (evidence: `backend/routes/billingPeriodRoutes.js`)
- Billing period workflow → SOA email delivery: delivers SOAs (evidence: `backend/routes/billingPeriodRoutes.js`)
- SOA and bills → Payment ledger: applies payments (evidence: `backend/routes/billRoutes.js`)
- SOA and bills → User notifications: notifies residents (evidence: `backend/routes/billRoutes.js`)
- Payment review → Receipt OCR and storage: analyzes receipt (evidence: `backend/routes/paymentRoutes.js`)
- Payment review → Cloudinary: uploads receipt (evidence: `README.md`)
- Payment review → Payment ledger: allocates credits (evidence: `backend/routes/paymentRoutes.js`)
- Payment review → Prescriptive insights: regenerates (evidence: `backend/routes/paymentRoutes.js`)
- Payment review → User notifications: notifies staff (evidence: `backend/routes/paymentRoutes.js`)
- Billing period workflow → PostgreSQL: reads and writes (evidence: `backend/routes/billingPeriodRoutes.js`)
- Payment ledger → PostgreSQL: reads and writes (evidence: `backend/services/paymentLedger.js`)
- JWT authorization → PostgreSQL: checks account (evidence: `backend/middleware/authMiddleware.js`)
- Audit logging → PostgreSQL: writes entries (evidence: `backend/services/auditLog.js`)
- Prescriptive insights → Water forecasts: uses forecasts (evidence: `backend/services/prescriptiveAnalytics.js`)
- Analytics routes → Water forecasts
- Historical imports → Analytics routes
- Financial reports → PostgreSQL: queries
- SOA email delivery → SMTP service: sends email
