# smkh4x/chatbit-app-full-stack architecture

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

- Interactive diagram: https://gitdiagram.com/smkh4x/chatbit-app-full-stack
- Repository: https://github.com/smkh4x/chatbit-app-full-stack

## Overview

ChatBit is a customer-support chat app: clients register or log in, create conversations, and exchange messages with support agents; agents can claim and close conversations. The mobile app restores JWT sessions, uses REST for account and conversation operations, and Socket.IO for live chat, typing, and presence. The backend separates routes, controllers, authentication/business logic, persistence, and realtime handling. Some mobile and backend capabilities are documented but their implementation files were not excerpted, so those subsystem links are shown as documented rather than inferred from unseen calls.

Main entry points: [`backend/sockets/index.js`](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/sockets/index.js) (Socket server), [`backend/controllers/conversation.controller.js`](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/conversation.controller.js) (Conversation handlers), [`backend/app.js`](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/app.js) (Express API), [`mobile/src/app/(app)/chat.tsx`](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/app/(app)/chat.tsx) (Chat screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile app"]
  node_screens["App screens"]
  node_home["Conversation home<br/>[home.tsx]"]
  node_chat["Chat screen<br/>[chat.tsx]"]
  node_rest_client["REST client<br/>[api.ts]"]
  node_conversation_hook["Conversation queries<br/>[useConversation.ts]"]
  node_message_hook["Message queries<br/>[useMessages.ts]"]
end

subgraph group_backend_api["Backend API"]
  node_api_app["Express API<br/>[app.js]"]
  node_conversation_routes["Conversation routes"]
  node_conversation_controller["Conversation handlers"]
  node_server["HTTP bootstrap<br/>[server.js]"]
end

subgraph group_realtime["Realtime chat"]
  node_socket_client["Socket client<br/>[socket.ts]"]
  node_socket_server["Socket server<br/>[index.js]"]
end

subgraph group_identity["Identity"]
  node_session[("Session store<br/>[auth.ts]")]
  node_auth_routes["Auth routes<br/>[auth.routes.js]"]
  node_user_routes["User routes<br/>[user.routes.js]"]
  node_auth_controller["Auth handlers<br/>[auth.controller.js]"]
  node_user_controller["User handler<br/>[user.controller.js]"]
  node_auth_service["Auth service<br/>[auth.service.js]"]
  node_auth_middleware["JWT middleware<br/>[auth.middleware.js]"]
end

subgraph group_data["Persistence"]
  node_database_config["PostgreSQL connection<br/>[database.js]"]
  node_users[("Users<br/>[user.model.js]")]
  node_conversations[("Conversations")]
  node_messages[("Messages<br/>[message.model.js]")]
end

node_client(("Client or agent"))
node_postgres[("PostgreSQL")]

node_client -->|"uses"| node_screens
node_screens -->|"restores session"| node_session
node_screens -->|"calls REST"| node_rest_client
node_home -->|"queries"| node_conversation_hook
node_conversation_hook -->|"requests data"| node_rest_client
node_chat -->|"loads history"| node_message_hook
node_message_hook -->|"requests history"| node_rest_client
node_chat -->|"sends live events"| node_socket_client
node_rest_client -->|"calls API"| node_api_app
node_socket_client -->|"connects"| node_socket_server
node_api_app -->|"mounts"| node_auth_routes
node_api_app -->|"mounts"| node_user_routes
node_api_app -->|"mounts"| node_conversation_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_conversation_routes -->|"authenticates"| node_auth_middleware
node_conversation_routes -->|"dispatches"| node_conversation_controller
node_user_routes -->|"authenticates"| node_auth_middleware
node_user_routes -->|"dispatches"| node_user_controller
node_auth_controller -->|"delegates"| node_auth_service
node_auth_service -->|"reads and creates"| node_users
node_auth_middleware -->|"loads user"| node_users
node_auth_middleware -->|"validates session"| node_session
node_conversation_controller -->|"reads and updates"| node_conversations
node_conversation_controller -->|"loads history"| node_messages
node_socket_server -->|"authenticates and tracks presence"| node_users
node_socket_server -->|"checks access and status"| node_conversations
node_socket_server -->|"persists messages"| node_messages
node_server -->|"serves"| node_api_app
node_server -->|"creates"| node_socket_server
node_database_config -->|"connects"| node_postgres
node_users -->|"defines model on"| node_database_config
node_conversations -->|"defines model on"| node_database_config
node_messages -.->|"defines model on"| node_database_config
node_socket_server -->|"broadcasts messages, typing, presence"| node_chat
node_conversation_controller -->|"serves create and list"| node_home
node_conversation_controller -->|"serves history and status actions"| node_chat

click node_screens "https://github.com/smkh4x/chatbit-app-full-stack/tree/main/mobile/src/app"
click node_home "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/app/(app)/home.tsx"
click node_chat "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/app/(app)/chat.tsx"
click node_session "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/store/auth.ts"
click node_rest_client "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/services/api.ts"
click node_socket_client "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/services/socket.ts"
click node_conversation_hook "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/hooks/useConversation.ts"
click node_message_hook "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/hooks/useMessages.ts"
click node_api_app "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/app.js"
click node_auth_routes "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/routes/auth.routes.js"
click node_conversation_routes "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/routes/conversation.routes.js"
click node_user_routes "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/routes/user.routes.js"
click node_auth_controller "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/auth.controller.js"
click node_conversation_controller "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/conversation.controller.js"
click node_user_controller "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/user.controller.js"
click node_auth_service "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/services/auth.service.js"
click node_auth_middleware "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/middlewares/auth.middleware.js"
click node_socket_server "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/sockets/index.js"
click node_server "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/server.js"
click node_database_config "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/config/database.js"
click node_users "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/models/user.model.js"
click node_conversations "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/models/conversation.model.js"
click node_messages "https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/models/message.model.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_screens,node_home,node_chat,node_rest_client,node_conversation_hook,node_message_hook,node_client toneBlue
class node_api_app,node_conversation_routes,node_conversation_controller,node_server,node_postgres toneAmber
class node_socket_client,node_socket_server toneMint
class node_session,node_auth_routes,node_user_routes,node_auth_controller,node_user_controller,node_auth_service,node_auth_middleware toneRose
class node_database_config,node_users,node_conversations,node_messages toneIndigo
```

## Components

### Mobile app

- [App screens](https://github.com/smkh4x/chatbit-app-full-stack/tree/main/mobile/src/app): `mobile/src/app`
- [Conversation home](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/app/(app)/home.tsx): `mobile/src/app/(app)/home.tsx`
- [Chat screen](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/app/(app)/chat.tsx): `mobile/src/app/(app)/chat.tsx`
- [REST client](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/services/api.ts): `mobile/src/services/api.ts`
- [Conversation queries](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/hooks/useConversation.ts): `mobile/src/hooks/useConversation.ts`
- [Message queries](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/hooks/useMessages.ts): `mobile/src/hooks/useMessages.ts`

### Backend API

- [Express API](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/app.js): `backend/app.js`
- [Conversation routes](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/routes/conversation.routes.js): `backend/routes/conversation.routes.js`
- [Conversation handlers](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/conversation.controller.js): `backend/controllers/conversation.controller.js`
- [HTTP bootstrap](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/server.js): `backend/server.js`

### Realtime chat

- [Socket client](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/services/socket.ts): `mobile/src/services/socket.ts`
- [Socket server](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/sockets/index.js): `backend/sockets/index.js`

### Identity

- [Session store](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/mobile/src/store/auth.ts): `mobile/src/store/auth.ts`
- [Auth routes](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/routes/auth.routes.js): `backend/routes/auth.routes.js`
- [User routes](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/routes/user.routes.js): `backend/routes/user.routes.js`
- [Auth handlers](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/auth.controller.js): `backend/controllers/auth.controller.js`
- [User handler](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/controllers/user.controller.js): `backend/controllers/user.controller.js`
- [Auth service](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/services/auth.service.js): `backend/services/auth.service.js`
- [JWT middleware](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/middlewares/auth.middleware.js): `backend/middlewares/auth.middleware.js`

### Persistence

- [PostgreSQL connection](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/config/database.js): `backend/config/database.js`
- [Users](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/models/user.model.js): `backend/models/user.model.js`
- [Conversations](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/models/conversation.model.js): `backend/models/conversation.model.js`
- [Messages](https://github.com/smkh4x/chatbit-app-full-stack/blob/main/backend/models/message.model.js): `backend/models/message.model.js`

### Other components

- **Client or agent**
- **PostgreSQL**

## Connections

- Client or agent → App screens: uses
- App screens → Session store: restores session (evidence: `mobile/src/app/index.tsx`)
- App screens → REST client: calls REST (evidence: `mobile/src/app/(app)/home.tsx`)
- Conversation home → Conversation queries: queries (evidence: `mobile/src/app/(app)/home.tsx`)
- Conversation queries → REST client: requests data (evidence: `mobile/src/hooks/useConversation.ts`)
- Chat screen → Message queries: loads history (evidence: `mobile/src/app/(app)/chat.tsx`)
- Message queries → REST client: requests history (evidence: `mobile/src/hooks/useMessages.ts`)
- Chat screen → Socket client: sends live events (evidence: `mobile/src/app/(app)/chat.tsx`)
- REST client → Express API: calls API
- Socket client → Socket server: connects
- Express API → Auth routes: mounts (evidence: `backend/app.js`)
- Express API → User routes: mounts (evidence: `backend/app.js`)
- Express API → Conversation routes: mounts (evidence: `backend/app.js`)
- Auth routes → Auth handlers: dispatches (evidence: `backend/routes/auth.routes.js`)
- Conversation routes → JWT middleware: authenticates (evidence: `backend/routes/conversation.routes.js`)
- Conversation routes → Conversation handlers: dispatches (evidence: `backend/routes/conversation.routes.js`)
- User routes → JWT middleware: authenticates (evidence: `backend/routes/user.routes.js`)
- User routes → User handler: dispatches (evidence: `backend/routes/user.routes.js`)
- Auth handlers → Auth service: delegates (evidence: `backend/controllers/auth.controller.js`)
- Auth service → Users: reads and creates (evidence: `backend/services/auth.service.js`)
- JWT middleware → Users: loads user (evidence: `backend/middlewares/auth.middleware.js`)
- JWT middleware → Session store: validates session
- Conversation handlers → Conversations: reads and updates (evidence: `backend/controllers/conversation.controller.js`)
- Conversation handlers → Messages: loads history (evidence: `backend/controllers/conversation.controller.js`)
- Socket server → Users: authenticates and tracks presence (evidence: `backend/sockets/index.js`)
- Socket server → Conversations: checks access and status (evidence: `backend/sockets/index.js`)
- Socket server → Messages: persists messages (evidence: `backend/sockets/index.js`)
- HTTP bootstrap → Express API: serves (evidence: `backend/server.js`)
- HTTP bootstrap → Socket server: creates (evidence: `backend/server.js`)
- PostgreSQL connection → PostgreSQL: connects (evidence: `backend/config/database.js`)
- Users → PostgreSQL connection: defines model on (evidence: `backend/models/user.model.js`)
- Conversations → PostgreSQL connection: defines model on (evidence: `backend/models/conversation.model.js`)
- Messages → PostgreSQL connection: defines model on (evidence: `backend/models/message.model.js`)
- Socket server → Chat screen: broadcasts messages, typing, presence
- Conversation handlers → Conversation home: serves create and list
- Conversation handlers → Chat screen: serves history and status actions
