# malapatilikith/pg architecture

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

- Interactive diagram: https://gitdiagram.com/malapatilikith/pg
- Repository: https://github.com/malapatilikith/pg

## Overview

PG Management System supports multi-role property managers in managing PG properties, rooms, tenants, rent payments, and notifications. The main workflow is to authenticate, choose a PG scope, manage rooms and tenants, generate or update payments, and track receipts and reminders. The frontend routes users to role-protected pages; the Worker API dispatches requests to domain routes, which use PostgreSQL and supporting services. The README documents major capabilities, but some frontend pages and route implementations were not sampled, so their detailed interactions are not shown.

Main entry points: [`backend/src/index.ts`](https://github.com/malapatilikith/pg/blob/main/backend/src/index.ts) (Worker entry), [`frontend/src/App.tsx`](https://github.com/malapatilikith/pg/blob/main/frontend/src/App.tsx) (App routes), [`backend/src/db/schema.ts`](https://github.com/malapatilikith/pg/blob/main/backend/src/db/schema.ts) (Neon PostgreSQL), [`backend/src/services/cron.ts`](https://github.com/malapatilikith/pg/blob/main/backend/src/services/cron.ts) (Payment and reminder scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web and Mobile UI"]
  node_app["App routes<br/>[App.tsx]"]
  node_authui["Auth context<br/>[AuthContext.tsx]"]
  node_authstorage[("Auth storage<br/>[authStorage.ts]")]
  node_tenantui["Tenant management<br/>[Persons.tsx]"]
  node_paymentui["Payment management<br/>[Payments.tsx]"]
  node_founderui["Founder PG detail"]
  node_otherui["Property and admin pages"]
  node_apiclient["API client<br/>[api.ts]"]
end

subgraph group_api["Backend API"]
  node_worker["Worker entry<br/>[index.ts]"]
  node_authroute["Authentication routes<br/>[auth.ts]"]
  node_pgroute["PG routes<br/>[pgs.ts]"]
  node_roomroute["Room routes<br/>[rooms.ts]"]
  node_personroute["Person routes<br/>[persons.ts]"]
  node_paymentroute["Payment routes<br/>[payments.ts]"]
  node_notifyroute["Notification routes<br/>[notifications.ts]"]
  node_authmiddleware["JWT and role checks<br/>[auth.ts]"]
end

subgraph group_data["Data and Files"]
  node_postgres[("Neon PostgreSQL<br/>[schema.ts]")]
  node_r2["Receipt and Aadhaar storage<br/>[r2.ts]"]
end

subgraph group_messaging["Payments and Messaging"]
  node_cron["Payment and reminder scheduler<br/>[cron.ts]"]
  node_sms["WhatsApp messaging<br/>[fast2sms.ts]"]
  node_whatsappconfig["WhatsApp settings"]
end

node_manager(("PG manager"))
node_fast2sms["Messaging provider"]
node_r2service[("Cloudflare R2")]

node_manager -->|"uses"| node_app
node_app -.->|"provides auth"| node_authui
node_app -->|"routes to"| node_tenantui
node_app -->|"routes to"| node_paymentui
node_app -->|"routes to"| node_founderui
node_app -->|"routes to"| node_otherui
node_authui -->|"reads and writes"| node_authstorage
node_authui -->|"requests identity"| node_apiclient
node_tenantui -->|"requests data"| node_apiclient
node_paymentui -->|"requests data"| node_apiclient
node_founderui -->|"requests data"| node_apiclient
node_apiclient -.->|"calls API"| node_worker
node_worker -->|"routes to"| node_authroute
node_worker -->|"routes to"| node_pgroute
node_worker -->|"routes to"| node_roomroute
node_worker -->|"routes to"| node_personroute
node_worker -->|"routes to"| node_paymentroute
node_worker -->|"routes to"| node_notifyroute
node_worker -->|"schedules"| node_cron
node_authroute -->|"checks access"| node_authmiddleware
node_authroute -->|"reads and writes"| node_postgres
node_pgroute -->|"reads and writes"| node_postgres
node_roomroute -->|"reads and writes"| node_postgres
node_personroute -->|"reads and writes"| node_postgres
node_personroute -->|"stores uploads"| node_r2
node_paymentroute -->|"reads and writes"| node_postgres
node_paymentroute -->|"stores receipts"| node_r2
node_paymentroute -->|"generates payments"| node_cron
node_notifyroute -->|"triggers reminders"| node_cron
node_notifyroute -->|"reads logs"| node_postgres
node_cron -->|"reads and writes"| node_postgres
node_cron -->|"sends messages"| node_sms
node_cron -->|"loads settings"| node_whatsappconfig
node_sms -.->|"sends via"| node_fast2sms
node_r2 -.->|"stores files"| node_r2service

click node_app "https://github.com/malapatilikith/pg/blob/main/frontend/src/App.tsx"
click node_authui "https://github.com/malapatilikith/pg/blob/main/frontend/src/context/AuthContext.tsx"
click node_authstorage "https://github.com/malapatilikith/pg/blob/main/frontend/src/utils/authStorage.ts"
click node_tenantui "https://github.com/malapatilikith/pg/blob/main/frontend/src/pages/Persons.tsx"
click node_paymentui "https://github.com/malapatilikith/pg/blob/main/frontend/src/pages/Payments.tsx"
click node_founderui "https://github.com/malapatilikith/pg/blob/main/frontend/src/pages/FounderPgDetail.tsx"
click node_otherui "https://github.com/malapatilikith/pg/tree/main/frontend/src/pages"
click node_apiclient "https://github.com/malapatilikith/pg/blob/main/frontend/src/utils/api.ts"
click node_worker "https://github.com/malapatilikith/pg/blob/main/backend/src/index.ts"
click node_authroute "https://github.com/malapatilikith/pg/blob/main/backend/src/routes/auth.ts"
click node_pgroute "https://github.com/malapatilikith/pg/blob/main/backend/src/routes/pgs.ts"
click node_roomroute "https://github.com/malapatilikith/pg/blob/main/backend/src/routes/rooms.ts"
click node_personroute "https://github.com/malapatilikith/pg/blob/main/backend/src/routes/persons.ts"
click node_paymentroute "https://github.com/malapatilikith/pg/blob/main/backend/src/routes/payments.ts"
click node_notifyroute "https://github.com/malapatilikith/pg/blob/main/backend/src/routes/notifications.ts"
click node_authmiddleware "https://github.com/malapatilikith/pg/blob/main/backend/src/middleware/auth.ts"
click node_postgres "https://github.com/malapatilikith/pg/blob/main/backend/src/db/schema.ts"
click node_r2 "https://github.com/malapatilikith/pg/blob/main/backend/src/services/r2.ts"
click node_cron "https://github.com/malapatilikith/pg/blob/main/backend/src/services/cron.ts"
click node_sms "https://github.com/malapatilikith/pg/blob/main/backend/src/services/fast2sms.ts"
click node_whatsappconfig "https://github.com/malapatilikith/pg/blob/main/backend/src/services/whatsappSettings.ts"

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_authstorage,node_tenantui,node_paymentui,node_founderui,node_otherui,node_apiclient toneBlue
class node_worker,node_authroute,node_pgroute,node_roomroute,node_personroute,node_paymentroute,node_notifyroute,node_authmiddleware,node_r2service toneAmber
class node_postgres,node_r2 toneMint
class node_cron,node_sms,node_whatsappconfig toneRose
class node_manager,node_fast2sms toneIndigo
```

## Components

### Web and Mobile UI

- [App routes](https://github.com/malapatilikith/pg/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Auth context](https://github.com/malapatilikith/pg/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Auth storage](https://github.com/malapatilikith/pg/blob/main/frontend/src/utils/authStorage.ts): `frontend/src/utils/authStorage.ts`
- [Tenant management](https://github.com/malapatilikith/pg/blob/main/frontend/src/pages/Persons.tsx): `frontend/src/pages/Persons.tsx`
- [Payment management](https://github.com/malapatilikith/pg/blob/main/frontend/src/pages/Payments.tsx): `frontend/src/pages/Payments.tsx`
- [Founder PG detail](https://github.com/malapatilikith/pg/blob/main/frontend/src/pages/FounderPgDetail.tsx): `frontend/src/pages/FounderPgDetail.tsx`
- [Property and admin pages](https://github.com/malapatilikith/pg/tree/main/frontend/src/pages): `frontend/src/pages`
- [API client](https://github.com/malapatilikith/pg/blob/main/frontend/src/utils/api.ts): `frontend/src/utils/api.ts`

### Backend API

- [Worker entry](https://github.com/malapatilikith/pg/blob/main/backend/src/index.ts): `backend/src/index.ts`
- [Authentication routes](https://github.com/malapatilikith/pg/blob/main/backend/src/routes/auth.ts): `backend/src/routes/auth.ts`
- [PG routes](https://github.com/malapatilikith/pg/blob/main/backend/src/routes/pgs.ts): `backend/src/routes/pgs.ts`
- [Room routes](https://github.com/malapatilikith/pg/blob/main/backend/src/routes/rooms.ts): `backend/src/routes/rooms.ts`
- [Person routes](https://github.com/malapatilikith/pg/blob/main/backend/src/routes/persons.ts): `backend/src/routes/persons.ts`
- [Payment routes](https://github.com/malapatilikith/pg/blob/main/backend/src/routes/payments.ts): `backend/src/routes/payments.ts`
- [Notification routes](https://github.com/malapatilikith/pg/blob/main/backend/src/routes/notifications.ts): `backend/src/routes/notifications.ts`
- [JWT and role checks](https://github.com/malapatilikith/pg/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`

### Data and Files

- [Neon PostgreSQL](https://github.com/malapatilikith/pg/blob/main/backend/src/db/schema.ts): `backend/src/db/schema.ts`
- [Receipt and Aadhaar storage](https://github.com/malapatilikith/pg/blob/main/backend/src/services/r2.ts): `backend/src/services/r2.ts`

### Payments and Messaging

- [Payment and reminder scheduler](https://github.com/malapatilikith/pg/blob/main/backend/src/services/cron.ts): `backend/src/services/cron.ts`
- [WhatsApp messaging](https://github.com/malapatilikith/pg/blob/main/backend/src/services/fast2sms.ts): `backend/src/services/fast2sms.ts`
- [WhatsApp settings](https://github.com/malapatilikith/pg/blob/main/backend/src/services/whatsappSettings.ts): `backend/src/services/whatsappSettings.ts`

### Other components

- **PG manager**
- **Messaging provider**
- **Cloudflare R2**

## Connections

- PG manager → App routes: uses (evidence: `frontend/src/App.tsx`)
- App routes → Auth context: provides auth
- App routes → Tenant management: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Payment management: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Founder PG detail: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Property and admin pages: routes to (evidence: `frontend/src/App.tsx`)
- Auth context → Auth storage: reads and writes (evidence: `frontend/src/context/AuthContext.tsx`)
- Auth context → API client: requests identity (evidence: `frontend/src/context/AuthContext.tsx`)
- Tenant management → API client: requests data (evidence: `frontend/src/pages/Persons.tsx`)
- Payment management → API client: requests data (evidence: `frontend/src/pages/Payments.tsx`)
- Founder PG detail → API client: requests data (evidence: `frontend/src/pages/FounderPgDetail.tsx`)
- API client → Worker entry: calls API
- Worker entry → Authentication routes: routes to (evidence: `backend/src/index.ts`)
- Worker entry → PG routes: routes to (evidence: `backend/src/index.ts`)
- Worker entry → Room routes: routes to (evidence: `backend/src/index.ts`)
- Worker entry → Person routes: routes to (evidence: `backend/src/index.ts`)
- Worker entry → Payment routes: routes to (evidence: `backend/src/index.ts`)
- Worker entry → Notification routes: routes to (evidence: `backend/src/index.ts`)
- Worker entry → Payment and reminder scheduler: schedules (evidence: `backend/src/index.ts`)
- Authentication routes → JWT and role checks: checks access (evidence: `backend/src/routes/auth.ts`)
- Authentication routes → Neon PostgreSQL: reads and writes (evidence: `backend/src/routes/auth.ts`)
- PG routes → Neon PostgreSQL: reads and writes (evidence: `backend/src/routes/pgs.ts`)
- Room routes → Neon PostgreSQL: reads and writes (evidence: `backend/src/routes/rooms.ts`)
- Person routes → Neon PostgreSQL: reads and writes (evidence: `backend/src/routes/persons.ts`)
- Person routes → Receipt and Aadhaar storage: stores uploads (evidence: `backend/src/routes/persons.ts`)
- Payment routes → Neon PostgreSQL: reads and writes (evidence: `backend/src/routes/payments.ts`)
- Payment routes → Receipt and Aadhaar storage: stores receipts (evidence: `backend/src/routes/payments.ts`)
- Payment routes → Payment and reminder scheduler: generates payments (evidence: `backend/src/routes/payments.ts`)
- Notification routes → Payment and reminder scheduler: triggers reminders (evidence: `backend/src/routes/notifications.ts`)
- Notification routes → Neon PostgreSQL: reads logs (evidence: `backend/src/routes/notifications.ts`)
- Payment and reminder scheduler → Neon PostgreSQL: reads and writes (evidence: `backend/src/services/cron.ts`)
- Payment and reminder scheduler → WhatsApp messaging: sends messages (evidence: `backend/src/services/cron.ts`)
- Payment and reminder scheduler → WhatsApp settings: loads settings (evidence: `backend/src/services/cron.ts`)
- WhatsApp messaging → Messaging provider: sends via
- Receipt and Aadhaar storage → Cloudflare R2: stores files
