• Stars
    star
    3,130
  • Rank 14,360 (Top 0.3 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

.NET 8, Angular 18, Clean Architecture, Clean Code, SOLID Principles, KISS Principle, DRY Principle, Fail Fast Principle, Common Closure Principle, Common Reuse Principle, Acyclic Dependencies Principle, Mediator Pattern, Result Pattern, Folder-by-Feature Structure, Separation of Concerns.

ARCHITECTURE

This project is an example of architecture using new technologies and best practices.

The goal is to learn and share knowledge and use it as reference for new projects.

PRINCIPLES and PATTERNS

  • Clean Architecture
  • Clean Code
  • SOLID Principles
  • KISS Principle
  • DRY Principle
  • Fail Fast Principle
  • Common Closure Principle
  • Common Reuse Principle
  • Acyclic Dependencies Principle
  • Mediator Pattern
  • Result Pattern
  • Folder-by-Feature Structure
  • Separation of Concerns

BENEFITS

  • Simple and evolutionary architecture.
  • Standardized and centralized flow for validation, log, security, return, etc.
  • Avoid cyclical references.
  • Avoid unnecessary dependency injection.
  • Segregation by feature instead of technical type.
  • Single responsibility for each request and response.
  • Simplicity of unit testing.

TECHNOLOGIES

RUN

Command Line

Prerequisites

Steps

  1. Open directory source\Web\Frontend in command line and execute npm i.
  2. Open directory source\Web in command line and execute dotnet run.
  3. Open https://localhost:8090.
Visual Studio Code

Prerequisites

Steps

  1. Open directory source\Web\Frontend in command line and execute npm i.
  2. Open source directory in Visual Studio Code.
  3. Press F5.
Visual Studio

Prerequisites

Steps

  1. Open directory source\Web\Frontend in command line and execute npm i.
  2. Open source\Architecture.sln in Visual Studio.
  3. Set Architecture.Web as startup project.
  4. Press F5.
Docker

Prerequisites

Steps

  1. Execute docker compose up --build -d in docker directory.
  2. Open http://localhost:8090.

PACKAGES

Source: https://github.com/rafaelfgx/DotNetCore

Published: https://www.nuget.org/profiles/rafaelfgx

LAYERS

Web: Frontend and Backend.

Application: Flow control.

Domain: Business rules and domain logic.

Model: Data transfer objects.

Database: Data persistence.

WEB

FRONTEND

Service

It is the interface between frontend and backend and has logic that does not belong in components.

export class AppCustomerService { }

Guard

It validates if a route can be activated.

export class AppGuard implements CanActivate { }

ErrorHandler

It provides a hook for centralized exception handling.

export class AppErrorHandler implements ErrorHandler { }

HttpInterceptor

It intercepts and handles an HttpRequest or HttpResponse.

export class AppHttpInterceptor implements HttpInterceptor { }

BACKEND

Controller

It has no any logic, business rules or dependencies other than mediator.

[ApiController]
[Route("customers")]
public sealed class CustomerController : BaseController
{
    [HttpPost]
    public IActionResult Add(AddCustomerRequest request) => Mediator.HandleAsync<AddCustomerRequest, AddCustomerResponse>(request).ApiResult();

    [HttpDelete("{id:long}")]
    public IActionResult Delete(long id) => Mediator.HandleAsync(new DeleteCustomerRequest(id)).ApiResult();

    [HttpGet("{id:long}")]
    public IActionResult Get(long id) => Mediator.HandleAsync<GetCustomerRequest, GetCustomerResponse>(new GetCustomerRequest(id)).ApiResult();

    [HttpGet("grid")]
    public IActionResult Grid([FromQuery] GridCustomerRequest request) => Mediator.HandleAsync<GridCustomerRequest, GridCustomerResponse>(request).ApiResult();

    [HttpGet]
    public IActionResult List() => Mediator.HandleAsync<ListCustomerRequest, ListCustomerResponse>(new ListCustomerRequest()).ApiResult();

    [HttpPut("{id:long}")]
    public IActionResult Update(UpdateCustomerRequest request) => Mediator.HandleAsync(request).ApiResult();
}

APPLICATION

It has only business flow, not business rules.

Request

It has properties representing the request.

public sealed record AddCustomerRequest;

Request Validator

It has rules for validating the request.

public sealed class AddCustomerRequestValidator : AbstractValidator<AddCustomerRequest> { }

Response

It has properties representing the response.

public sealed record AddCustomerResponse;

Handler

It is responsible for the business flow and processing a request to return a response.

It call factories, repositories, unit of work, services or mediator, but it has no business rules.

public sealed record AddCustomerHandler : IHandler<AddCustomerRequest, AddCustomerResponse>
{
    public async Task<Result<AddCustomerResponse>> HandleAsync(AddCustomerRequest request)
    {
        return Result<AddCustomerResponse>.Success(new AddCustomerResponse());
    }
}

Factory

It creates a complex object.

Any change to object affects compile time rather than runtime.

public interface ICustomerFactory { }
public sealed class CustomerFactory : ICustomerFactory { }

DOMAIN

It has no any references to any layer.

It has aggregates, entities, value objects and services.

Aggregate

It defines a consistency boundary around one or more entities.

The purpose is to model transactional invariants.

One entity in an aggregate is the root, any other entities in the aggregate are children of the root.

public sealed class CustomerAggregate { }

Entity

It has unique identity. Identity may span multiple bounded contexts and may endure beyond the lifetime.

Changing properties is only allowed through internal business methods in the entity, not through direct access to the properties.

public sealed class Customer : Entity { }

Value Object

It has no identity and it is immutable.

It is defined only by the values โ€‹โ€‹of its properties.

To update a value object, you must create a new instance to replace the old one.

It can have methods that encapsulate domain logic, but these methods must have no side effects on the state.

public sealed record ValueObject;

Services

It performs domain operations and business rules.

It is stateless and has no operations that are not a part of an entity or value object.

public interface ICustomerService { }
public sealed class CustomerService : ICustomerService { }

MODEL

It has properties to transport and return data.

public sealed record CustomerModel;

DATABASE

It encapsulates data persistence.

Context

It configures the connection and represents the database.

public sealed class Context : DbContext
{
    public Context(DbContextOptions options) : base(options) { }
}

Entity Configuration

It configures the entity and its properties in the database.

public sealed class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
    public void Configure(EntityTypeBuilder<Customer> builder) { }
}

