# mshchebetiuk/chatspace architecture

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

- Interactive diagram: https://gitdiagram.com/mshchebetiuk/chatspace
- Repository: https://github.com/mshchebetiuk/chatspace

## Overview

ChatSpace is a chat API. Clients register or log in, then use a bearer token to access private conversations, create or list conversations, mark them read, and send, page through, edit, or delete messages. The implementation separates HTTP routing, authentication and validation, conversation orchestration, and persistence through Prisma. The excerpts show direct route and service calls and database operations; the message service is substantial but its caller is not established by the supplied evidence, so it is shown without an inferred connection.

Main entry points: [`server/src/routes/auth.routes.ts`](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/auth.routes.ts) (Auth endpoints), [`server/src/app.ts`](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/app.ts) (Express app), [`server/src/config/prisma.ts`](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/config/prisma.ts) (Prisma client), [`server/src/routes/message.routes.ts`](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/message.routes.ts) (Message endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_server["Server startup<br/>[server.ts]"]
  node_app["Express app<br/>[app.ts]"]
  node_error["Error responses<br/>[errorHandler.ts]"]
  node_api_types["API response types<br/>[api.types.ts]"]
end

subgraph group_identity["Identity and validation"]
  node_auth_routes["Auth endpoints<br/>[auth.routes.ts]"]
  node_auth_schema["Auth validation<br/>[auth.schema.ts]"]
  node_rate_limit["Login rate limit"]
  node_jwt_middleware["Bearer authentication<br/>[auth.middleware.ts]"]
  node_jwt["JWT signing<br/>[jwt.ts]"]
end

subgraph group_chat["Conversation and messaging"]
  node_conversation_routes["Conversation endpoints"]
  node_conversation_controller["Conversation handlers"]
  node_conversation_schema["Conversation validation"]
  node_conversation_service["Conversation operations"]
  node_message_routes["Message endpoints<br/>[message.routes.ts]"]
  node_message_schema["Message validation<br/>[message.schema.ts]"]
  node_message_service["Message service<br/>[message.service.ts]"]
end

subgraph group_persistence["Persistence"]
  node_prisma["Prisma client<br/>[prisma.ts]"]
  node_database[("PostgreSQL data<br/>[schema.prisma]")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_server -->|"starts listener"| node_app
node_server -->|"checks connection"| node_prisma
node_app -->|"mounts auth"| node_auth_routes
node_app -->|"mounts conversations"| node_conversation_routes
node_app -->|"handles errors"| node_error
node_auth_routes -->|"validates input"| node_auth_schema
node_auth_routes -->|"limits login"| node_rate_limit
node_auth_routes -->|"signs token"| node_jwt
node_auth_routes -->|"guards profile"| node_jwt_middleware
node_jwt_middleware -->|"verifies token"| node_jwt
node_auth_routes -->|"reads and writes users"| node_prisma
node_conversation_routes -->|"guards routes"| node_jwt_middleware
node_conversation_routes -->|"dispatches handlers"| node_conversation_controller
node_conversation_routes -->|"mounts messages"| node_message_routes
node_conversation_controller -->|"validates input"| node_conversation_schema
node_conversation_controller -->|"calls operations"| node_conversation_service
node_conversation_service -->|"queries chat data"| node_prisma
node_message_routes -->|"guards messages"| node_jwt_middleware
node_message_routes -->|"validates input"| node_message_schema
node_message_routes -->|"reads and writes messages"| node_prisma
node_message_service -->|"uses client"| node_prisma
node_prisma -.->|"persists data"| node_database
node_app -->|"formats responses"| node_api_types
node_error -->|"formats responses"| node_api_types
node_auth_routes -->|"formats responses"| node_api_types
node_conversation_controller -->|"formats responses"| node_api_types
node_message_routes -->|"formats responses"| node_api_types

click node_server "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/server.ts"
click node_app "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/app.ts"
click node_error "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/middlewares/errorHandler.ts"
click node_api_types "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/types/api.types.ts"
click node_auth_routes "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/auth.routes.ts"
click node_auth_schema "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/validators/auth.schema.ts"
click node_rate_limit "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/middlewares/login-rate-limit.middleware.ts"
click node_jwt_middleware "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/middlewares/auth.middleware.ts"
click node_jwt "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/config/jwt.ts"
click node_conversation_routes "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/conversation.routes.ts"
click node_conversation_controller "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/controllers/conversation.controller.ts"
click node_conversation_schema "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/validators/conversation.schema.ts"
click node_conversation_service "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/services/conversation.service.ts"
click node_message_routes "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/message.routes.ts"
click node_message_schema "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/validators/message.schema.ts"
click node_message_service "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/services/message.service.ts"
click node_prisma "https://github.com/mshchebetiuk/chatspace/blob/main/server/src/config/prisma.ts"
click node_database "https://github.com/mshchebetiuk/chatspace/blob/main/server/prisma/schema.prisma"

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_server,node_app,node_error,node_api_types,node_client toneBlue
class node_auth_routes,node_auth_schema,node_rate_limit,node_jwt_middleware,node_jwt toneAmber
class node_conversation_routes,node_conversation_controller,node_conversation_schema,node_conversation_service,node_message_routes,node_message_schema,node_message_service toneMint
class node_prisma,node_database toneRose
```

## Components

### API entry

- [Server startup](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/server.ts): `server/src/server.ts`
- [Express app](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/app.ts): `server/src/app.ts`
- [Error responses](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/middlewares/errorHandler.ts): `server/src/middlewares/errorHandler.ts`
- [API response types](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/types/api.types.ts): `server/src/types/api.types.ts`

### Identity and validation

- [Auth endpoints](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/auth.routes.ts): `server/src/routes/auth.routes.ts`
- [Auth validation](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/validators/auth.schema.ts): `server/src/validators/auth.schema.ts`
- [Login rate limit](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/middlewares/login-rate-limit.middleware.ts): `server/src/middlewares/login-rate-limit.middleware.ts`
- [Bearer authentication](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/middlewares/auth.middleware.ts): `server/src/middlewares/auth.middleware.ts`
- [JWT signing](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/config/jwt.ts): `server/src/config/jwt.ts`

### Conversation and messaging

- [Conversation endpoints](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/conversation.routes.ts): `server/src/routes/conversation.routes.ts`
- [Conversation handlers](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/controllers/conversation.controller.ts): `server/src/controllers/conversation.controller.ts`
- [Conversation validation](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/validators/conversation.schema.ts): `server/src/validators/conversation.schema.ts`
- [Conversation operations](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/services/conversation.service.ts): `server/src/services/conversation.service.ts`
- [Message endpoints](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/routes/message.routes.ts): `server/src/routes/message.routes.ts`
- [Message validation](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/validators/message.schema.ts): `server/src/validators/message.schema.ts`
- [Message service](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/services/message.service.ts): `server/src/services/message.service.ts`

### Persistence

- [Prisma client](https://github.com/mshchebetiuk/chatspace/blob/main/server/src/config/prisma.ts): `server/src/config/prisma.ts`
- [PostgreSQL data](https://github.com/mshchebetiuk/chatspace/blob/main/server/prisma/schema.prisma): `server/prisma/schema.prisma`

### Other components

- **API client**

## Connections

- API client → Express app: sends requests (evidence: `server/src/app.ts`)
- Server startup → Express app: starts listener (evidence: `server/src/server.ts`)
- Server startup → Prisma client: checks connection (evidence: `server/src/server.ts`)
- Express app → Auth endpoints: mounts auth (evidence: `server/src/app.ts`)
- Express app → Conversation endpoints: mounts conversations (evidence: `server/src/app.ts`)
- Express app → Error responses: handles errors (evidence: `server/src/app.ts`)
- Auth endpoints → Auth validation: validates input (evidence: `server/src/routes/auth.routes.ts`)
- Auth endpoints → Login rate limit: limits login (evidence: `server/src/routes/auth.routes.ts`)
- Auth endpoints → JWT signing: signs token (evidence: `server/src/routes/auth.routes.ts`)
- Auth endpoints → Bearer authentication: guards profile (evidence: `server/src/routes/auth.routes.ts`)
- Bearer authentication → JWT signing: verifies token (evidence: `server/src/middlewares/auth.middleware.ts`)
- Auth endpoints → Prisma client: reads and writes users (evidence: `server/src/routes/auth.routes.ts`)
- Conversation endpoints → Bearer authentication: guards routes (evidence: `server/src/routes/conversation.routes.ts`)
- Conversation endpoints → Conversation handlers: dispatches handlers (evidence: `server/src/routes/conversation.routes.ts`)
- Conversation endpoints → Message endpoints: mounts messages (evidence: `server/src/routes/conversation.routes.ts`)
- Conversation handlers → Conversation validation: validates input (evidence: `server/src/controllers/conversation.controller.ts`)
- Conversation handlers → Conversation operations: calls operations (evidence: `server/src/controllers/conversation.controller.ts`)
- Conversation operations → Prisma client: queries chat data (evidence: `server/src/services/conversation.service.ts`)
- Message endpoints → Bearer authentication: guards messages (evidence: `server/src/routes/message.routes.ts`)
- Message endpoints → Message validation: validates input (evidence: `server/src/routes/message.routes.ts`)
- Message endpoints → Prisma client: reads and writes messages (evidence: `server/src/routes/message.routes.ts`)
- Message service → Prisma client: uses client (evidence: `server/src/services/message.service.ts`)
- Prisma client → PostgreSQL data: persists data
- Express app → API response types: formats responses (evidence: `server/src/app.ts`)
- Error responses → API response types: formats responses (evidence: `server/src/middlewares/errorHandler.ts`)
- Auth endpoints → API response types: formats responses (evidence: `server/src/routes/auth.routes.ts`)
- Conversation handlers → API response types: formats responses (evidence: `server/src/controllers/conversation.controller.ts`)
- Message endpoints → API response types: formats responses (evidence: `server/src/routes/message.routes.ts`)
