📦 Sample.CleanArchitecture.Microservice
A modern microservice template with Clean Architecture principles
Sample.CleanArchitecture.Microservice
is a demonstration project that implements a microservice using the principles of Clean Architecture. This project is intended as a template or starting point for building scalable, maintainable, and testable microservices.
Microservices is an architectural style that structures an application as a collection of small, autonomous services. Each service is self-contained, independently deployable, and communicates with others via APIs or messaging systems.
- Independence: Services can be developed, deployed, and scaled independently.
- Decentralization: Each service manages its own data and operates autonomously.
- Resilience: Services are designed to handle failures gracefully.
- Scalability: Services can be scaled independently to meet demand.
Clean Architecture is a design philosophy that emphasizes separation of concerns, making systems easy to understand, maintain, and test. It organizes code into distinct layers, each with a specific responsibility.
- Entities: Core business logic and rules, independent of external frameworks.
- Use Cases (Interactors): Application-specific business rules and actions.
- Interface Adapters: Bridges between use cases and external systems, converting data formats as needed.
- Frameworks & Drivers: The outermost layer, containing implementation details like UI frameworks, databases, and web APIs.
- Testability: Isolated components are easier to test.
- Maintainability: Changes in one layer do not affect others.
- Flexibility: Easier integration of new technologies or modifications.
Sample.CleanArchitecture.Microservice/
│
├── src(Each Domain Source)/
│ ├── Domain/ # Business logic, entities, and use cases
│ ├── Application/ # Application services, interfaces
│ ├── Infrastructure/ # Implementations for data access, external services
│ └── Web (Gateway)/ # Entry point, controllers, HTTP handling
│
└── README.md # Project documentation
- .NET 8.0 SDK
- Docker (optional, for containerization)
- SQL Server (or any other supported database)
-
Clone the Repository:
git clone https://github.com/raminsharifiOrg/Sample.CleanArchitechture.Microservice cd Sample.CleanArchitecture.Microservice
-
Build the Solution:
dotnet build
-
Run the Application:
dotnet run --project src/Api
-
Access the API:
The API will be available at
https://localhost:5001
by default.
-
Build the Docker Image:
docker build -t sample-cleanarchitecture-microservice .
-
Run the Docker Container:
docker run -p 5001:80 sample-cleanarchitecture-microservice
-
Access the API:
The API will be available at
http://localhost:5001
.
This project is licensed under the MIT License - see the LICENSE file for details.
A big thank you to the contributors of the Clean Architecture and Microservices communities for their guidance and inspiration.