Repository

It inherits from the generic repository and only implements specific methods.

public interface ICustomerRepository : IRepository<Customer> { }
public sealed class CustomerRepository : Repository<Customer>, ICustomerRepository
{
    public CustomerRepository(Context context) : base(context) { }
}

More Repositories

1

DotNetCore

.NET 8 Nuget Packages.
C#
463
star
2

DesignPatterns

The 23 Gang of Four Design Patterns.
C#
149
star
3

SOLID

SOLID is an acronym created by Michael Feathers from the principles of object-oriented programming identified by Robert C. Martin (Uncle Bob).
77
star
4

DDD

Domain-Driven Design is a software development approach in which it utilizes concepts and good practices related to object-oriented programming.
C#
64
star
5

ChatService

ChatService (SignalR).
TypeScript
31
star
6

ObjectOrientedProgramming

Object-Oriented Programming.
C#
23
star
7

MessageBrokerService

MessageBrokerService (RabbitMQ).
C#
21
star
8

GatewayService

GatewayService (Ocelot).
C#
20
star
9

TaskSchedulerService

TaskSchedulerService (Hangfire).
C#
12
star
10

StorageService

StorageService.
C#
12
star
11

DotNetTests

Examples using MSTest and XUnit projects with test libraries (Moq, NSubstitute, FakeItEasy, NBuilder).
C#
11
star
12

Java

API using Java, Spring Boot, Docker, Testcontainers, PostgreSQL, MongoDB, Kafka, LocalStack, SQS, S3, JWT, Swagger.
Java
10
star
13

NotificationService

NotificationService.
C#
8
star
14

Docker

Docker.
PowerShell
8
star
15

RulesEngineService

RulesEngineService.
C#
6
star
16

rafaelfgx

5
star
17

Blockchain

Blockchain.
C#
3
star
18

SagaPattern

Saga Pattern.
C#
3
star
19

Nest

API using Nest, JWT Authentication and Authorization, Swagger, Folder-by-Feature Structure.
TypeScript
2
star
20

Kubernetes

Kubernetes.
JavaScript
1
star
21

FunctionalProgramming

Paradigm that focuses on the use of functions and immutability to write clean and predictable code.
1
star
22

Utils

Utils.
TSQL
1
star