# baghdatyangurgen/teamchat architecture

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

- Interactive diagram: https://gitdiagram.com/baghdatyangurgen/teamchat
- Repository: https://github.com/baghdatyangurgen/teamchat

## Overview

TeamChat is a company-oriented chat application with REST APIs and SignalR realtime access. The principal workflow is a user creating or joining a company, opening an authorized chat, exchanging messages and attachments, and tracking reads; company structure and direct-message policy govern access. The application layer coordinates domain services and repository abstractions, while infrastructure supplies persistence, files, messaging, email, and token services. The tree and excerpts support the main API, chat, company, persistence, file, and notification boundaries; several integrations are shown only by their module paths, so uncertain links are omitted.

Main entry points: [`TeamChat/Program.cs`](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Program.cs) (REST API), [`TeamChat.Application/Services/ChatService.cs`](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/ChatService.cs) (Chat service), [`TeamChat/Controllers/ChatController.cs`](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/ChatController.cs) (Chat endpoints), [`TeamChat/Controllers/MessageController.cs`](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/MessageController.cs) (Message endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and realtime"]
  node_api["REST API<br/>[Program.cs]"]
  node_chat_api["Chat endpoints<br/>[ChatController.cs]"]
  node_message_api["Message endpoints"]
  node_company_api["Company endpoints"]
  node_user_api["User endpoints<br/>[UserController.cs]"]
  node_realtime["Chat hub<br/>[ChatHub.cs]"]
end

subgraph group_domain["Chat and company"]
  node_chat_service["Chat service<br/>[ChatService.cs]"]
  node_message_service["Message service<br/>[MessageService.cs]"]
  node_company_service["Company service<br/>[CompanyService.cs]"]
  node_user_service["User service<br/>[UserService.cs]"]
  node_dm_policy["DM policy"]
  node_hierarchy["Position hierarchy"]
end

subgraph group_data["Persistence"]
  node_chat_repo["Chat repository<br/>[ChatRepository.cs]"]
  node_message_repo["Message repository"]
  node_user_repo["User repository<br/>[UserRepository.cs]"]
  node_db[("Application database<br/>[AppDbContext.cs]")]
end

subgraph group_integration["Integrations"]
  node_file_api["File endpoints<br/>[FileController.cs]"]
  node_file_adapter["gRPC file adapter<br/>[FileService.cs]"]
  node_file_worker["File service<br/>[GrpcFileService.cs]"]
  node_publisher["RabbitMQ publisher"]
  node_notification["Notification worker<br/>[Worker.cs]"]
  node_listener["RabbitMQ listener"]
  node_email["SMTP email<br/>[SmtpEmailSender.cs]"]
end

subgraph group_identity["Identity and security"]
  node_tokens["Token services"]
  node_jwt["JWT service<br/>[JwtTokenService.cs]"]
end

node_user(("User"))

node_user -->|"sends requests"| node_api
node_api -->|"routes requests"| node_chat_api
node_api -->|"routes requests"| node_message_api
node_api -->|"routes requests"| node_company_api
node_api -->|"routes requests"| node_user_api
node_api -->|"maps hub"| node_realtime
node_chat_api -->|"calls"| node_chat_service
node_chat_api -->|"uses hub"| node_realtime
node_message_api -->|"calls"| node_message_service
node_message_api -->|"uses hub"| node_realtime
node_company_api -->|"calls"| node_company_service
node_company_api -->|"calls"| node_dm_policy
node_user_api -->|"calls"| node_user_service
node_chat_service -->|"queries chats"| node_chat_repo
node_chat_service -->|"queries messages"| node_message_repo
node_chat_service -->|"checks hierarchy"| node_hierarchy
node_company_service -->|"uploads logos"| node_file_adapter
node_chat_repo -->|"reads chats"| node_db
node_message_repo -->|"reads and writes"| node_db
node_user_repo -->|"queries users"| node_db
node_file_api -.->|"uses file service"| node_file_adapter
node_file_adapter -.->|"streams files"| node_file_worker
node_notification -->|"starts listener"| node_listener

click node_api "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Program.cs"
click node_chat_api "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/ChatController.cs"
click node_message_api "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/MessageController.cs"
click node_company_api "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/CompanyController.cs"
click node_user_api "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/UserController.cs"
click node_realtime "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Hubs/ChatHub.cs"
click node_chat_service "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/ChatService.cs"
click node_message_service "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/MessageService.cs"
click node_company_service "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/CompanyService.cs"
click node_user_service "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/UserService.cs"
click node_dm_policy "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/DirectMessagePolicyService.cs"
click node_hierarchy "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/PositionHierarchyService.cs"
click node_chat_repo "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/Repositories/ChatRepository.cs"
click node_message_repo "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/Repositories/MessageRepository.cs"
click node_user_repo "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/Repositories/UserRepository.cs"
click node_db "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/AppDbContext.cs"
click node_file_api "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/FileController.cs"
click node_file_adapter "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/File/FileService.cs"
click node_file_worker "https://github.com/baghdatyangurgen/teamchat/blob/master/FileService/Services/GrpcFileService.cs"
click node_publisher "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Messaging/RabbitMqPublisher.cs"
click node_notification "https://github.com/baghdatyangurgen/teamchat/blob/master/NotificationService/Services/Worker.cs"
click node_listener "https://github.com/baghdatyangurgen/teamchat/blob/master/NotificationService/Services/RabbitMqListener.cs"
click node_email "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Email/SmtpEmailSender.cs"
click node_tokens "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Security/RefreshToken/RefreshTokenService.cs"
click node_jwt "https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Security/Jwt/JwtTokenService.cs"

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_api,node_chat_api,node_message_api,node_company_api,node_user_api,node_realtime,node_user toneBlue
class node_chat_service,node_message_service,node_company_service,node_user_service,node_dm_policy,node_hierarchy toneAmber
class node_chat_repo,node_message_repo,node_user_repo,node_db toneMint
class node_file_api,node_file_adapter,node_file_worker,node_publisher,node_notification,node_listener,node_email toneRose
class node_tokens,node_jwt toneIndigo
```

## Components

### API and realtime

- [REST API](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Program.cs): `TeamChat/Program.cs`
- [Chat endpoints](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/ChatController.cs): `TeamChat/Controllers/ChatController.cs`
- [Message endpoints](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/MessageController.cs): `TeamChat/Controllers/MessageController.cs`
- [Company endpoints](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/CompanyController.cs): `TeamChat/Controllers/CompanyController.cs`
- [User endpoints](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/UserController.cs): `TeamChat/Controllers/UserController.cs`
- [Chat hub](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Hubs/ChatHub.cs): `TeamChat/Hubs/ChatHub.cs`

### Chat and company

- [Chat service](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/ChatService.cs): `TeamChat.Application/Services/ChatService.cs`
- [Message service](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/MessageService.cs): `TeamChat.Application/Services/MessageService.cs`
- [Company service](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/CompanyService.cs): `TeamChat.Application/Services/CompanyService.cs`
- [User service](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/UserService.cs): `TeamChat.Application/Services/UserService.cs`
- [DM policy](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/DirectMessagePolicyService.cs): `TeamChat.Application/Services/DirectMessagePolicyService.cs`
- [Position hierarchy](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Application/Services/PositionHierarchyService.cs): `TeamChat.Application/Services/PositionHierarchyService.cs`

### Persistence

- [Chat repository](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/Repositories/ChatRepository.cs): `TeamChat.Infrastructure/Persistance/Repositories/ChatRepository.cs`
- [Message repository](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/Repositories/MessageRepository.cs): `TeamChat.Infrastructure/Persistance/Repositories/MessageRepository.cs`
- [User repository](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/Repositories/UserRepository.cs): `TeamChat.Infrastructure/Persistance/Repositories/UserRepository.cs`
- [Application database](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Persistance/AppDbContext.cs): `TeamChat.Infrastructure/Persistance/AppDbContext.cs`

### Integrations

- [File endpoints](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat/Controllers/FileController.cs): `TeamChat/Controllers/FileController.cs`
- [gRPC file adapter](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/File/FileService.cs): `TeamChat.Infrastructure/File/FileService.cs`
- [File service](https://github.com/baghdatyangurgen/teamchat/blob/master/FileService/Services/GrpcFileService.cs): `FileService/Services/GrpcFileService.cs`
- [RabbitMQ publisher](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Messaging/RabbitMqPublisher.cs): `TeamChat.Infrastructure/Messaging/RabbitMqPublisher.cs`
- [Notification worker](https://github.com/baghdatyangurgen/teamchat/blob/master/NotificationService/Services/Worker.cs): `NotificationService/Services/Worker.cs`
- [RabbitMQ listener](https://github.com/baghdatyangurgen/teamchat/blob/master/NotificationService/Services/RabbitMqListener.cs): `NotificationService/Services/RabbitMqListener.cs`
- [SMTP email](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Email/SmtpEmailSender.cs): `TeamChat.Infrastructure/Email/SmtpEmailSender.cs`

### Identity and security

- [Token services](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Security/RefreshToken/RefreshTokenService.cs): `TeamChat.Infrastructure/Security/RefreshToken/RefreshTokenService.cs`
- [JWT service](https://github.com/baghdatyangurgen/teamchat/blob/master/TeamChat.Infrastructure/Security/Jwt/JwtTokenService.cs): `TeamChat.Infrastructure/Security/Jwt/JwtTokenService.cs`

### Other components

- **User**

## Connections

- User → REST API: sends requests (evidence: `TeamChat/Program.cs`)
- REST API → Chat endpoints: routes requests (evidence: `TeamChat/Program.cs`)
- REST API → Message endpoints: routes requests (evidence: `TeamChat/Program.cs`)
- REST API → Company endpoints: routes requests (evidence: `TeamChat/Program.cs`)
- REST API → User endpoints: routes requests (evidence: `TeamChat/Program.cs`)
- REST API → Chat hub: maps hub (evidence: `TeamChat/Program.cs`)
- Chat endpoints → Chat service: calls (evidence: `TeamChat/Controllers/ChatController.cs`)
- Chat endpoints → Chat hub: uses hub (evidence: `TeamChat/Controllers/ChatController.cs`)
- Message endpoints → Message service: calls (evidence: `TeamChat/Controllers/MessageController.cs`)
- Message endpoints → Chat hub: uses hub (evidence: `TeamChat/Controllers/MessageController.cs`)
- Company endpoints → Company service: calls (evidence: `TeamChat/Controllers/CompanyController.cs`)
- Company endpoints → DM policy: calls (evidence: `TeamChat/Controllers/CompanyController.cs`)
- User endpoints → User service: calls (evidence: `TeamChat/Controllers/UserController.cs`)
- Chat service → Chat repository: queries chats (evidence: `TeamChat.Application/Services/ChatService.cs`)
- Chat service → Message repository: queries messages (evidence: `TeamChat.Application/Services/ChatService.cs`)
- Chat service → Position hierarchy: checks hierarchy (evidence: `TeamChat.Application/Services/ChatService.cs`)
- Company service → gRPC file adapter: uploads logos (evidence: `TeamChat.Application/Services/CompanyService.cs`)
- Chat repository → Application database: reads chats (evidence: `TeamChat.Infrastructure/Persistance/Repositories/ChatRepository.cs`)
- Message repository → Application database: reads and writes (evidence: `TeamChat.Infrastructure/Persistance/Repositories/MessageRepository.cs`)
- User repository → Application database: queries users (evidence: `TeamChat.Infrastructure/Persistance/Repositories/UserRepository.cs`)
- File endpoints → gRPC file adapter: uses file service
- gRPC file adapter → File service: streams files (evidence: `FileService/Services/GrpcFileService.cs`)
- Notification worker → RabbitMQ listener: starts listener (evidence: `NotificationService/Services/Worker.cs`)
