# rudreshp18/just-chat architecture

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

- Interactive diagram: https://gitdiagram.com/rudreshp18/just-chat
- Repository: https://github.com/rudreshp18/just-chat

## Overview

This repository implements a chat backend with account registration, email verification and login; authenticated friend and conversation APIs; and WebSocket messaging with online-user updates. API handlers and the WebSocket server access user, message and group records through Mongoose models. The shown WebSocket handler persists direct messages and sends them to connected recipients; group creation and conversation retrieval are exposed through the chat API. Both index.js and websocket.js contain server implementations. Evidence is limited to the supplied excerpts and source index; unsampled behavior is not inferred.

Main entry points: [`index.js`](https://github.com/rudreshp18/just-chat/blob/master/index.js) (HTTP Server), [`websocket.js`](https://github.com/rudreshp18/just-chat/blob/master/websocket.js) (WebSocket Server), [`models/userSchema.js`](https://github.com/rudreshp18/just-chat/blob/master/models/userSchema.js) (User Records), [`controllers/chatControllers.js`](https://github.com/rudreshp18/just-chat/blob/master/controllers/chatControllers.js) (Chat Handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_account["Accounts"]
  node_auth_routes["Auth Routes<br/>[authRoutes.js]"]
  node_auth_controller["Account Handler<br/>[authController.js]"]
  node_verify_middleware["JWT Middleware<br/>[verify.js]"]
end

subgraph group_api["Chat API"]
  node_chat_routes["Chat Routes<br/>[chatRoutes.js]"]
  node_chat_controller["Chat Handler<br/>[chatControllers.js]"]
  node_user_controller["User Listing<br/>[userControllers.js]"]
  node_http_server["HTTP Server<br/>[index.js]"]
end

subgraph group_realtime["Realtime Chat"]
  node_websocket_server["WebSocket Server<br/>[websocket.js]"]
  node_index_ws["Integrated WebSocket<br/>[index.js]"]
end

subgraph group_data["Data Models"]
  node_db_connector["Database Connector<br/>[dbConnection.js]"]
  node_user_model[("User Records<br/>[userSchema.js]")]
  node_message_model[("Message Records<br/>[messageSchema.js]")]
  node_group_model[("Group Records<br/>[groupSchema.js]")]
end

node_client(("Chat Client"))
node_email["Email Provider"]
node_mongo[("MongoDB")]

node_client -->|"HTTP requests"| node_http_server
node_http_server -->|"mounts auth"| node_auth_routes
node_http_server -->|"mounts chat"| node_chat_routes
node_http_server -->|"guards routes"| node_verify_middleware
node_http_server -->|"routes users"| node_user_controller
node_auth_routes -->|"dispatches"| node_auth_controller
node_chat_routes -->|"dispatches"| node_chat_controller
node_auth_controller -->|"reads and saves"| node_user_model
node_auth_controller -->|"sends verification"| node_email
node_verify_middleware -->|"loads user"| node_user_model
node_user_controller -->|"lists users"| node_user_model
node_chat_controller -->|"reads and updates"| node_user_model
node_chat_controller -->|"queries conversations"| node_message_model
node_chat_controller -->|"creates and reads zones"| node_group_model
node_client -->|"opens connection"| node_websocket_server
node_websocket_server -->|"authenticates and updates"| node_user_model
node_websocket_server -->|"saves messages"| node_message_model
node_websocket_server -->|"reads groups"| node_group_model
node_client -->|"opens connection"| node_index_ws
node_index_ws -->|"authenticates and updates"| node_user_model
node_index_ws -->|"saves messages"| node_message_model
node_index_ws -->|"reads groups"| node_group_model
node_websocket_server -->|"sends chat and lists"| node_client
node_index_ws -->|"sends chat and lists"| node_client
node_websocket_server -->|"initializes database"| node_db_connector
node_http_server -->|"imports connector"| node_db_connector
node_db_connector -->|"connects"| node_mongo

click node_auth_routes "https://github.com/rudreshp18/just-chat/blob/master/routes/authRoutes.js"
click node_auth_controller "https://github.com/rudreshp18/just-chat/blob/master/controllers/authController.js"
click node_verify_middleware "https://github.com/rudreshp18/just-chat/blob/master/controllers/verify.js"
click node_chat_routes "https://github.com/rudreshp18/just-chat/blob/master/routes/chatRoutes.js"
click node_chat_controller "https://github.com/rudreshp18/just-chat/blob/master/controllers/chatControllers.js"
click node_user_controller "https://github.com/rudreshp18/just-chat/blob/master/controllers/userControllers.js"
click node_http_server "https://github.com/rudreshp18/just-chat/blob/master/index.js"
click node_websocket_server "https://github.com/rudreshp18/just-chat/blob/master/websocket.js"
click node_index_ws "https://github.com/rudreshp18/just-chat/blob/master/index.js"
click node_db_connector "https://github.com/rudreshp18/just-chat/blob/master/dbConnection.js"
click node_user_model "https://github.com/rudreshp18/just-chat/blob/master/models/userSchema.js"
click node_message_model "https://github.com/rudreshp18/just-chat/blob/master/models/messageSchema.js"
click node_group_model "https://github.com/rudreshp18/just-chat/blob/master/models/groupSchema.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_auth_routes,node_auth_controller,node_verify_middleware,node_client toneBlue
class node_chat_routes,node_chat_controller,node_user_controller,node_http_server,node_mongo toneAmber
class node_websocket_server,node_index_ws toneMint
class node_db_connector,node_user_model,node_message_model,node_group_model toneRose
class node_email toneIndigo
```

## Components

### Accounts

- [Auth Routes](https://github.com/rudreshp18/just-chat/blob/master/routes/authRoutes.js): `routes/authRoutes.js`
- [Account Handler](https://github.com/rudreshp18/just-chat/blob/master/controllers/authController.js): `controllers/authController.js`
- [JWT Middleware](https://github.com/rudreshp18/just-chat/blob/master/controllers/verify.js): `controllers/verify.js`

### Chat API

- [Chat Routes](https://github.com/rudreshp18/just-chat/blob/master/routes/chatRoutes.js): `routes/chatRoutes.js`
- [Chat Handler](https://github.com/rudreshp18/just-chat/blob/master/controllers/chatControllers.js): `controllers/chatControllers.js`
- [User Listing](https://github.com/rudreshp18/just-chat/blob/master/controllers/userControllers.js): `controllers/userControllers.js`
- [HTTP Server](https://github.com/rudreshp18/just-chat/blob/master/index.js): `index.js`

### Realtime Chat

- [WebSocket Server](https://github.com/rudreshp18/just-chat/blob/master/websocket.js): `websocket.js`
- [Integrated WebSocket](https://github.com/rudreshp18/just-chat/blob/master/index.js): `index.js`

### Data Models

- [Database Connector](https://github.com/rudreshp18/just-chat/blob/master/dbConnection.js): `dbConnection.js`
- [User Records](https://github.com/rudreshp18/just-chat/blob/master/models/userSchema.js): `models/userSchema.js`
- [Message Records](https://github.com/rudreshp18/just-chat/blob/master/models/messageSchema.js): `models/messageSchema.js`
- [Group Records](https://github.com/rudreshp18/just-chat/blob/master/models/groupSchema.js): `models/groupSchema.js`

### Other components

- **Chat Client**
- **Email Provider**
- **MongoDB**

## Connections

- Chat Client → HTTP Server: HTTP requests (evidence: `index.js`)
- HTTP Server → Auth Routes: mounts auth (evidence: `index.js`)
- HTTP Server → Chat Routes: mounts chat (evidence: `index.js`)
- HTTP Server → JWT Middleware: guards routes (evidence: `index.js`)
- HTTP Server → User Listing: routes users (evidence: `index.js`)
- Auth Routes → Account Handler: dispatches (evidence: `routes/authRoutes.js`)
- Chat Routes → Chat Handler: dispatches (evidence: `routes/chatRoutes.js`)
- Account Handler → User Records: reads and saves (evidence: `controllers/authController.js`)
- Account Handler → Email Provider: sends verification (evidence: `controllers/authController.js`)
- JWT Middleware → User Records: loads user (evidence: `controllers/verify.js`)
- User Listing → User Records: lists users (evidence: `controllers/userControllers.js`)
- Chat Handler → User Records: reads and updates (evidence: `controllers/chatControllers.js`)
- Chat Handler → Message Records: queries conversations (evidence: `controllers/chatControllers.js`)
- Chat Handler → Group Records: creates and reads zones (evidence: `controllers/chatControllers.js`)
- Chat Client → WebSocket Server: opens connection (evidence: `websocket.js`)
- WebSocket Server → User Records: authenticates and updates (evidence: `websocket.js`)
- WebSocket Server → Message Records: saves messages (evidence: `websocket.js`)
- WebSocket Server → Group Records: reads groups (evidence: `websocket.js`)
- Chat Client → Integrated WebSocket: opens connection (evidence: `index.js`)
- Integrated WebSocket → User Records: authenticates and updates (evidence: `index.js`)
- Integrated WebSocket → Message Records: saves messages (evidence: `index.js`)
- Integrated WebSocket → Group Records: reads groups (evidence: `index.js`)
- WebSocket Server → Chat Client: sends chat and lists (evidence: `websocket.js`)
- Integrated WebSocket → Chat Client: sends chat and lists (evidence: `index.js`)
- WebSocket Server → Database Connector: initializes database (evidence: `websocket.js`)
- HTTP Server → Database Connector: imports connector (evidence: `index.js`)
- Database Connector → MongoDB: connects (evidence: `dbConnection.js`)
