# wignn/rpl-prod architecture

> Architecture diagram of the GitHub repository wignn/rpl-prod, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wignn/rpl-prod
- Repository: https://github.com/wignn/rpl-prod

## Overview

##### Project type and purpose
- This is a full-stack web application comprising:
- A NestJS backend (API server and business logic)
- A Next.js frontend (React-based UI)
- A Node.js “client” service for WhatsApp API integration
- A PostgreSQL database
- Supporting infrastructure: Docker Compose networking, Caddy reverse proxy, Prometheus metrics, k6 load-testing

##### File structure
- Top-level services (defined in compose.yaml):
- backend/ – NestJS monolith (controllers, services, Prisma schema & migrations, guards, middleware)
- frontend/ – Next.js app (app directory, API routes for NextAuth, components, lib utilities)
- client/ – standalone Node.js service for WhatsApp/Twilio integration
- db – Postgres container (not in file tree but in compose.yaml)
- caddy – reverse proxy (Caddyfile at root)
- prometheus/ & k6/ – monitoring and load-testing scaffolding
- Key patterns:
- Modular NestJS structure (facility, finance, rent, report, room, etc.)
- Prisma ORM for DB access
- NextAuth for authentication flows in Next.js
- Dockerfiles and compose.yaml orchestrate containerized deployment

##### README insights
- Services overview confirms tech stack and responsibilities:
- NestJS handles business logic, JWT guards, error filters, file uploads
- Next.js serves SSR/SSG pages and client API routes
- Client service connects to external WhatsApp APIs for notifications/bots
- PostgreSQL holds all persistent data, managed via Prisma migrations

