ShawnShiSS / clean-architecture-azure-cosmos-db

A starting point to build a web API to work with Azure Cosmos DB using .NET 5 and Azure Cosmos DB .NET SDK V3, based on Clean Architecture and repository design pattern. Partition key is also implemented through the repository pattern.
MIT License
346 stars 95 forks source link
asp-net-core asp-net-core-cosmos-db azure-functions clean-architecture clean-architecture-cosmos-db cosmos-db cosmos-db-sdk-v3 dotnet5 material-ui nswagstudio partition-key partitioning react repository-pattern typescript

Clean Architecture with partitioned repository pattern using Azure Cosmos DB

UPDATE: all projects in this soluction have been updated to .NET 5. Azure Functions project is updated to the newest v4.

This solution provides a starting point to build a web API to work with Azure Cosmos DB using .NET 5 and Azure Cosmos DB .NET V3, based on Clean Architecture and repository design pattern.

Clean Architecture is promoted by Microsoft on their .NET application architecture guide page. The e-book written by Steve "ardalis" Smith (@ardalis) is beautifully written and well explains the beauty and benefits of using Clean Architecture. For more details, please see Architect Modern Web Applications with ASP.NET Core and Azure.

This project uses the newer Cosmos DB .NET SDK V3, because it adds support for stream APIs and Cosmos DB Change Feed processor APIs, as well as performance improvements.

(NEW) Azure Functions starter project

(NEW) Auditing feature

(NEW) React Client Web Application

(NEW) Token Service Provider

System Design Diagram

Give a star

:star: If you enjoy this project, or are using this project to start your exciting new project, or are just forking it to play, please give it a star. Much appreciated! :star:

Goals

The primary goal of the project is to provide a basic solution structure for anyone who is building a new ASP.NET Core web or API project using Cosmos DB.

For a detailed introduction, please see my recent article, Clean Architecture — ASP.NET Core API using Partitioned Repository Pattern and Azure Cosmos DB.

Getting Started - API

  1. Download the Azure CosmosDB emulator in order to run the API project locally. Here is a download link: https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator-release-notes#download.
  2. Start the emulator
  3. Set the API project as your Startup project in Visual Studio
  4. The swagger UI page should be loaded at: https://localhost:5001/swagger/index.html
  5. Running the API project will automatically ensure Cosmos DB containers are created and also seed application data. See Startup.cs and DatabaseConfig.cs in API project for details.
  6. Running the API project will automatically ensure ASP.NET Core Identity database is created and also seed application user data. See Startup.cs and DatabaseConfig.cs in API project for details.

Getting Started - Client Application

Because the client web application is built using React and TypeScript, you need a couple of things below installed on your machine.

Prerequisites:

  1. Open folder src/CleanArchitectureCosmosDB.ClientApp in Visual Studio Code
  2. Open Terminal
  3. Run command "yarn install"
  4. Run command "yarn start"
  5. You should see the web app running on localhost:3000

Features supported

New Features Under Development

Additional Resources

I have published some short articles to cover different aspects of this project. Please feel free to give them a read.

Acknowledgement

Special thanks to Steve Smith (@ardalis) for sharing the CleanArchitecture repository and the e-book. I absolutely love it!

Thanks to Azure-Samples/PartitionedRepository for sample code using Cosmos DB .NET SDK V2, which helped me understand Cosmos DB .NET SDK V2 and compare SDK V2 against V3.