Skip to content

Jackpieking/ASPNET_CORE_VSA_Template

Repository files navigation

ASPNET_CORE_VSA_Template

TL;DR

  • The ASP.NET Core template follows the Vertical Slice Architecture (VSA).

  • Please leave everything as default in order to make the scripts work or check out how to customize scripts Here.

  • For explanations about idea and structure of template, please check out Here

  • For more information about each config file, please check out Here

  • For how to start the project, please check out Getting Started

  • For the detail about the features I build on this template, please download and check out this Excel File or take a look at this image below:

FeatManagementDoc

Introduction

Welcome to the ASP.NET Core Vertical Slice Architecture Template! This template helps you build maintainable, scalable, and testable web applications by organizing code around business features. It addresses the challenges of traditional layered architectures, such as bloated controllers and scattered code, by promoting a modular and feature-centric approach.

Demo video of how to apply this template to your project

Coming soon

Context

I used to build projects by following tutorials, but their suggested structures caused problems. I struggled with:

  • Massive service files: These became unwieldy and hard to maintain as they grew.
  • Dispersed context: It was difficult to find all the pieces of a feature because they were scattered across different files and folders.
  • Overloaded controllers: Controllers became bloated and hard to manage.

This traditional, technical-based architecture, which groups files by type (e.g., all services in a Services folder), seemed organized at first, but it became inefficient. I then explored feature-based architecture, which offers:

  • Clearer organization: Each feature gets its own folder, making navigation easier.
  • Simplified maintenance: All related files are together.

However, feature-based architecture also presented challenges as projects scaled:

  • Class naming collisions: With many feature-related classes, it was easy to mix up or mistype names (e.g., FM1Endpoint vs. FM2Endpoint).

To address this, I moved each feature into its own assembly (class library). This prevents accidental calls between features, as you must explicitly reference the correct assembly (e.g., you can't call FM1Endpoint from the FM2Endpoint assembly). This also allows for simpler, more consistent naming within each feature, eliminating the need for feature prefixes (e.g., FM1Endpoint becomes simply Endpoint).

While this could lead to duplicate class names across libraries, this is easily resolved by using the full class name (namespace + class). For example:

I have 2 classes that have the same name like this:

Duplicate Class Name

I can decide which one to use by writing the full class name, like this:

System.Reflection.Metadata.Constant

Beside, you can check out for more things related to this template:

  • Explanations about idea and structure of template: Here

  • Detail of each config files: Here

  • How to customize scripts that are used to support for this project: Here

  • For the detail about the features I build on this template, please download and check out this Excel File or take a look at this image below:

FeatManagementDoc

Getting Started

Prerequisites

Ensure you have the following installed:

  • .NET SDK 8.0.404

  • Docker (Any version but at least 20.10.17)

    • please make sure it supports docker compose
  • Text editor (Vs code, fleet,..) or IDE (Visual Studio 2022, Rider, ...)

Installation

Clone this project via this command:

git clone https://github.com/Jackpieking/ASPNET_CORE_VSA_Template.git

Usage

1. Navigate to the root of the template

  • Windows

cd E:\CODE_PROJECTS\ASPNET_CORE_VSA_Template\
  • Mac/Linux

cd /home/CODE_PROJECTS/ASPNET_CORE_VSA_Template/

2. Install necessary dotnet tool via this script:

  • Windows

.\Scripts\Init\init.ps1
  • Mac/Linux

./Scripts/Init/init.sh

3: Update the HOST_IP var in .env file in ./AppInfrastructure folder (docker stack)

For example:

Currently, in .env there is a section at the top expressing docker server IP:

# ======================
# GLOBAL
# ======================
HOST_IP=192.168.56.104

But your docker server IP is 192.168.1.10, so you must change it to:

# ======================
# GLOBAL
# ======================
HOST_IP=192.168.1.10

4: Run docker compose by following command, make sure to stand in ./AppInfrastructure folder:

docker compose up -d --build

you can confirm the results by running the following command:

docker ps

It should give out an image like this:

Docker Running Successfully

5: Find and update the all parts that have IP in all files that start with appsettings in Src/Entry folder

For example:

Currently, in appsettings.Development.json in Src/Entry ther was a connection string for postgressql database like this:

"Database": {
    "Main": {
      "ConnectionString": "Server=192.168.56.104; Port=6102; Database=todoappdb; User ID=admin; Password=Admin123@; SSL Mode=Prefer; Pooling=true; Minimum Pool Size=64; Maximum Pool Size=120; Connection Idle Lifetime=300; Connection Lifetime=500",
      // ... other settings
    }
  }

The current postgres server IP is 192.168.56.104, but your server IP is 192.168.1.10, so you must change it to:

"Database": {
    "Main": {
      "ConnectionString": "Server=192.168.1.10; Port=6102; Database=todoappdb; User ID=admin; Password=Admin123@; SSL Mode=Prefer; Pooling=true; Minimum Pool Size=64; Maximum Pool Size=120; Connection Idle Lifetime=300; Connection Lifetime=500",
      // ... other settings
    }
  }

6. Run the project via this script:

  • Windows

.\Scripts\Run\run.ps1
  • Mac/Linux

./Scripts/Run/run.sh

After script runs successfully, you are going to see the result like this:

  • On terminal: Run-On-Terminal-Result

  • Click the link http://localhost:5245, a swagger page is going to pop up for API testing purpose. Swagger-Page

Other usage

1. Build the project via this script:

  • Windows

.\Scripts\Build\build.ps1
  • Mac/Linux

./Scripts/Build/build.sh

2. Test the project via this script:

  • Windows

.\Scripts\Test\test.ps1
  • Mac/Linux

./Scripts/Test/test.sh

--> The result will be in TestResults folder, the content inside will be always the newest.

TestResult folder image

3. Publish the project via this script:

  • Windows

.\Scripts\PublishApp\publish.ps1
  • Mac/Linux

./Scripts/PublishApp/publish.sh

--> The result will be in out folder, the content inside will be always the newest.

Out folder image

4. Clean the project via this script:

  • Windows

.\Scripts\Clean\clean.ps1
  • Mac/Linux

./Scripts/Clean/clean.sh

License

This project is licensed under the MIT License, allowing you to freely use, modify, and distribute it under the terms of the license.

Contact

Please submit any problems or questions related to this project on GitHub issues.

About

ASP.NET Core projects follows the Vertical Slice Architecture

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published