This is an app. That generates surveys. Fake ones. For fun. That is all.
Component(s) | Build Status |
---|---|
Fake Survey Generator API | |
Fake Survey Generator UI | |
Azure Infrastructure |
This is a .NET | C# | React | TypeScript full-stack application of moderate complexity (not just a to-do app), used as a playground for experimentation. Simply put: This is where I mess around with code. It is heavily inspired by the .NET Microservices: Architecture for Containerized .NET Applications book, as well as its companion reference application eShopOnContainers. It also incorporates various elements from different repos & blog posts which served as inspiration.
It is built using Clean Architecture principles with CQRS (Command Query Responsibility Segregation) and DDD (Domain-Driven Design) thrown into the mix. It doesn't follow these principles to the letter, but provides a decent example of how to apply the basics of these principles.
It is heavily centered around the Microsoft .NET + Azure technology stacks as these are what I have the most experience in & just like building things with. 😀
Here are some of the features incorporated into this project:
- Unit & Integration tests for a CQRS/DDD project with XUnit
- Running Unit & Integration tests with Docker Compose
- Using an in-memory database for testing
- Implementing health checks for an ASP.NET Core Web API using AspNetCore.Diagnostics.HealthChecks
- Adding Swagger to an ASP.NET Core Web API using Swashbuckle.AspNetCore
- Adding OpenID Connect for Authentication
- Adding OpenID Connect to Swagger UI
- Securing an ASP.NET Core Web API using JWT Bearer authentication
- Adding security headers to API responses using NetEscapades.AspNetCore.SecurityHeaders
- Using AutoWrapper to return consistent API response models
- Using Hosted Services in ASP.NET Core Web API
- Using a distributed Redis cache
- Configuring SQL Server retry policies
- Using Polly to make resilient HTTP requests
- Implementing Forwarded Headers for hosting ASP.NET Core Web API behind a load balancer
- Validation of commands using FluentValidation
- Configuring Azure Application Insights for telemetry
- Automatic semantic versioning using Nerdbank.GitVersioning
- Creating trusted SSL certificates for HTTPS in development
- Deploying Entity Framework Core Code-First Migrations to Azure SQL Database using Azure Pipelines
- Using Azure Active Directory authentication to Azure SQL Database with Entity Framework Core
- Running a microservice application locally using Docker Compose
- Deploying a microservice application to Kubernetes using Helm charts
- Local Kubernetes development using Skaffold
- Using Azure Pipelines to build & deploy a microservice application to Azure Kubernetes Service
- Using AAD Pod Identity in AKS to associate an Azure Active Directory identity to pods
- Integrating Azure Key Vault with AKS to protect sensitive application configuration using Azure Key Vault Provider for Secrets Store CSI Driver
- Configuring Kubernetes ExternalDNS with Azure DNS for custom domain names in AKS
- Configuring Cert Manager with AKS & Azure DNS for automatic TLS certificates using Let's Encrypt
- Infrastructure as Code for Azure resources using Azure Resource Manager (ARM) templates
Some of the above features are relatively straightforward to implement, others have some intricacies that require some Googling in order to set up. I just like to have them placed in the context of a complete working application to refer back to when necessary.
I wanted something to try new things out on, without the risk of substantially endangering an actual production environment used by actual people.
It was for this reason that I built the Fake Survey Generator (FSG) app as a way to test out tools, libraries, patterns, frameworks & various other stuff.
It has a very simple domain: it generates surveys. Fake ones. They can be used as a tool for helping you decide what to have for dinner, which book you should read next, where you should go for your next team lunch, or anything that tickles your fancy.
This application is also used as a reference for configuring/wiring up some common things I sometimes forget how to do. Living Documentation if you will. You know the culprits: How do I wire up that database again? What is the syntax for that logging configuration? How do I make thing A talk to thing B?
The domain is kept relatively simple such that it doesn't overwhelm the app with unnecessary complexity. It should be quite easy to wrap your head around without requiring a degree in Computer Science.
I also felt that a lot of reference/demo/boilerplate projects out there cover the core application domain & don't go into much detail around the building/deployment/hosting of final application. So this project aims to cover both. It contains application code, configuration, CI/CD pipelines, infrastructure-as-code needed to run the application, as well as a live, running version of the application (as long as budget allows 😁). So this repo hopefully may contain something for everyone & fill in the potential gaps across the whole spectrum of application development. It falls somewhere between a template/boilerplate project & a real-world production open-source application.
FSG consists of two parts:
The server side consists of the following main components:
- Fake Survey Generator API
- Domain Project
- Domain Unit Tests Project
- Infrastructure Project
- Application Project
- Application Tests Project
- API Integration Tests Project
- EF Design Project (used purely for EF Core design-time tooling)
- Data Project (helpers for test data used across test projects)
- Fake Survey Generator Worker
The server side makes use of the following tools, libraries & frameworks:
- Fake Survey Generator API
- .NET 5.0
- ASP.NET Core 5.0 Web API
- Entity Framework Core 5.0 with Code-First Migrations
- Dapper
- Redis
- Swagger
- AutoMapper
- MediatR
- FluentValidation
- Polly
- AspNetCore.Diagnostics.HealthChecks
- Docker
- Serilog
- AutoWrapper
- Fake Survey Generator Worker
- .NET 5.0
- ASP.NET Core 5.0 Worker Service
The client side consists of the following main components:
- UI
The client side makes use of the following tools, libraries & frameworks:
The application is built for Docker, Docker Compose & Kubernetes with Helm. For local development, Docker Compose is used when debugging the application with Visual Studio, and Skaffold is used to package the application into a Helm chart to deploy to a local Kubernetes cluster for running locally.
The hosted version of the application is deployed here: https://aks.fakesurveygenerator.mysecondarydomain.com
The following endpoints are accessible:
- /swagger - The Swagger documentation page for the API
- /health/live - Health Checks endpoint used by Kubernetes liveness probe
- /health/ready - Health Checks endpoint used by Kubernetes readiness probe
The hosted version utilizes the following infrastructure:
- Azure Kubernetes Service
- Azure SQL Database
- Azure Cache for Redis
- Azure Container Registry
- Azure Key Vault
- Azure Application Insights
- Azure DNS
- Azure DevOps (for CI/CD)
The application makes use of OpenID Connect for authentication which is implemented by Auth0. Currently supported connections are:
- Auth0
- Microsoft
Initially, this project used IdentityServer for authentication, but I didn't feel like maintaining the separate IdentityServer project as well as the Fake Survey Generator, so I switched it out for Auth0 because authn/authz is hard and I prefer to delegate that responsibility to the people who know how to do it properly. 😁
In order to run FSG on your local machine, you will need the following prerequisites:
To run with Docker Compose:
- Docker Desktop
- mkcert - To generate SSL certificates for local development
- Visual Studio (optional)
-
After installing mkcert, run:
mkcert localhost
in thecerts
directory to create the localhost development certificates. If successful, the following will be printed:The certificate is at "./localhost.pem" and the key at "./localhost-key.pem"
-
In a Terminal/Command Prompt/PowerShell window in the project root, run:
docker-compose up
-
In a browser, navigate to https://localhost:3000 to open up the Fake Survey Generator UI
or
-
Open
FakeSurveyGenerator.sln
in Visual Studio: -
Make sure that the
docker-compose
project is selected as the startup project -
Hit
F5
to debug the application, orCtrl
+F5
to run without debugging -
In a browser, navigate to https://localhost:3000 to open up the Fake Survey Generator UI
To run on local Kubernetes:
- Docker Desktop with Kubernetes enabled (Ensure that at least 2048 MB of Memory is allocated to Docker Engine)
- NGINX Ingress Controller installed on the Kubernetes cluster
- Skaffold
To deploy to a local Kubernetes cluster:
-
Create an entry in your
hosts
file as follows:127.0.0.1 k8s.local
-
In a Terminal/Command Prompt/PowerShell window in the project root, run:
skaffold run
-
In a browser, navigate to https://k8s.local to open up the Fake Survey Generator UI
If you find a bug, want to add a feature, or want to improve the documentation, open up a PR!
My deepest thanks to all the people who provided these resources as reference: