A modern forum application built with .NET 10.0 using microservices architecture, implementing Domain-Driven Design (DDD) principles, CQRS pattern, and event-driven communication.
This project is a distributed forum system composed of three main microservices that handle different aspects of the application:
- Forum Service: Manages questions, answers, and forum-related operations
- User Service: Handles authentication, authorization, and user management
- Notification Service: Processes and delivers notifications to users
The project follows a microservices architecture with the following characteristics:
- Domain-Driven Design (DDD): Each service is organized around business domains
- Clean Architecture: Clear separation of concerns with distinct layers (Domain, Application, Infrastructure, Endpoints)
- Event-Driven Communication: Microservices communicate through integration events
- CQRS Pattern: Separation of read and write operations
- Minimal API: Using .NET's minimal API approach for lightweight endpoints
The project includes a shared BuildingBlocks library that provides:
- Base Domain Classes: Aggregate, Entity, ValueObject, UniqueEntityId, WatchedList
- Event Bus: Implementation for both in-memory and RabbitMQ-based event publishing
- Custom Exceptions: Domain-specific exception handling (BadRequest, NotFound, Validation, etc.)
- Middleware: Correlation ID tracking, Request/Response logging
- Logging: Structured logging with Serilog
- Pagination: Generic pagination support
- Result Pattern: Functional error handling
- .NET 10.0 - Latest .NET framework
- C# 13 - Modern C# features
- ASP.NET Core - Web framework with Minimal APIs
- PostgreSQL - Primary database for all services
- Entity Framework Core 10.0 - ORM for database access
- Npgsql - PostgreSQL provider for EF Core
- RabbitMQ - Message broker for asynchronous communication between services
- RabbitMQ.Client 6.8.1 - RabbitMQ client library
- ASP.NET Core Identity - User management framework
- JWT Bearer Authentication - Token-based authentication
- Microsoft.IdentityModel.Tokens - JWT token handling
- Serilog - Structured logging
- Serilog.AspNetCore - ASP.NET Core integration
- Serilog.Sinks.Console - Console output
- Serilog.Sinks.File - File-based logging
- Serilog.Expressions - Advanced logging expressions
- Swagger/OpenAPI - API documentation and testing interface
- Swashbuckle.AspNetCore - Swagger generator for ASP.NET Core
- Docker - Container platform
- Docker Compose - Multi-container orchestration
- xUnit - Testing framework
- In-Memory Database - For unit and integration testing
Each microservice has its own dedicated database:
- ForumDb: Stores questions, answers, attachments, and forum-related data
- UserDb: Manages user accounts, roles, and authentication data
- NotificationDb: Handles notification records and delivery status
| Service | Local HTTP | Local HTTPS | Docker HTTP | Docker HTTPS | Docker Internal |
|---|---|---|---|---|---|
| Forum | 5000 | 5050 | 8000 | 8443 | 8080 - 8081 |
| Notification | 5001 | 5051 | 8001 | 8444 | 8080 - 8081 |
| User | 5002 | 5052 | 8002 | 8445 | 8080 - 8081 |
Note: Docker uses safe ports (8000-8002, 8443-8445) to avoid browser blocking issues. Ports 6000-6007 are considered unsafe by modern browsers.
| Service | Port | Management Port |
|---|---|---|
| ForumDb | 5433 | - |
| NotificationDb | 5434 | - |
| UserDb | 5435 | - |
| RabbitMQ | 5672 | 15672 |
- Create, read, update, and delete questions
- Create, read, update, and delete answers
- Mark best answer for questions
- Filter questions by author
- Attachment management
- Student and Instructor roles
- Pagination support
- User registration
- User authentication with JWT tokens
- Role-based authorization
- Password management
- Email validation
- Token refresh mechanism
- Send notifications to users
- Read notification status
- Integration with other services via events
- Notification history
Forum/
βββ src/
β βββ BuildingBlocks/ # Shared library
β β βββ Base/ # Domain base classes
β β βββ Exceptions/ # Custom exceptions
β β βββ Extensions/ # Helper extensions
β β βββ Logging/ # Logging infrastructure
β β βββ Messaging/ # Event bus implementation
β β βββ Middleware/ # Common middleware
β βββ Forum/ # Forum microservice
β β βββ Application/ # Application layer
β β βββ Domain/ # Domain layer
β β βββ Endpoints/ # API endpoints
β β βββ Infrastructure/ # Infrastructure layer
β β βββ Migrations/ # Database migrations
β βββ Notification/ # Notification microservice
β β βββ Application/
β β βββ Domain/
β β βββ Endpoints/
β β βββ Infrastructure/
β β βββ Migrations/
β βββ User/ # User microservice
β βββ Data/ # Data layer
β βββ DTOs/ # Data transfer objects
β βββ Endpoints/ # API endpoints
β βββ Extensions/ # Extensions
β βββ Migrations/ # Database migrations
β βββ Services/ # Business services
βββ tests/
β βββ Forum.UnitTest/ # Forum unit tests
β βββ Notification.UnitTest/ # Notification unit tests
β βββ User.UnitTest/ # User unit tests
β βββ Seed/ # Database seeding
βββ docs/ # Documentation
βββ compose.yaml # Docker Compose configuration
βββ Forum.sln # Solution file
- .NET 10.0 SDK
- Docker and Docker Compose
- PostgreSQL (if running locally without Docker)
- RabbitMQ (if running locally without Docker)
- Clone the repository:
git clone <repository-url>
cd Forum- Option A - Run Everything in Docker (Recommended)
# Start all services (APIs + Databases + RabbitMQ)
docker-compose up -d
# Access the APIs:
# Forum API: http://localhost:8000/swagger
# Notification API: http://localhost:8001/swagger
# User API: http://localhost:8002/swagger
# HTTPS is also available:
# Forum API: https://localhost:8443/swagger
# Notification API: https://localhost:8444/swagger
# User API: https://localhost:8445/swagger- Option B - Run APIs Locally (For Debugging)
# Start only infrastructure (databases and RabbitMQ)
docker-compose up -d userdb forumdb notificationdb messagebroker
# Terminal 1 - Forum Service
cd src/Forum
dotnet run
# Terminal 2 - User Service
cd src/User
dotnet run
# Terminal 3 - Notification Service
cd src/Notification
dotnet run
# Access the APIs:
# Forum API: http://localhost:5000/swagger
# Notification API: http://localhost:5001/swagger
# User API: http://localhost:5002/swaggerHTTPS certificates are automatically generated inside containers on first startup. No manual configuration needed!
Migrations run automatically when starting services. To run manually:
# Forum Service
cd src/Forum
dotnet ef database update
# User Service
cd src/User
dotnet ef database update
# Notification Service
cd src/Notification
dotnet ef database update- Forum API: http://localhost:5000/swagger
- User API: http://localhost:5002/swagger
- Notification API: http://localhost:5001/swagger
HTTP:
- Forum API: http://localhost:8000/swagger
- User API: http://localhost:8002/swagger
- Notification API: http://localhost:8001/swagger
HTTPS:
- Forum API: https://localhost:8443/swagger
- User API: https://localhost:8445/swagger
- Notification API: https://localhost:8444/swagger
- URL: http://localhost:15672
- Username: guest
- Password: guest
Run all tests:
dotnet testRun tests for a specific project:
dotnet test tests/Forum.UnitTest
dotnet test tests/User.UnitTest
dotnet test tests/Notification.UnitTestEach service can be configured via appsettings.json and appsettings.Development.json. Key configurations include:
- Connection Strings: Database connections
- JWT Settings: Token configuration (User service)
- RabbitMQ Settings: Message broker configuration
- Logging Levels: Serilog configuration
- CORS Policies: Cross-origin resource sharing
- Question: Forum questions with title, content, and metadata
- Answer: Responses to questions
- Attachment: File attachments for questions/answers
- Student: Student user type
- Instructor: Instructor user type with additional privileges
- ApplicationUser: Extended Identity user
- Roles: Role-based access control
- Notification: User notifications with read status
The system uses an event bus pattern for inter-service communication:
- Domain Events: Events within a single service boundary
- Integration Events: Events that cross service boundaries
- Event Handlers: Process events asynchronously
Supported event bus implementations:
- InMemoryEventBus: For development and testing
- RabbitMQEventBus: For production use
The application implements comprehensive error handling with:
- Custom Exception Types: BadRequest, NotFound, Validation, Forbidden, InternalServer
- Global Exception Handler: Centralized exception processing
- Result Pattern: Functional error handling for operations
- Structured Logging: All errors are logged with context
# Start everything
docker-compose up -d
# View logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f forum
docker-compose logs -f notification
docker-compose logs -f user
# Check status
docker-compose ps
# Stop everything
docker-compose down
# Stop and remove volumes (clean slate)
docker-compose down -v
# Restart a specific service
docker-compose restart forumβ
Automatic HTTPS Certificates - Generated automatically inside containers
β
Safe Ports - Uses browser-safe ports (8000-8002, 8443-8445)
β
Health Checks - All services have health monitoring
β
Persistent Data - Databases use volumes for data persistence
β
Auto-restart - Services restart automatically on failure
β
Zero Configuration - Just run docker-compose up -d
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Host Machine β
β β
β Browser β :8000 (Forum HTTP) β :8443 (Forum HTTPS) β
β β :8001 (Notification) β :8444 (Notification) β
β β :8002 (User) β :8445 (User) β
β β :15672 (RabbitMQ UI) β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Docker Network β β
β β β β
β β ββββββββββββ βββββββββββββββ ββββββββββββ β β
β β β Forum β β Notificationβ β User β β β
β β β API β β API β β API β β β
β β ββββββββββββ βββββββββββββββ ββββββββββββ β β
β β β β β β β
β β ββββββββββ ββββββββββ ββββββββββ β β
β β βForumDB β βNotifyDBβ βUserDB β β β
β β ββββββββββ ββββββββββ ββββββββββ β β
β β β β β β β
β β βββββββββββββββββββββ β β
β β β RabbitMQ β β β
β β βββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
APIs not responding?
# Check if containers are running
docker-compose ps
# Check logs for errors
docker-compose logs -fDatabase connection issues?
# Restart databases
docker-compose restart forumdb notificationdb userdbRabbitMQ issues?
# Restart RabbitMQ
docker-compose restart messagebrokerClean everything and start fresh?
docker-compose down -v
docker-compose up -d --build- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with .NET 10.0
- Inspired by Clean Architecture and DDD principles
- Microservices architecture patterns