BattleGamePlatform là một dự án microservices pattern được xây dựng với mục đích luyện tập và áp dụng các best practices trong kiến trúc phân tán. Dự án này triển khai một nền tảng game trận chiến với các services độc lập, giao tiếp qua message bus, và áp dụng các patterns như:
- Clean Architecture: Phân tách rõ ràng giữa Domain, Application, Infrastructure layers
- CQRS (Command Query Responsibility Segregation): Tách biệt logic đọc và ghi
- Event-Driven Architecture: Giao tiếp bất đồng bộ giữa các services thông qua RabbitMQ
- Outbox Pattern: Đảm bảo tính nhất quán khi publish events
- API Gateway Pattern: Điểm vào duy nhất cho clients
- Health Checks: Giám sát trạng thái services
- Distributed Tracing: Theo dõi requests xuyên suốt các services với OpenTelemetry
- Repository Pattern: Trừu tượng hóa data access layer
- Dependency Injection: Loose coupling giữa các components
Hệ thống bao gồm các services sau:
- UserService: Quản lý người dùng, authentication/authorization
- GameService: Quản lý thông tin games, game logic
- MatchService: Xử lý các trận đấu, matchmaking
- TournamentService: Quản lý giải đấu
- LeaderboardService: Bảng xếp hạng người chơi
- SearchService: Tìm kiếm games với Elasticsearch
- PostgreSQL: Primary database cho các services
- MongoDB: Document storage
- Redis: Caching layer
- RabbitMQ: Message broker cho event-driven communication
- Elasticsearch: Full-text search engine
- Aspire Dashboard: Monitoring và observability
- PgWeb: PostgreSQL web interface
git clone https://github.com/yourusername/BattleGamePlatform.git
cd BattleGamePlatformTạo file .env trong thư mục Docker/ với nội dung sau:
# PostgreSQL
POSTGRES_VERSION=17
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=battlegamedb
POSTGRES_PORT=5432
# MongoDB
MONGO_VERSION=latest
MONGO_ROOT_USERNAME=root
MONGO_ROOT_PASSWORD=your_secure_password
MONGO_PORT=27017
# Redis
REDIS_VERSION=latest
REDIS_PASSWORD=your_secure_password
REDIS_PORT=6379
# RabbitMQ
RABBITMQ_VERSION=3-management
RABBITMQ_USER=admin
RABBITMQ_PASSWORD=your_secure_password
RABBITMQ_PORT=5672
RABBITMQ_MANAGEMENT_PORT=15672
# JWT
JWT__KEY=your_jwt_secret_key_minimum_32_characters_long
# Aspire Dashboard
ASPIRE_DASHBOARD_OTLP_API_KEY=your_api_key
ASPIRE_DASHBOARD_UI_PORT=18888
ASPIRE_DASHBOARD_OTLP_PORT=18889
# Services
ASPNETCORE_ENVIRONMENT=Development
USERSERVICE_PORT=5001
GAMESERVICE_PORT=5002
MATCHSERVICE_PORT=5003
TOURNAMENTSERVICE_PORT=5004
LEADERBOARDSERVICE_PORT=5005
SEARCHSERVICE_PORT=5006
# PgWeb
PGWEB_PORT=5050
# OpenTelemetry
OTEL_SERVICE_VERSION=1.0.0cd Docker
docker-compose up -dLệnh này sẽ:
- Build tất cả các services từ source code
- Khởi động các infrastructure services (PostgreSQL, MongoDB, Redis, RabbitMQ)
- Chạy migrations cho databases
- Khởi động tất cả microservices
Sau khi khởi động, các services sẽ available tại:
- Aspire Dashboard: http://localhost:18888 - Monitoring và distributed tracing
- RabbitMQ Management: http://localhost:15672 - Message broker UI (user: admin)
- PgWeb: http://localhost:5050 - PostgreSQL web interface
- User Service API: http://localhost:5001
- Game Service API: http://localhost:5002
- Match Service API: http://localhost:5003
- Tournament Service API: http://localhost:5004
- Leaderboard Service API: http://localhost:5005
- Search Service API: http://localhost:5006
# Xem logs tất cả services
docker-compose logs -f
# Xem logs của một service cụ thể
docker-compose logs -f battlegame-userservicedocker-compose down
# Dừng và xóa volumes (xóa toàn bộ data)
docker-compose down -v# Chạy unit tests
dotnet test BattleGamePlatform.Tests/BattleGame.UnitTests/
# Chạy integration tests
dotnet test BattleGamePlatform.Tests/BattleGame.IntergrationTests/Mỗi service đều có Swagger UI để explore APIs:
- UserService: http://localhost:5001/swagger
- GameService: http://localhost:5002/swagger
- MatchService: http://localhost:5003/swagger
- TournamentService: http://localhost:5004/swagger
- LeaderboardService: http://localhost:5005/swagger
- Start infrastructure services:
cd Docker
docker-compose up -d postgres redis rabbitmq mongo dashboard- Run services từ Visual Studio hoặc command line:
cd BattleGamePlatform.AppHost
dotnet runAspire AppHost sẽ orchestrate tất cả services và mở dashboard tự động.
Migrations được tự động chạy khi services khởi động. Để tạo migration mới:
cd BattleGamePlatform.Services/User/BattleGame.UserService.DataAccessLayer
dotnet ef migrations add YourMigrationNameBattleGame.{ServiceName}/
├── Domain/ # Entities, Value Objects, Domain Events
├── Application/ # Use Cases, DTOs, Interfaces
├── Infrastructure/ # Data Access, External Services
└── API/ # Controllers, Middleware, Configuration
BattleGame.{ServiceName}.BusinessLogicLayer/ # Application layer
BattleGame.{ServiceName}.DataAccessLayer/ # Infrastructure layer
BattleGame.{ServiceName}.Common/ # Shared contracts
Dự án tuân thủ các coding standards được định nghĩa trong .github/copilot-instructions.md, bao gồm:
- Naming conventions (PascalCase, camelCase)
- Clean Architecture principles
- RESTful API design
- Error handling với ProblemDetails
- Logging best practices
- Validation và security
Đây là dự án học tập cá nhân, nhưng mọi góp ý và suggestions đều được welcome!
This project is for educational purposes.
- Clean Architecture by Robert C. Martin
- Microservices Pattern by Chris Richardson
- .NET Aspire Documentation
- Docker Documentation
Made with ❤️ for learning and practicing microservices architecture