# pugarchdev/connect.pugarch architecture

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

- Interactive diagram: https://gitdiagram.com/pugarchdev/connect.pugarch
- Repository: https://github.com/pugarchdev/connect.pugarch

## Overview

This is a multi-tenant grievance-management platform with an administrative dashboard and a citizen-facing WhatsApp workflow. Citizens interact through WhatsApp; the backend routes webhook traffic into dynamic flows that can collect grievance details and send replies. Administrators manage grievances, appointments, departments, users, chatbot flows, and company settings through the dashboard. The source index and excerpts establish key backend calls and data models, but do not show all route-to-service wiring or frontend API usage; those links are omitted or marked unverified.

Main entry points: [`backend/src/services/dynamicFlowEngine.ts`](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/dynamicFlowEngine.ts) (Dynamic Flow Engine), [`backend/src/server.ts`](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/server.ts) (API Server), [`backend/src/routes/grievance.routes.ts`](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/grievance.routes.ts) (Grievance Routes), [`backend/src/routes/user.routes.ts`](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/user.routes.ts) (User Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Dashboard"]
  node_dashboard["Dashboard UI"]
  node_api_client["API Client<br/>[client.ts]"]
end

subgraph group_api["Backend API"]
  node_server["API Server<br/>[server.ts]"]
  node_grievance_routes["Grievance Routes"]
  node_user_routes["User Routes<br/>[user.routes.ts]"]
  node_flow_routes["Chatbot Flow Routes"]
  node_whatsapp_routes["WhatsApp Routes<br/>[whatsapp.routes.ts]"]
end

subgraph group_citizen["Citizen Workflows"]
  node_flow_engine["Dynamic Flow Engine"]
  node_whatsapp_service["WhatsApp Service<br/>[whatsappService.ts]"]
end

subgraph group_data["Domain Data"]
  node_grievance_model[("Grievances<br/>[Grievance.ts]")]
  node_user_model[("Users<br/>[User.ts]")]
  node_flow_model[("Chatbot Flows<br/>[ChatbotFlow.ts]")]
  node_appointment_model[("Appointments<br/>[Appointment.ts]")]
  node_company_model[("Companies<br/>[Company.ts]")]
  node_department_model[("Departments<br/>[Department.ts]")]
  node_audit_model[("Audit Logs<br/>[AuditLog.ts]")]
end

subgraph group_platform["Platform Services"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_rbac["Access Control<br/>[rbac.ts]"]
  node_sessions["WhatsApp Sessions<br/>[sessionService.ts]"]
  node_redis[("Redis<br/>[redis.ts]")]
  node_audit["Audit Logging<br/>[auditLogger.ts]"]
end

node_admin(("Administrators"))
node_citizen_actor(("Citizens"))

node_admin -->|"uses"| node_dashboard
node_dashboard -.->|"requests data"| node_api_client
node_api_client -.->|"calls API"| node_server
node_server -->|"mounts webhook"| node_whatsapp_routes
node_server -->|"mounts routes"| node_grievance_routes
node_server -->|"mounts routes"| node_user_routes
node_server -->|"mounts routes"| node_flow_routes
node_whatsapp_routes -.->|"dispatches"| node_flow_engine
node_flow_engine -->|"sends messages"| node_whatsapp_service
node_flow_engine -->|"updates session"| node_sessions
node_sessions -->|"stores sessions"| node_redis
node_flow_engine -->|"reads flows"| node_flow_model
node_flow_engine -->|"creates grievances"| node_grievance_model
node_flow_engine -->|"reads appointments"| node_appointment_model
node_flow_engine -->|"reads company"| node_company_model
node_flow_engine -->|"reads departments"| node_department_model
node_citizen_actor -.->|"sends messages"| node_whatsapp_routes
node_whatsapp_service -.->|"delivers replies"| node_citizen_actor
node_grievance_routes -->|"manages records"| node_grievance_model
node_grievance_routes -->|"records actions"| node_audit
node_user_routes -->|"manages users"| node_user_model
node_user_routes -->|"records actions"| node_audit
node_flow_routes -->|"manages flows"| node_flow_model
node_auth -->|"loads user"| node_user_model
node_auth -->|"checks company"| node_company_model
node_rbac -->|"checks permissions"| node_auth
node_audit -->|"creates entries"| node_audit_model

click node_dashboard "https://github.com/pugarchdev/connect.pugarch/blob/main/frontend/src/components/dashboard/DashboardPageClient.tsx"
click node_api_client "https://github.com/pugarchdev/connect.pugarch/blob/main/frontend/src/lib/api/client.ts"
click node_server "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/server.ts"
click node_grievance_routes "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/grievance.routes.ts"
click node_user_routes "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/user.routes.ts"
click node_flow_routes "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/chatbotFlow.routes.ts"
click node_whatsapp_routes "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/whatsapp.routes.ts"
click node_flow_engine "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/dynamicFlowEngine.ts"
click node_whatsapp_service "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/whatsappService.ts"
click node_grievance_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Grievance.ts"
click node_user_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/User.ts"
click node_flow_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/ChatbotFlow.ts"
click node_appointment_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Appointment.ts"
click node_company_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Company.ts"
click node_department_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Department.ts"
click node_auth "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/middleware/auth.ts"
click node_rbac "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/middleware/rbac.ts"
click node_sessions "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/sessionService.ts"
click node_redis "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/config/redis.ts"
click node_audit "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/utils/auditLogger.ts"
click node_audit_model "https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/AuditLog.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_dashboard,node_api_client toneBlue
class node_server,node_grievance_routes,node_user_routes,node_flow_routes,node_whatsapp_routes toneAmber
class node_flow_engine,node_whatsapp_service toneMint
class node_grievance_model,node_user_model,node_flow_model,node_appointment_model,node_company_model,node_department_model,node_audit_model toneRose
class node_auth,node_rbac,node_sessions,node_redis,node_audit,node_admin,node_citizen_actor toneIndigo
```

## Components

### Dashboard

- [Dashboard UI](https://github.com/pugarchdev/connect.pugarch/blob/main/frontend/src/components/dashboard/DashboardPageClient.tsx): `frontend/src/components/dashboard/DashboardPageClient.tsx`
- [API Client](https://github.com/pugarchdev/connect.pugarch/blob/main/frontend/src/lib/api/client.ts): `frontend/src/lib/api/client.ts`

### Backend API

- [API Server](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [Grievance Routes](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/grievance.routes.ts): `backend/src/routes/grievance.routes.ts`
- [User Routes](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/user.routes.ts): `backend/src/routes/user.routes.ts`
- [Chatbot Flow Routes](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/chatbotFlow.routes.ts): `backend/src/routes/chatbotFlow.routes.ts`
- [WhatsApp Routes](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/routes/whatsapp.routes.ts): `backend/src/routes/whatsapp.routes.ts`

### Citizen Workflows

- [Dynamic Flow Engine](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/dynamicFlowEngine.ts): `backend/src/services/dynamicFlowEngine.ts`
- [WhatsApp Service](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/whatsappService.ts): `backend/src/services/whatsappService.ts`

### Domain Data

- [Grievances](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Grievance.ts): `backend/src/models/Grievance.ts`
- [Users](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/User.ts): `backend/src/models/User.ts`
- [Chatbot Flows](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/ChatbotFlow.ts): `backend/src/models/ChatbotFlow.ts`
- [Appointments](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Appointment.ts): `backend/src/models/Appointment.ts`
- [Companies](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Company.ts): `backend/src/models/Company.ts`
- [Departments](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/Department.ts): `backend/src/models/Department.ts`
- [Audit Logs](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/models/AuditLog.ts): `backend/src/models/AuditLog.ts`

### Platform Services

- [Authentication](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`
- [Access Control](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/middleware/rbac.ts): `backend/src/middleware/rbac.ts`
- [WhatsApp Sessions](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/services/sessionService.ts): `backend/src/services/sessionService.ts`
- [Redis](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/config/redis.ts): `backend/src/config/redis.ts`
- [Audit Logging](https://github.com/pugarchdev/connect.pugarch/blob/main/backend/src/utils/auditLogger.ts): `backend/src/utils/auditLogger.ts`

### Other components

- **Administrators**
- **Citizens**

## Connections

- Administrators → Dashboard UI: uses
- Dashboard UI → API Client: requests data
- API Client → API Server: calls API
- API Server → WhatsApp Routes: mounts webhook (evidence: `backend/src/server.ts`)
- API Server → Grievance Routes: mounts routes (evidence: `backend/src/server.ts`)
- API Server → User Routes: mounts routes (evidence: `backend/src/server.ts`)
- API Server → Chatbot Flow Routes: mounts routes (evidence: `backend/src/server.ts`)
- WhatsApp Routes → Dynamic Flow Engine: dispatches
- Dynamic Flow Engine → WhatsApp Service: sends messages (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- Dynamic Flow Engine → WhatsApp Sessions: updates session (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- WhatsApp Sessions → Redis: stores sessions (evidence: `backend/src/services/sessionService.ts`)
- Dynamic Flow Engine → Chatbot Flows: reads flows (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- Dynamic Flow Engine → Grievances: creates grievances (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- Dynamic Flow Engine → Appointments: reads appointments (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- Dynamic Flow Engine → Companies: reads company (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- Dynamic Flow Engine → Departments: reads departments (evidence: `backend/src/services/dynamicFlowEngine.ts`)
- Citizens → WhatsApp Routes: sends messages
- WhatsApp Service → Citizens: delivers replies
- Grievance Routes → Grievances: manages records (evidence: `backend/src/routes/grievance.routes.ts`)
- Grievance Routes → Audit Logging: records actions (evidence: `backend/src/routes/grievance.routes.ts`)
- User Routes → Users: manages users (evidence: `backend/src/routes/user.routes.ts`)
- User Routes → Audit Logging: records actions (evidence: `backend/src/routes/user.routes.ts`)
- Chatbot Flow Routes → Chatbot Flows: manages flows (evidence: `backend/src/routes/chatbotFlow.routes.ts`)
- Authentication → Users: loads user (evidence: `backend/src/middleware/auth.ts`)
- Authentication → Companies: checks company (evidence: `backend/src/middleware/auth.ts`)
- Access Control → Authentication: checks permissions (evidence: `backend/src/middleware/rbac.ts`)
- Audit Logging → Audit Logs: creates entries (evidence: `backend/src/utils/auditLogger.ts`)
