How log795-pfe020/stockai-backend works
Main Components
• Presentation Layer:
• This includes the Presentation.Api (API controllers and middlewares), Presentation.Consumers (for event consumption via messaging), and Presentation.Jobs (background tasks such as TickJob, AddDefaultDbRecords, etc.).
• Application Layer:
• Separated into two major parts: Application.Commands and Application.Queries, which follow the CQRS pattern. Identify the command handlers (e.g., ResetAdminPasswordHandler, CreateClockHandler, etc.) and query handlers (e.g., GetStockPriceHandler, GetJwtForCredentialsHandler, etc.) in these directories.
• Domain Layer:
• Consists of Domain.Common, Domain.News, Domain.Portfolio, Domain.Stock, Domain.Time, and Domain.User. Here you have domain models (like Article, Wallet, Share, Clock, etc.), value objects, and domain events. This layer encapsulates core business logic and rules.
• Infrastructure Layer:
• Includes Infrastructure.RabbitMQ (for messaging, using MassTransit, with services and registration code that sets up message publishing) and Infrastructure.Repositories (various repository implementations, migrations, and context setups for both relational databases and NoSQL such as MongoArticleRepository and InMemoryStore).
• Configuration/Bootstrap Layer:
• The Configuration directory contains startup code (Program.cs, Startup.cs) and dispatchers (CommandDispatcher, QueryDispatcher), which wire up dependency injection, the message publisher, encryption services, and other cross-cutting concerns like certificate management.
Relationships and Data Flow
• The Presentation Layer (API controllers and job runners) interacts with the Application Layer by issuing commands or queries.
• In the Application Layer, the command and query dispatchers (from the “Seedwork” sections) route operations to their respective handlers.
• The command handlers in Application.Commands perform business operations by delegating to the Domain Layer (for rules and state changes) and then interact with the Infrastructure Layer for persistence (e.g., repositories) and messaging (e.g., RabbitMQ for event distribution).
• The query handlers in Application.Queries retrieve data from the underlying data stores via repositories.
• RabbitMQ handled in Infrastructure.RabbitMQ facilitates asynchronous communication between components, with consumers in Presentation.Consumers picking up events such as News or StockQuote.
• Integration tests (AuthServer.IntegrationTests) reference these layers and test the interactions by setting up dockerized containers for external dependencies (e.g., Azurite for blob storage, MongoDB, Postgres, RabbitMQ).
Architectural Patterns and Key Technologies
• CQRS Pattern: Clear separation between write (commands) and read (queries) sides.
• Domain-Driven Design (DDD): The Domain projects and Seedwork classes indicate a strong emphasis on business logic encapsulated in aggregates, entities, value objects, and domain events.
• Messaging: The use of RabbitMQ (via MassTransit configuration) for event-driven communication is a core architectural element.
• Microservices-ish or Modular Monolithic: Even though it might run as a combined solution, the neat separation into layers and projects indicates a modular design that could be split later.
• Infrastructure orchestration: Docker compose is used to build and run dependencies, as indicated by the docker-compose.yml, which ties the system together during development and testing.
Final Reminders
• Be detailed – include all essential components (presentation, application commands/queries, domain, infrastructure, configuration).
• Optionally, annotate technologies (e.g., .NET 8, RabbitMQ, MassTransit, Docker) alongside each section.
• Remember to note integration points such as the docker-compose network and testing/integration components.