• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

A project that exemplifies a well-considered architectural approach that combines the advantages of both monolithic and microservices paradigms, fostering modularity, maintainability, and scalability.

The project has been developed using .NET 7, demonstrating a fusion of monolithic architecture principles with microservices methodologies. It follows a structured approach, segmenting the project into distinct domains to achieve a well-organized and scalable system.

My Medium article that references this repository

The example undertaking comprises of both users and their corresponding tasks. A user is described by an id, a status, as well as their first and last name. A user's task is outlined by an id, a status, a title, a description, an author (the user), and potentially an assigned user identification number.

Run application

To execute the project, you must ensure that Docker is properly installed. Subsequently, you can initiate the project by executing the following command from the project's root directory:

docker-compose up

To avoid using a cached version, simply include the --build --force-recreate arguments when running the command. Please be aware that these arguments will reset all contents within the Docker image.

This command will initialize the API, the background worker, and a SQL Server database. The API will be accessible on port 80, and the Hangfire dashboard will be accessible on port 81.

If you prefer to selectively run specific services, such as just the SQL Server database, you can achieve this by executing the following command:

docker-compose start db

Before commencing the API, it is crucial to verify the creation of databases and the successful execution of migrations. After successfully setting up the database, two databases should be established:

  1. One database is designated for the API and is typically named 'app' by default in the appsettings.json file. You have the flexibility to change this name as necessary.
  2. Another database is allocated for the Background worker, and it is typically named 'jobs' in the appsettings.json file. You can adjust this name to suit your requirements.

Once the databases are established, it's essential to apply the necessary migrations. This can be accomplished by navigating to the DataModel directory and executing the subsequent command:

dotnet ef database update

Please ensure that you have correctly configured the ASPNETCORE_ENVIRONMENT environment variable to correspond with the appropriate appsettings configuration. To use the default configuration, set the environment variable to "Development".

Project structure

The project has been structured into different domains:

Overall, the project exemplifies a well-considered architectural approach that combines the advantages of both monolithic and microservices paradigms, fostering modularity, maintainability, and scalability.

The project leverages essential external dependencies:

  • Ulid: This library provides unique identifiers that serve as primary keys in the database, contributing to data integrity and accuracy.
  • Mediatr: As an in-process messaging framework, Mediatr streamlines communication between components, minimizing dependencies and enhancing efficiency.
  • FluentValidation: By ensuring proper validation of incoming requests, FluentValidation contributes to the reliability of the application's data handling.
  • Hangfire: Permits the application to execute background processing essential for event management.

Generating strongly typed ids

A distinctive aspect of the project is the use of strongly typed IDs, which are employed as unique identifiers throughout the database. These IDs are prefixed with the corresponding domain abbreviation, mitigating potential errors when dealing with foreign keys and database joinsโ€”drawing inspiration from the concept of Stripes object IDs.

Api

Serving as the primary interface for the application, the API is built using .NET and is responsible for routing incoming requests. This involves directing requests to their respective handlers within the "Components" section. Additionally, the "Api" domain encompasses the creation of Data Transfer Objects (DTOs) that bridge the gap between the API and the components, along with filters like action and authorization filters, if needed.

It consists of the following:

  • Controllers: Exposing api routes and directing routes to the different handlers in components
  • Dtos: If some DTOs differs from the requests/responses in components
  • Filters: In case filters are needed (e.g. action-, authorization-filters, etc.)

Components

At the heart of the application's business logic, the "Components" domain handles all CRUD (Create, Read, Update, Delete) operations. This domain is subdivided into queries (for read operations) and commands (for write operations), adhering to the principles of Command Query Responsibility Segregation (CQRS).

DataModel

Within this section, the application's data structures and relationships are defined. This underpins the database schema and the models that interact with the data.

Events

Events, encapsulated as event models or objects, facilitate communication across the application's various components. By utilizing an "IEvent" interface, events are decoupled from specific components and can trigger actions more flexibly.

EventHandlers

Event handlers play a crucial role in responding to events propagated within the application. Through the use of an "IEventHandler" interface, these handlers execute specific actions in response to events, fostering loose coupling between different parts of the system.

Infrastructure

The "Infrastructure" section addresses cross-cutting concerns and setup tasks. This includes implementing authentication, Cross-Origin Resource Sharing (CORS), middleware, and more. Notably, the infrastructure layer incorporates the concepts of CQRS, employing a mediator, command, query, and event bus pattern to facilitate communication and interaction between components.

Lastly, the inclusion of Swagger for API documentation enhances the project's usability and developer experience by providing clear insights into the API's structure and endpoints.

BackgroundWorker

A background worker serves the purpose of event management. Events are employed to manage side effects, and consequently, we aim to prevent events from obstructing endpoint execution. In this project, Hangfire is employed, and to reduce the workload on the API instance, it has been relocated to a separate instance. This can be effortlessly accomplished by leveraging the infrastructure to configure its dependencies.

More Repositories

1

NetCoreMicroservicesSample

Sample using micro services in .NET Core 3.1 Focusing on clean code
C#
695
star
2

keybindings

Remap arrow keys to ijkl and make use of caps lock
AutoHotkey
216
star
3

docker-cloud-media-scripts

Upload and stream media from the cloud with or without encryption. Cache all new and recently streamed media locally to access quickly and reduce API calls
Shell
100
star
4

cloud-media-scripts

Upload and stream media from the cloud with or without encryption. Cache all new and recently streamed media locally to access quickly and reduce API calls
Shell
88
star
5

RadarrSonarrPlex

View and manage your movies and series in Radarr and Sonarr directly in the Plex app
TypeScript
14
star
6

NetCoreGraphQLSample

Sample using GraphQL implemented in .NET Core by using graphql-dotnet identityserver4, background workers, real-time metrics, monitoring, logging, validations and more
C#
9
star
7

sonarr-pogdesign-importer

Scrapes pogdesign and trakt for new tv series and import them to Sonarr
TypeScript
8
star
8

DotNetBaseSample

Template to get started with a simple .NET 5 API including CQRS including event based models as well
C#
7
star
9

Media-frontend

Web application for a quick overview for sabNZBD, NzbDrone, CouchPotato
CSS
5
star
10

NetCoreEventSourceSample

.Net Core 3.1 with CQRS and event source
C#
5
star
11

knowledge-quiz-api

C#
4
star
12

plex-sync-scripts

Sync watch status between Plex servers
3
star
13

create-react-app-ts-redux-hmr

Create-react-app with Typescript Redux and HMR
JavaScript
2
star
14

react-webpack2-typescript

React+Redux with Webpack 2 and Typescript
TypeScript
2
star
15

serverpage

Serverpage for get a quick overview for sabnzbd, xbmc, couchpotato and sickbeard. Using couchbeard-plugin.
1
star
16

React-Mobx-with-Webpack-2-and-Typescript

React+Mobx with Webpack 2 and Typescript
TypeScript
1
star
17

cryptanalysis

01435: Practical Cryptanalysis
C++
1
star
18

serverless-aws-node-sample

Serverless AWS Lambda NodeJS sample
TypeScript
1
star
19

visual-studio-code-key-bindings

Visual Studio Code key bindings
Lua
1
star
20

sveltekitsample

Svelte-kit sample WIP
JavaScript
1
star
21

BingoBanko

Bingo banko auto checker
Java
1
star
22

couchbeard-plugin

Wordpress plugin to access xbmc, couchpotato, sickbeard and sabnzbd functionality
CSS
1
star