-
Notifications
You must be signed in to change notification settings - Fork 8
System Design
The Flet-Chat application follows a clean architecture approach, separating concerns into distinct layers and utilizing various design patterns to ensure maintainability, testability, and scalability.
The system is divided into several key components:
- API Layer: Handles HTTP requests and responses
- Interactors: Implements use cases and business logic
- Gateways: Provides an abstraction over data access
- Infrastructure: Manages external concerns like databases and caching
- Domain: Contains core business entities and events
The Unit of Work pattern is implemented to manage database transactions and track changes to domain objects.
Click to view/hide UoW class diagram

Data Mappers are used to separate the in-memory representation of domain objects from their database representation.
Gateways provide an abstraction layer over data access, implementing repository-like interfaces for each domain entity.
Interactors (or Use Case classes) encapsulate and implement business rules, coordinating between gateways and domain objects.
An Event Dispatcher is used to handle domain events, allowing for loose coupling between components.
Click to view/hide Event Dispatcher class diagram

A SecurityService class handles authentication and authorization concerns, including password hashing and JWT token management.
- HTTP requests are received by the API layer
- The API layer uses Interactors to handle the request
- Interactors use Gateways to access data
- Gateways use the Unit of Work and Data Mappers to interact with the database
- Domain events are dispatched using the Event Dispatcher
- The API layer returns the response to the client
Click to view/hide Data Flow sequence diagram

- API Layer: Implemented using FastAPI, handling HTTP requests and responses.
- Interactors: Implement use cases such as user management, chat operations, and messaging.
- Gateways: Provide interfaces for data access, implemented for users, chats, messages, and tokens.
- Unit of Work: Manages database transactions and tracks changes to domain objects.
- Data Mappers: Handle the mapping between domain objects and database models.
- Event Dispatcher: Manages domain events, allowing for decoupled communication between components.
- Security Service: Handles authentication, authorization, and token management.
- Redis Client: Manages real-time communication and caching.
This architecture promotes separation of concerns, making the system more maintainable and testable. It also allows for easy extension and modification of individual components without affecting the entire system.