How mrquackduck/colirbackend works
And Outline the Main Components
• Web API Layer: This is the entry point for all client requests. It includes controllers for authentication, messaging, user management, and room operations. Within the Web API you have additional components for SignalR hubs (ChatHub, ClearRoomHub, RegistrationHub, VoiceChatHub) that support real-time communication.
• Business Logic Layer (BLL): Contains services, models, factories, and request models that encapsulate the core business rules for rooms, messages, users, and statistics. It also includes an AutoMapper profile for object transformation.
• Data Access Layer (DAL): Handles interactions with the PostgreSQL database using Entity Framework Core. It comprises the DbContext, entity definitions (such as Attachment, Message, Room, User, etc.), repositories, and UnitOfWork to abstract and coordinate data operations.
• Exception Handling Modules: Separate project providing custom exceptions (e.g., NotFoundException, NotEnoughPermissionsException) to capture different error conditions.
• Integration & Unit Tests: Projects for testing the BLL, DAL, and Web API integration ensure that the components interact correctly.
• API Related Services: Within the Web API project, additional services such as OAuth2 integration for GitHub and Google as well as token and event handling are defined.
Relationships and Data Flow
• The Web API receives client requests and forwards them to the corresponding BLL services.
• Services in the BLL call the DAL via repository interfaces to read/write data. The mapping between DAL entities and BLL models is managed through AutoMapper.
• Exception modules are used centrally to manage any errors or permission issues.
• Authentication is handled by services that generate JWT tokens, manage refresh tokens, and integrate with third-party OAuth2 providers.
• All data passing through the API is encrypted on the client side; the API handles only transmission and storage of already encrypted content.
• Real-time messaging flows via SignalR hubs in the Web API, which interact with the service layer to relay chat messages and manage room states.
Architectural Patterns and Key Design Principles
• Layered Architecture: Clearly defined separation between the presentation layer (Web API), business logic (BLL), and data access (DAL) ensures maintainability and testability.
• Repository and UnitOfWork Patterns: Implemented in the DAL to abstract database operations.
• Dependency Injection: Interfaces for services and repositories across all layers promote loose coupling.
• SignalR for Real-Time Communication: Essential for chat and voice features.
• Security Concerns: End-to-end encryption means that while the API handles encrypted data, the key management is handled client-side. Additionally, thorough error handling and permission checks are enforced.