This is a template to set up a backend ASP.NET Core project with React frontend. You could check it out at https://template.mcc-soft.de (credentials: admin/BSjo1M8jU760).
Developers are encouraged to start with setting up the environment and proceed to development how-to.
Template contains (you could also check CHANGELOG for latest changes):
- ASP.NET Core backend (.NET 8)
- OpenIddict authentication (with support for Social Networks authentication)
- Guidance/example on how to structure backend
- Helpers for easy implementation of REST API for CRUD (with PATCH instead of UPDATE)
- Configured Domain events to apply DDD principles
- Localization (i18next), background jobs (Hangfire), etc.
- Audit logging for DB entities
- Logging via Serilog to:
- OpenSearch (credentials: backend-frontend-template/$a55IVHBhAJ@)
- Loggly (free up to 250MB/day). You could check out logs yourself (credentials: mcc.template.app@gmail.com/dBAeFm7_y5mq3)
- React frontend
- Vite-based template
- API client autogeneration (including react-query hooks)
- UI Kit to simplify app restyling
- Guidance/examples on setting up forms (react-hook-form), tables (with sorting/paging) and filters
- Support for injecting environment variables (without rebuilding the app)
- Redux with persistence
- Routing with react-router
- Error-boundaries which works with suspense/react-query/code splitting
- Pre-built authentication UI
- Build-script to build a single Docker container from backend and frontend
- package.json based build script (just run
yarn build
from repo root)
- package.json based build script (just run
- Azure-pipelines CI script which
- Builds Docker Image
- Uploads it to Container Registry (on Digital Ocean)
- Deploys Image to preconfigured agent
- Instructions about configuring an agent to deploy aforementioned Docker Image on any linux PC (Digital Ocean prefered :))
- Kubernetes deployment files and guidance regarding deploy to kubernetes (in progress)
Before using the template for your brand-new app run yarn rename -n YourProjectName
. Additionally you can use -c YourCompanyName
to change solution's root namespace. Use CamelCase for your project name. The script does the following (you could check the script and do this manually if you like to):
- Rename all files/folders from 'TemplateApp' to your project name.
- Change all namespaces, classnames, database names, dockerfiles and deployment scripts to suit your project
- Adjust SPA port number to something random, so that it doesn't clash with other projects (in package.json: 'start' script, PORT=3011; in main app .csproj: `http://localhost:3011/)
Create a new git repository and copy everything (except .git
folder) to it. Don't forget to change the favicons/tiles in frontend/public
folder to the logo of your project (use https://realfavicongenerator.net/ to create favicons in all required sizes)
- Check that connection string in appsettings is correct. Default connection string assumes that you have Postgres running on localhost on standard port with user/pass: postgres/postgres. Adjust connection string if the assumption is wrong.
- Make sure the target database exists (or that the postgres user has rights to create databases).
- Run backend (Open
webapi/MccSoft.TemplateApp.sln
in Rider/Visual Studio and hitF5
) - Run frontend (
yarn start
fromfrontend
folder) - Frontend will open up in browser. Use that url to test the app!
- (To authorize, you could use a preconfigured user. Login/Password is in
appsettings.json
underDefaultUser
section)
- First of all, you need to create an email for your project. It will be needed for registering in 3rd party systems that the project will use (e.g. Sentry and Loggly)
- Go to Azure and create Pipeline. Specify
.ci/azure-pipelines.yml
as the source of pipeline. - Set up Container Registry to push images to.
- You could use GitLab Container Registry (since it's private and free)
- Register a user in GitLab (using project email)
- Create a personal access token with read/write access to container registry at https://gitlab.com/-/profile/personal_access_tokens
- Add secret variable
DOCKER_TOKEN
to a pipeline (with value generated on previous step) - Adjust
DOCKER_REGISTRY
(e.g.registry.gitlab.com/mcctemplateapp1/main
) andDOCKER_USER
(e.g.mcc.template.app@gmail.com
) variables in pipeline.
- You could use GitLab Container Registry (since it's private and free)
- (optional) If you want to add git Tags to your sourcecode when deploying to DEV/PROD, you need to do the following:
- Give access for WRITING to Repo for your Pipeline. Instructions: https://elanderson.net/2020/04/azure-devops-pipelines-manual-tagging/
- Set TAG_SOURCES_DEV and TAG_SOURCES_PROD variables in base.partial.yml.
- Run your pipeline. The first Stage (build) should pass.
- Disable Pipeline notifications in Azure (i.e. 'Run stage waiting for approval' and 'Manual validation Pending') https://dev.azure.com/mccsoft/TemplateApp/_settings/notifications. Also disable them in your personal profile: https://dev.azure.com/mccsoft/_usersSettings/notifications
- Pipeline contains 2 stages for deploying to DEV and PROD. You could add new deployment stages by copying existing once.
Here are the possible ways to deploy your app:
- Kubernetes (k3s) on VM. It is the preferred and simplest deployment setup. Read the details in the instructions.
- For low workloads you could host App & Postgres together on 1CPU/2GB VPS together (~5$ on Hetzner/MVPS)
- Azure Web App. It's simple, use it if you already use Azure and are ok with paying quite a bit more than for a regular VM (5x more :))
- [Obsolete] Docker-compose on VM. This is an obsolete way, instructions are available for backwards compatibility. It's NOT recommended for new projects, and even old ones should better switch to Kubernetes (k3s) :).