- Load Balancer / Reverse Proxy (Caddy)
- Frontend (Next.js container)
- Backend API (NestJS container)
- WhatsApp Integration Service (Node.js “client” container)
- Database (PostgreSQL)
- Monitoring (Prometheus server)
- Load-testing (k6) – optional, can be shown as external tool
- File Storage (backend/uploads volume)
- Users ↔️ Caddy → Frontend (HTTP/HTTPS)
- Frontend → Backend API (REST calls, NextAuth token flow)
- Backend API ↔️ PostgreSQL via Prisma client
- Backend API → WhatsApp Service (push requests or via message queue if implemented)
- WhatsApp Service ↔️ External WhatsApp/Twilio APIs
- Backend API → Prometheus client endpoints → Prometheus server (metrics scraping)
- k6 → Caddy/frontdoor (load testing traffic)
c. Architectural patterns & design principles:
- Modular monolith on the backend using NestJS modules & DI
- Clear separation of concerns: UI, business logic, integration service
- Container-based deployment with Docker Compose networking (app-network)
- Infrastructure as code for reverse proxy and monitoring
d. Key technologies & frameworks:
- Frontend: Next.js, React, NextAuth, TypeScript
- Backend: NestJS, Prisma ORM, PostgreSQL, JWT guards, middleware, pipes
- Client: Node.js service calling WhatsApp/Twilio APIs
- DevOps: Docker, Docker Compose, Caddy, Prometheus, k6

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Users
    Users["Users"]:::external

    %% Reverse Proxy / Load Balancer
    Caddy["Caddy Reverse Proxy"]:::blue
    Compose["Docker Compose"]:::blue

    %% Frontend Service
    subgraph "Frontend Layer"
        Frontend["Next.js Frontend"]:::blue
    end

    %% Backend Service
    subgraph "Backend Layer"
        Backend["NestJS API"]:::green
        subgraph "Modules & Utils"
            AppModule["app.module.ts"]:::green
            Guards["guards/"]:::green
            Middleware["auth.middleware.ts"]:::green
            Common["common/"]:::green
            Utils["utils/"]:::green
        end
        MainEntry["main.ts"]:::green
    end

    %% Prisma ORM
    subgraph "Prisma"
        PrismaSchema["schema.prisma"]:::orange
        Migrations["migrations/"]:::orange
    end

    %% File Storage
    Uploads["Uploads Volume"]:::orange

    %% Client Integration Service
    subgraph "Integration Service"
        Client["WhatsApp Client"]:::purple
    end

    %% Database
    DB["PostgreSQL"]:::orange

    %% Monitoring & Testing
    subgraph "Monitoring & Testing"
        Prometheus["Prometheus"]:::gray
        K6["k6 Load Testing"]:::gray
    end

    %% External APIs
    ExternalAPI["WhatsApp / Twilio APIs"]:::external

    %% Connections
    Users -->|"HTTP/HTTPS"| Caddy
    K6 -->|"Load Test Traffic"| Caddy
    Caddy -->|"Serve UI"| Frontend
    Frontend -->|"REST / NextAuth Tokens"| Backend
    Backend -->|"Prisma Client Queries"| DB
    Backend -->|"Uploads"| Uploads
    Backend -->|"Push Messages"| Client
    Client -->|"API Calls"| ExternalAPI
    Backend -->|"Metrics Endpoint"| Prometheus

    %% Docker Compose network
    Compose -.-> Caddy
    Compose -.-> Frontend
    Compose -.-> Backend
    Compose -.-> Client
    Compose -.-> DB
    Compose -.-> Prometheus

    %% Click Events
    click Caddy "https://github.com/wignn/rpl-prod/tree/main/Caddyfile"
    click Compose "https://github.com/wignn/rpl-prod/blob/main/compose.yaml"
    click Frontend "https://github.com/wignn/rpl-prod/tree/main/frontend/"
    click Pages "https://github.com/wignn/rpl-prod/tree/main/frontend/src/app/"
    click AuthRoute "https://github.com/wignn/rpl-prod/blob/main/frontend/src/app/api/auth/[...nextauth]/route.ts"
    click UIComp "https://github.com/wignn/rpl-prod/tree/main/frontend/src/components/"
    click Lib "https://github.com/wignn/rpl-prod/tree/main/frontend/src/lib/"
    click Types "https://github.com/wignn/rpl-prod/tree/main/frontend/src/types/"
    click NextConfig "https://github.com/wignn/rpl-prod/blob/main/frontend/next.config.ts"
    click FrontendDocker "https://github.com/wignn/rpl-prod/tree/main/frontend/Dockerfile"
    click Backend "https://github.com/wignn/rpl-prod/tree/main/backend/"
    click AppModule "https://github.com/wignn/rpl-prod/blob/main/backend/src/app.module.ts"
    click Guards "https://github.com/wignn/rpl-prod/tree/main/backend/src/guards/"
    click Middleware "https://github.com/wignn/rpl-prod/blob/main/backend/src/middleware/auth/auth.middleware.ts"
    click Common "https://github.com/wignn/rpl-prod/tree/main/backend/src/common/"
    click Utils "https://github.com/wignn/rpl-prod/tree/main/backend/src/utils/"
    click MainEntry "https://github.com/wignn/rpl-prod/blob/main/backend/src/main.ts"
    click PrismaSchema "https://github.com/wignn/rpl-prod/blob/main/backend/prisma/schema.prisma"
    click Migrations "https://github.com/wignn/rpl-prod/tree/main/backend/prisma/migrations/"
    click Uploads "https://github.com/wignn/rpl-prod/tree/main/backend/uploads/"
    click BackendDocker "https://github.com/wignn/rpl-prod/tree/main/backend/Dockerfile"
    click Client "https://github.com/wignn/rpl-prod/tree/main/client/"
    click ClientMain "https://github.com/wignn/rpl-prod/blob/main/client/src/index.js"
    click ClientPrisma "https://github.com/wignn/rpl-prod/blob/main/client/prisma/schema.prisma"
    click ClientDocker "https://github.com/wignn/rpl-prod/tree/main/client/Dockerfile"
    click Prometheus "https://github.com/wignn/rpl-prod/blob/main/prometheus/prometheus.yml"
    click K6 "https://github.com/wignn/rpl-prod/blob/main/k6/src/ping.js"
    click K6Config "https://github.com/wignn/rpl-prod/blob/main/k6/package.json"

    %% Styles
    classDef blue fill:#B3D4FC,stroke:#0366D6,stroke-width:1px
    classDef green fill:#C6F6D5,stroke:#2F855A,stroke-width:1px
    classDef purple fill:#E9D8FD,stroke:#6B46C1,stroke-width:1px
    classDef orange fill:#FEEBC8,stroke:#DD6B20,stroke-width:1px
    classDef gray fill:#EDF2F7,stroke:#4A5568,stroke-width:1px
    classDef external fill:#F0FFF4,stroke:#38A169,stroke-width:1px
```
