# punkuz/whatsapp-backend architecture

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

- Interactive diagram: https://gitdiagram.com/punkuz/whatsapp-backend
- Repository: https://github.com/punkuz/whatsapp-backend

## Overview

This NestJS starter implements account signup/login, user lookup and updates, and chat through both HTTP endpoints and a WebSocket gateway. The principal flow is a client request routed to an authentication or chat entry point, then handled by a service that verifies or persists domain data. PostgreSQL is configured at application startup; Redis provides a separate Pub/Sub service, but the available evidence does not show a chat component consuming it. Gateway behavior is represented only at the service/guard boundary because its implementation details were not excerpted.

Main entry points: [`src/auth/auth.service.ts`](https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/auth.service.ts) (Auth Service), [`src/chat/chat.service.ts`](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.service.ts) (Chat Service), [`src/chat/chat.gateway.ts`](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.gateway.ts) (WebSocket Gateway), [`src/main.ts`](https://github.com/punkuz/whatsapp-backend/blob/main/src/main.ts) (Nest Bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Application Runtime"]
  node_main["Nest Bootstrap<br/>[main.ts]"]
  node_app["Application Modules<br/>[app.module.ts]"]
end

subgraph group_accounts["Accounts and Authentication"]
  node_auth_api["Auth HTTP API<br/>[auth.controller.ts]"]
  node_auth_service["Auth Service<br/>[auth.service.ts]"]
  node_http_guard["HTTP Guard<br/>[http.guard.ts]"]
  node_user_api["User HTTP API<br/>[user.controller.ts]"]
  node_user_service["User Service<br/>[user.service.ts]"]
  node_user_entity["User Account<br/>[user.entity.ts]"]
end

subgraph group_chat["Chat"]
  node_chat_api["Chat HTTP API<br/>[chat.controller.ts]"]
  node_chat_gateway["WebSocket Gateway<br/>[chat.gateway.ts]"]
  node_ws_guard["WebSocket Guard<br/>[ws.guard.ts]"]
  node_chat_service["Chat Service<br/>[chat.service.ts]"]
  node_conversation["Conversations"]
  node_message["Messages<br/>[message.entity.ts]"]
end

subgraph group_infra["Persistence and Messaging"]
  node_postgres[("PostgreSQL")]
  node_redis_service["Redis Pub/Sub Service<br/>[redis.service.ts]"]
  node_redis[("Redis")]
  node_jwt["JWT Service"]
end

node_client(("Client"))

node_client -->|"starts request"| node_main
node_main -->|"boots"| node_app
node_app -->|"configures"| node_postgres
node_client -->|"submits credentials"| node_auth_api
node_auth_api -->|"delegates"| node_auth_service
node_auth_service -->|"reads and writes"| node_user_entity
node_auth_service -->|"signs and verifies"| node_jwt
node_http_guard -->|"verifies tokens"| node_auth_service
node_client -->|"requests user data"| node_user_api
node_user_api -->|"delegates"| node_user_service
node_user_service -->|"queries and updates"| node_user_entity
node_client -->|"requests conversations"| node_chat_api
node_chat_api -->|"delegates"| node_chat_service
node_client -->|"opens socket"| node_chat_gateway
node_chat_gateway -->|"checks connection"| node_ws_guard
node_chat_gateway -->|"delegates chat operations"| node_chat_service
node_chat_service -->|"queries and saves"| node_conversation
node_chat_service -->|"queries and saves"| node_message
node_conversation -->|"relates messages"| node_message
node_redis_service -->|"publishes and subscribes"| node_redis

click node_main "https://github.com/punkuz/whatsapp-backend/blob/main/src/main.ts"
click node_app "https://github.com/punkuz/whatsapp-backend/blob/main/src/app.module.ts"
click node_auth_api "https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/auth.controller.ts"
click node_auth_service "https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/auth.service.ts"
click node_http_guard "https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/guards/http.guard.ts"
click node_user_api "https://github.com/punkuz/whatsapp-backend/blob/main/src/user/user.controller.ts"
click node_user_service "https://github.com/punkuz/whatsapp-backend/blob/main/src/user/user.service.ts"
click node_user_entity "https://github.com/punkuz/whatsapp-backend/blob/main/src/user/entities/user.entity.ts"
click node_chat_api "https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.controller.ts"
click node_chat_gateway "https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.gateway.ts"
click node_ws_guard "https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/guards/ws.guard.ts"
click node_chat_service "https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.service.ts"
click node_conversation "https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/entities/conversation.entity.ts"
click node_message "https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/entities/message.entity.ts"
click node_redis_service "https://github.com/punkuz/whatsapp-backend/blob/main/src/redis/redis.service.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_main,node_app,node_client toneBlue
class node_auth_api,node_auth_service,node_http_guard,node_user_api,node_user_service,node_user_entity toneAmber
class node_chat_api,node_chat_gateway,node_ws_guard,node_chat_service,node_conversation,node_message toneMint
class node_postgres,node_redis_service,node_redis,node_jwt toneRose
```

## Components

### Application Runtime

- [Nest Bootstrap](https://github.com/punkuz/whatsapp-backend/blob/main/src/main.ts): `src/main.ts`
- [Application Modules](https://github.com/punkuz/whatsapp-backend/blob/main/src/app.module.ts): `src/app.module.ts`

### Accounts and Authentication

- [Auth HTTP API](https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/auth.controller.ts): `src/auth/auth.controller.ts`
- [Auth Service](https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/auth.service.ts): `src/auth/auth.service.ts`
- [HTTP Guard](https://github.com/punkuz/whatsapp-backend/blob/main/src/auth/guards/http.guard.ts): `src/auth/guards/http.guard.ts`
- [User HTTP API](https://github.com/punkuz/whatsapp-backend/blob/main/src/user/user.controller.ts): `src/user/user.controller.ts`
- [User Service](https://github.com/punkuz/whatsapp-backend/blob/main/src/user/user.service.ts): `src/user/user.service.ts`
- [User Account](https://github.com/punkuz/whatsapp-backend/blob/main/src/user/entities/user.entity.ts): `src/user/entities/user.entity.ts`

### Chat

- [Chat HTTP API](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.controller.ts): `src/chat/chat.controller.ts`
- [WebSocket Gateway](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.gateway.ts): `src/chat/chat.gateway.ts`
- [WebSocket Guard](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/guards/ws.guard.ts): `src/chat/guards/ws.guard.ts`
- [Chat Service](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/chat.service.ts): `src/chat/chat.service.ts`
- [Conversations](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/entities/conversation.entity.ts): `src/chat/entities/conversation.entity.ts`
- [Messages](https://github.com/punkuz/whatsapp-backend/blob/main/src/chat/entities/message.entity.ts): `src/chat/entities/message.entity.ts`

### Persistence and Messaging

- **PostgreSQL**
- [Redis Pub/Sub Service](https://github.com/punkuz/whatsapp-backend/blob/main/src/redis/redis.service.ts): `src/redis/redis.service.ts`
- **Redis**
- **JWT Service**

### Other components

- **Client**

## Connections

- Client → Nest Bootstrap: starts request
- Nest Bootstrap → Application Modules: boots (evidence: `src/main.ts`)
- Application Modules → PostgreSQL: configures (evidence: `src/app.module.ts`)
- Client → Auth HTTP API: submits credentials
- Auth HTTP API → Auth Service: delegates (evidence: `src/auth/auth.controller.ts`)
- Auth Service → User Account: reads and writes (evidence: `src/auth/auth.service.ts`)
- Auth Service → JWT Service: signs and verifies (evidence: `src/auth/auth.service.ts`)
- HTTP Guard → Auth Service: verifies tokens (evidence: `src/auth/guards/http.guard.ts`)
- Client → User HTTP API: requests user data
- User HTTP API → User Service: delegates (evidence: `src/user/user.controller.ts`)
- User Service → User Account: queries and updates (evidence: `src/user/user.service.ts`)
- Client → Chat HTTP API: requests conversations
- Chat HTTP API → Chat Service: delegates (evidence: `src/chat/chat.controller.ts`)
- Client → WebSocket Gateway: opens socket
- WebSocket Gateway → WebSocket Guard: checks connection (evidence: `src/chat/chat.gateway.ts`)
- WebSocket Gateway → Chat Service: delegates chat operations (evidence: `src/chat/chat.gateway.ts`)
- Chat Service → Conversations: queries and saves (evidence: `src/chat/chat.service.ts`)
- Chat Service → Messages: queries and saves (evidence: `src/chat/chat.service.ts`)
- Conversations → Messages: relates messages (evidence: `src/chat/entities/conversation.entity.ts`)
- Redis Pub/Sub Service → Redis: publishes and subscribes (evidence: `src/redis/redis.service.ts`)
