A modern .NET microservice template with GraphQL, MongoDB, Docker support, and comprehensive testing infrastructure.
- 🚀 GraphQL API using HotChocolate
- 📦 MongoDB Integration
- 🐳 BytLabs Core Packages Integration
- 🐳 Docker & Docker Compose support
- 🧪 Comprehensive testing setup (Unit & Acceptance Tests)
- 📊 OpenTelemetry integration
- 🔄 CI/CD pipeline with GitHub Actions
- 🎯 Domain-Driven Design (DDD) architecture
- 🔍 Health checks
- 👥 Multi-tenant support
- 📝 Logging with Serilog
This template leverages BytLabs core packages to ensure consistency and standardization across all microservices:
Package | Description |
---|---|
BytLabs.Domain |
Domain model building blocks |
BytLabs.Application |
CQRS, validation, and application services |
BytLabs.DataAccess |
Data persistence and MongoDB integration |
BytLabs.DataAccess.MongoDB |
Data persistence and MongoDB integration |
BytLabs.Multitenancy |
Multi-tenant infrastructure |
BytLabs.Observability |
Monitoring and logging tools |
Using these packages ensures:
- Uniform architecture across all microservices
- Consistent error handling and logging
- Standardized testing approaches
- Common security practices
- Shared domain patterns and building blocks
- .NET 8.0 SDK
- Docker & Docker Compose
- MongoDB (or use the provided Docker container)
To get started with the project, follow these steps:
-
Create a New Repository from the Template
Instead of cloning the repository directly, use the "Use this template" button on GitHub to create your own repository based on the microservice-template. This ensures that you have a copy of the template repository to work with.
- Click the "Use this template" button (usually found near the top-right corner of the page).
- Create your new repository by following the instructions on GitHub.
-
Clone Your New Repository
Once your new repository is created, clone it to your local machine:
git clone https://github.com/your-username/your-new-repository.git cd your-new-repository
-
Run the Project Setup Script
To rename the project, run the
set-project-name.sh
script. It will prompt you for a new project name:bash set-project-name.sh
Example Input: When prompted, enter the new project name. For example:
Order Management
Orders
The script will automatically update the project name in all relevant files.
-
Run the application using Docker Compose
docker-compose up
The service will be available at:
- HTTP: http://localhost:8080
- HTTPS: https://localhost:8081
- GraphQL Endpoint: http://localhost:8080/graphql/
This blog series will guide you step by step, from setting up the template to deploying your services in the cloud.
- Getting Started with BytLabs.MicroserviceTemplate: API Project Setup
- Getting Started with BytLabs.MicroserviceTemplate: Domain and Application Setup
The application can be configured through various settings files:
-
Main Configuration (
appsettings.json
):{ "ObservabilityConfiguration": { "CollectorUrl": "http://localhost:4317", "ServiceName": "microservice-template", "Timeout": 1000 }, "MongoDatabaseConfiguration": { "DatabaseName": "microserviceTemplate", "ConnectionString": "mongodb://localhost:27017?retryWrites=false", "UseTransactions": false } }
Execute all tests using Docker:
docker-compose up bytlabs-microservice-template-tests
The template uses StrawberryShake for GraphQL client generation. To update the client:
-
Install the StrawberryShake CLI:
dotnet tool restore
-
Generate the client code:
dotnet graphql generate
The template includes a GitHub Actions workflow that:
- Runs all tests
- Builds the application
- Publishes NuGet packages
- Supports different versioning for:
- Feature branches (alpha versions)
- Release tags (stable versions)
The solution follows Clean Architecture and DDD principles:
- API Layer: GraphQL endpoints, configuration, and middleware
- Application Layer: Commands, queries, and application logic
- Domain Layer: Aggregates, entities, and domain logic
- Infrastructure Layer: Database access, external services integration
We are planning to introduce the following enhancements to the BytLabs Microservice Template:
-
BytLabs MessageBus Package Integration:
- Leverages Dapr's message bus to handle both event-based pub/sub and command-driven point-to-point communication.
- Facilitates seamless communication for integration events and commands between microservices.
- Supports the outbox pattern to ensure reliable message delivery and consistency.
-
BytLabs FileSystem Service:
- The FileSystem Service will provide an abstraction for managing object storage across multiple cloud providers (e.g., AWS S3, Azure Blob Storage, Google Cloud Storage).
- It will be implemented as a standalone microservice, built using the BytLabs Microservice Template, ensuring consistency in architecture and design principles.
- Key Features:
- Multi-Cloud Compatibility: The service will support major cloud providers, enabling seamless storage operations regardless of the underlying cloud infrastructure.
- Unified API: Developers can interact with a single API, abstracting the complexities of different cloud provider implementations.
- Core Operations: Includes file upload, download, metadata retrieval, and secure file sharing.
This service aims to simplify object storage management and provide a consistent developer experience across varied cloud environments.
Stay tuned for updates as we continue enhancing the BytLabs ecosystem!
- Fork the repository
- Create your 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.
- HotChocolate for GraphQL implementation
- MongoDB.Driver for MongoDB integration
- OpenTelemetry for observability
- Docker for containerization