This structured approach ensures a clear separation of concerns, making the codebase easier to manage and extend. Below is an outline of the projectβs directory structure:
------------------------------------------------------------------
UserService
βββ src π¦
β βββ UserService.Domain π
β β βββ Entities π
β β β βββ _README.txt
β β β βββ AggregateRoot.cs
β β β βββ User.cs
----------------------------
β β βββ Events π
β β β βββ _README.txt
β β β βββ BannedUserAdded.cs
β β β βββ BannedUserRemoved.cs
β β β βββ ContactRequestAdded.cs
β β β βββ ContactRequestRemoved.cs
β β β βββ IDomainEvent.cs
β β β βββ UserTrackingAuditAdded.cs
----------------------------
β β βββ Exceptions π
β β β βββ _README.txt
β β β βββ <<CustomDomainLayerExceptions>>
----------------------------
β β βββ Factories π
β β β βββ Interfaces π
β β β β βββ IUserFactory.cs
β β β βββ _README.txt
β β β βββ UserFactory.cs
----------------------------
β β βββ Repositories π
β β β βββ _README.txt
β β β βββ IUserRepository.cs
----------------------------
β β βββ ValueObjects π
β β β βββ _README.txt
β β β βββ BannedUser.cs
β β β βββ ContactRequest.cs
β β β βββ UserEmailAddress.cs
β β β βββ UserFullName.cs
β β β βββ UserID.cs
β β β βββ UserNickName.cs
β β β βββ UserTracking.cs
----------------------------
β βββ UserService.Application π
β β βββ AsyncDataServices π
β β β βββ IMessageBusPublisher.cs
----------------------------
β β βββ Commands π
β β β βββ Dispatcher π
β β β β βββ _README.txt
β β β β βββ ICommandDispatcher.cs
β β β β βββ InMemoryCommandDispatcher.cs
β β β βββ Handlers π
β β β β βββ _README.txt
β β β β βββ AddContactRequestHandler.cs
β β β β βββ AddToAuditTrailHandler.cs
β β β β βββ BanUserHandler.cs
β β β β βββ CreateUserHandler.cs
β β β β βββ ICommandHandler.cs
β β β β βββ RemoveIssuedContactRequestHandler.cs
β β β β βββ RemoveReceivedContactRequestHandler.cs
β β β β βββ UnbanUserHandler.cs
β β β β βββ UpdateContactRequestMessageHandler.cs
β β βββ _README.txt
β β βββ AddContactRequestCommand.cs
β β βββ AddToAuditTrailCommand.cs
β β βββ BanUserCommand.cs
β β βββ CreateUserCommand.cs
β β βββ ICommand.cs
β β βββ RemoveIssuedContactRequestCommand.cs
β β βββ RemoveReceivedContactRequestCommand.cs
β β βββ UnbanUserCommand.cs
β β βββ UpdateContactRequestMessageCommand.cs
----------------------------
β β βββ Dtos π
β β β βββ _README.txt
β β β βββ IssuedBanByUserDto.cs
β β β βββ IssuedContactRequestByUserDto.cs
β β β βββ ReceivedBanByUserDto.cs
β β β βββ ReceivedContactRequestByUserDto.cs
β β β βββ UserDto.cs
β β β βββ UserPublishedDto.cs
----------------------------
β β βββ Exceptions π
β β β βββ _README.txt
β β β βββ <<CustomApplicationLayerExceptions>>
----------------------------
β β βββ Extensions π
β β β βββ ServiceCollectionExtensions.cs
----------------------------
β β βββ Queries π
β β β βββ Dispatcher π
β β β β βββ _README.txt
β β β β βββ InMemoryQueryDispatcher.cs
β β β β βββ IQueryDispatcher.cs
----------------------------
β β | βββ Handlers π
β β β β βββ _README.txt
β β β β βββ IQueryHandler.cs
β β βββ _README.txt
β β βββ GetIssuedBansByUserQuery.cs
β β βββ GetIssuedContactRequestsByUserQuery.cs
β β βββ GetReceivedBansByUserQuery.cs
β β βββ GetReceivedContactRequestByUserQuery.cs
β β βββ GetUserQuery.cs
β β βββ IQuery.cs
----------------------------
β β βββ Services π
β β β βββ ReadServices π
β β β β βββ IUserReadService.cs
β β | βββ _README.txt
----------------------------
β βββ UserService.Infrastructure π
β β βββ AsyncDataServices π
β β β βββ MessageBusPublisher.cs
----------------------------
β β βββ Automapper π
β β β βββ Profiles π
β β β β βββ BannedUserProfile.cs
β β β β βββ ContactRequestProfile.cs
β β β β βββ UserProfile.cs
----------------------------
β β βββ EntityFramework π
β β β βββ Contexts π
β β β β βββ ReadDbContext.cs
β β β β βββ WriteDbContext.cs
β β β βββ Encryption π
β β β β βββ EncryptionConverters π
β β β β β βββ EncryptedDateTimeOffsetConverter.cs
β β β β β βββ EncryptedStringConverter.cs
β β β β β βββ EncryptedUserEmailAddressConverter.cs
β β β β β βββ EncryptedUserFullNameConverter.cs
β β β β β βββ EncryptedUserNickNameConverter.cs
β β β β βββ EncryptionProvider π
β β β β β βββ IEncryptionProvider.cs
β β β β β βββ EncryptionProvider.cs
β β β βββ Initialization π
β β β β βββ DbInitializer.cs
β β β βββ Migrations π
β β β β βββ <<EntityFramework database migrations>>
β β β βββ ModelConfiguration π
β β β β βββ ReadConfiguration π
β β β β β βββ _README.txt
β β β β β βββ BannedUserConfiguration.cs
β β β β β βββ ContactRequestConfiguration.cs
β β β β β βββ UserConfiguration.cs
β β β β β βββ UserTrackingConfiguration.cs
β β β β βββ WriteConfiguration π
β β β β β βββ BannedUserConfiguration.cs
β β β β β βββ ContactRequestConfiguration.cs
β β β β β βββ UserConfiguration.cs
β β β β β βββ UserTrackingConfiguration.cs
β β β βββ Models π
β β β β βββ _README.txt
β β β β βββ BannedUserReadModel.cs
β β β β βββ ContactRequestReadModel.cs
β β β β βββ UserReadModel.cs
β β β β βββ UserTrackingReadModel.cs
β β β βββ Options π
β β β β βββ PostgresOptions.cs
β β β βββ Repositories π
β β β β βββ PostgresUserRepository.cs
β β β βββ Services π
β β β β βββ ReadServices π
β β β β β βββ PostgresUserReadService.cs
----------------------------
β β βββ Exceptions π
β β β βββ Interfaces π
β β β β βββ IExceptionToResponseMapper.cs
β β β βββ ExceptionResponse.cs
β β β βββ ExceptionToResponseMapper.cs
β β β βββ InfrastructureException.cs
β β β βββ NullDbContextException.cs
----------------------------
β β βββ Extensions π
β β β βββ ServiceCollectionExtensions.cs
β β β βββ ConfigurationExtensions.cs
----------------------------
β β βββ Logging π
β β β βββ Formatters π
β β β β βββ SerilogJsonFormatter.cs
β β β βββ LoggingCommandHandlerDecorator.cs
----------------------------
β β βββ Queries π
β β β βββ Handlers π
β β β β βββ GetIssuedBansByUserHandler.cs
β β β β βββ GetIssuedContactRequestsByUserHandler.cs
β β β β βββ GetReceivedBansByUserHandler.cs
β β β β βββ GetReceivedContactRequestByUserHandler.cs
β β β β βββ GetUserHandler.cs
----------------------------
β β βββ UserRegistration π
β β β βββ IUserSynchronizer.cs
β β β βββ UserSynchronizer.cs
----------------------------
β βββ UserService.Presentation π
β β βββ Properties π
β β β βββ launchSettings.json
β β βββ Controllers π
β β β βββ UserController.cs
β β βββ Dtos π
β β β βββ ResponseDto.cs
β β βββ Middlewares π
β β β βββ ErrorHandlerMiddleware.cs
β β β βββ RateLimitingMiddleware.cs
β β β βββ UserRegistrationMiddleware.cs
β β βββ appsettings.json
β β βββ Program.cs
----------------------------
βββ tests π§ͺ
β βββ UserService.Tests.EndToEnd
β β βββ Extensions π
β β β βββ IServiceCollectionExtensions.cs
β β βββ Factories π
β β β βββ UserServiceApplicationFactory.cs
β β βββ Sync π
β β β βββ _README.txt
β β β βββ BaseSyncIntegrationTest.cs
β β β βββ RegisterBannedUserTests.cs
β β β βββ RegisterContactRequestTests.cs
β β β βββ RegisterUserActivityTests.cs
β β β βββ RegisterUserTests.cs
β β β βββ RemoveBannedUserTests.cs
β β β βββ RemoveIssuedContactRequestTests.cs
β β β βββ RemoveReceivedContactRequestTests.cs
β β β βββ UpdateContactRequestMessageTests.cs
----------------------------
β βββ UserService.Tests.Unit
β β βββ Application π
β β β βββ Handlers π
β β β β βββ AddContactRequestHandlerTests.cs
β β β β βββ AddToAuditTrailHandlerTests.cs
β β β β βββ BanUserHandlerTests.cs
β β β β βββ CreateUserHandlerTests.cs
β β β β βββ RemoveIssuedContactRequestHandlerTests.cs
β β β β βββ RemoveReceivedContactRequestHandlerTests.cs
β β β β βββ UnbanUserHandlerTests.cs
β β β β βββ UpdateContactRequestMessageHandlerTests.cs
β β βββ Domain π
β β β βββ Entities π
β β β β βββ UserTests π
β β β β | βββ _README.txt
β β β β | βββ AddToAuditTrail.cs
β β β β | βββ BanUser.cs
β β β β | βββ IssueContactRequest.cs
β β β β | βββ ReceiveContactRequest.cs
β β β β | βββ RemoveReceivedContactRequest.cs
β β β β | βββ UnbanUser.cs
β β β βββ Factories π
β β β β βββ _README.txt
β β β β βββ UserFactoryTests.cs
------------------------------------------------------------------
Layer | Directory/File | Description |
---|---|---|
Domain | UserService/src/UserService.Domain/Entities/ |
Contains domain entities representing core business concepts. |
Domain | UserService/src/UserService.Domain/Events/ |
Includes domain events capturing significant changes or actions. |
Domain | UserService/src/UserService.Domain/Exceptions/ |
Houses custom exceptions specific to domain logic. |
Domain | UserService/src/UserService.Domain/Factories/ |
Provides factories for creating domain entities. |
Domain | UserService/src/UserService.Domain/Repositories/ |
Defines interfaces or base classes for data access operations. |
Domain | UserService/src/UserService.Domain/ValueObjects/ |
Contains immutable value objects used within the domain. |
Application | UserService/src/UserService.Application/AsyncDataServices/ |
Defines interfaces for asynchronous operations. |
Application | UserService/src/UserService.Application/Commands/ |
Contains command types and serves as the central location for defining and organizing commands. |
Application | UserService/src/UserService.Application/Commands/Dispatcher/ |
Contains command dispatcher type and serves as the central component responsible for |
routing commands to their respective command handlers. | Β | Β |
Application | UserService/src/UserService.Application/Commands/Handlers/ |
Contains command handler types that implement ICommandHandler |
Command Query Responsibility Segregation (CQRS). | Β | Β |
Application | UserService/src/UserService.Application/Dtos/ |
Contains Data Transfer Objects (DTOs). |
Application | UserService/src/UserService.Application/Exceptions/ |
Contains Application layer specific custom exception types. |
Application | UserService/src/UserService.Application/Extensions/ |
Contains custom extension methods. |
Application | UserService/src/UserService.Application/Queries/ |
Contains query types and serves as the central location for defining and organizing queries. |
Application | UserService/src/UserService.Application/Queries/Dispatcher/ |
Contains query dispatcher type that implements IQueryDispatcher interface and serves as the central component responsible for |
routing queries to their respective query handlers for execution and data retrieval. | Β | Β |
Application | UserService/src/UserService.Application/Queries/Handlers/ |
Contains the definition of the IQueryHandler<TQuery, TResult> interface, which serves as a contract for all query handlers |
responsible for executing queries and retrieving data from the applicationβs read-side or queryable data sources. | Β | Β |
Application | UserService/src/UserService.Application/Services/ |
Implements application services containing business logic. |
Infrastructure | UserService/src/UserService.Infrastructure/AsyncDataServices/ |
Defines implementations of interfaces for asynchronous operations. |
Infrastructure | UserService/src/UserService.Infrastructure/Automapper/ |
Contains types, that are inheriting the Profile type from AutoMapper library. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Contexts/ |
Contains two EntityFramework DbContext classes - ReadDbContext and WriteDbContext. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Encryption/ |
Contains custom EntityFramework encryption converters and encryption provider. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Initialization/ |
Contains DbInitializer class that applies entity framework migrations. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Migrations/ |
Contains EntityFramework migrations. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/ModelConfiguration/ReadConfiguration/ |
Contains classes that implement IEntityTypeConfiguration |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/ModelConfiguration/WriteConfiguration/ |
Contains classes that implement IEntityTypeConfiguration |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Models/ |
Contains classes for the database models that represent the database tables and the overall database schema. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Options/ |
Contains class that is used for the OPTIONS pattern. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Repositories/ |
Contains implementations of interfaces for data access operations. |
Infrastructure | UserService/src/UserService.Infrastructure/EntityFramework/Services/ |
Contains implementations of interfaces for services containing business logic. |
Infrastructure | UserService/src/UserService.Infrastructure/Exceptions/ |
Contains Infrastructure layer specific custom exception types. |
Infrastructure | UserService/src/UserService.Infrastructure/Extensions/ |
Contains custom extension methods. |
Infrastructure | UserService/src/UserService.Infrastructure/Logging/ |
Contains logging decorators and formatters. The purpose of the decorators is to wrap the behaviour of a Command Handler or other part of the application and to enrich itβs capabilities with the ability to log information. |
Infrastructure | UserService/src/UserService.Infrastructure/Queries/ |
Contains query handlers that work with the queries from the Command Query Responsibility Segregation (CQRS) approach. |
Infrastructure | UserService/src/UserService.Infrastructure/UserRegistration/ |
Contains UserSynchronizer that synchronizes a user with this service. |
Presentation | UserService/src/UserService.Presentation/Properties/ |
Contains the application properties related to port and protocol configuration. |
Presentation | UserService/src/UserService.Presentation/Controllers/ |
Contains API controllers handling HTTP requests and responses. |
Presentation | UserService/src/UserService.Presentation/DTOs/ |
Provides Data Transfer Objects (DTOs) for API input and output. |
Presentation | UserService/src/UserService.Presentation/Middlewares/ |
Contains custom middlewares. |