Giter Site home page Giter Site logo

j-didi / clean-architecture-dotnet Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 158 KB

This repository is a sandbox to experiment with new techniques, concepts, and technologies using Clean Architecture concepts. Here you will find Domain-Driven Design (DDD), Command Query Responsibility Segregation (CQRS), SOLID Design Principles, Design Patterns, and more.

Home Page: https://github.com/j-didi/clean-arch-dotnet

License: MIT License

C# 91.09% Dockerfile 1.98% JavaScript 6.92%
clean-architecture domain-driven-design solid cqrs unit-testing integration-testing load-testing end-to-end-testing domain-validation mediator-pattern

clean-architecture-dotnet's Introduction

Dotnet Clean Architecture

Give a Star! โญ

If you liked my work and want to support me, please give it a star. Thanks!

Introduction

This repository is a sandbox to experiment with new techniques, concepts, and technologies using Clean Architecture concepts. Here you will find Domain-Driven Design (DDD), Command Query Responsibility Segregation (CQRS), SOLID Design Principles, Design Patterns, and more.

1. How to Run ๐Ÿš€

App

docker-compose -f ./infra/docker-compose.yml -f ./infra/docker-compose.dev.yml -p clean-arch-dotnet-dev up -d

Swagger

http://localhost:5010/swagger

Tests

Unit, Integration, and End-to-End Tests

dotnet test CleanArchDotnet.sln

Load and Stress Tests

docker-compose -f ./infra/docker-compose.yml -f ./infra/docker-compose.test.yml -p clean-arch-dotnet-test up -d

2. Architecture ๐ŸŽฏ

I'm using a Clean Architecture model, splitting the solution into Core, Infra, Services, and Shared Kernel layers.

alt text

Core

The Core layer is responsible for the Domain Entities, Value Objects, Domain Services, Domain Events, Use Cases and Abstractions for communication with external layers. The main goal of this architecture is to keep the Core, where the business lives, isolated from external dependencies implementation details.

The organization follows "The Screaming Architecture" concept by Uncle Bob that purposes that your application architecture should scream what the system does. So I've preferred an organization by context rather than by component type.

Another principle that I'm following is CQRS/CQS, so the Use Cases are divided into Write or Read operations. Also, any Use Case has its owns Command, Query, Result, and Handler.

alt text

Infra

The Infra layer is responsible for Repository Concerns (Schemas, Repository Implementations, and Database Connections), Dependency Injection, Application Settings, and External Providers for integration or services consumption.

Services

These are entry points for Core Use Cases consumption. Can be APIs, gRPC Services, Serverless Functions, Workers, and more. As the domain does not depend upon, the consumption can be anything.

Shared Kernel

These are common resources used between application layers. This project avoids circular dependencies between the layers.

3. Dependency Structure ๐Ÿ”Œ

alt text

This Architecture follows the Dependency Rule, where all dependencies points toward the architecture center (AKA the Core).

The Infra layer depends upon the Core layer, while the Core uses abstractions with the Dependency Inversion Principle to consume infra resources, like data access.

The Services layer depends upon the Infra due to Dependency Injection and Application Settings needs. The Services layer depends upon the Core too and communicates with the Core through abstractions.

The Shared Kernel layer helps to avoid circular dependencies between projects. All projects depend upon the Shared Kernel.

4. Containers ๐Ÿณ

The application is containerized using Docker and automated using Docker Compose.

The docker-compose file has overridden versions for Dev and Load Tests environments. I took the caution not to use default ports in containers to avoid conflict with other containers/servers that you may have using these ports.

Another point is that the application is working with Entity Framework Core ORM, and the migrations are applied at the Application Startup.

5. Tests ๐Ÿงช

Unit

Fast and without external dependencies. These tests are focused on the smaller units of code. The Todo Entity and the DomainValidationProvider are unit tested since they don't have extra dependencies to work.

Integration

With dependencies and focused on some internal functionality. In this application context, the Integration Tests are focused on use cases. External dependencies could be mocked or replaced (I'm replacing the Database with an In-memory one).

There are discussions about how many assertions you should have in a test, the boundaries, and soo. Here, following my experience and trying to be very comprehensive in these tests. I'm testing from the input until the persisted data.

End-to-End

These tests focus on test application entry points and returns. To avoid inserting test data into the Database. I'm using an In-memory Database one.

Load

There is a whole separated structure for Load Tests, with containers and tools. The application uses the K6 tool. The K6 idea is to simplify load test where basic JavaScript and HTTP knowledge is sufficient to build load tests.

Results

After executing the Load Tests, you can view results at /tests/CleanArchDotnet.Tests.Load/k6/results folder. The result.json shows a detailed report, and the export.json is a resumed version with a more general view.

Tests Execution

Different from other tests, the Load Tests are executed and analyzed separately.

6. Used Packages, Frameworks, and Tools ๐Ÿ“ฆ

7. Used Patterns and Principles ๐Ÿ“š

clean-architecture-dotnet's People

Contributors

j-didi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.