Engrslan.SME.DDD 1.0.0-beta3

This is a prerelease version of Engrslan.SME.DDD.
dotnet new install Engrslan.SME.DDD::1.0.0-beta3
                    
This package contains a .NET Template Package you can call from the shell/command line.

Important Note: This repository is under active development. Expect frequent changes, and use it at your own discretion.

๐Ÿ—๏ธ SME DDD Pattern Template

A comprehensive Domain-Driven Design (DDD) pattern template for building scalable, maintainable enterprise applications with .NET 9 and Angular 19.

.NET 9 Angular 19 TypeScript License

๐Ÿ“‘ Table of Contents

๐Ÿ“œ License

This template is FREE to use for your projects, but commercial resale is restricted. See LICENSE.md for details.

โœ… You CAN: Use it for commercial projects, client work, modify it freely
โŒ You CANNOT: Sell or resell this template without permission

๐ŸŽฏ Overview

This template provides a production-ready foundation implementing Domain-Driven Design patterns with clean architecture principles. It combines the power of .NET 9 backend with Angular 19 frontend, offering a complete full-stack solution for enterprise applications.

Key Highlights

  • Clean Architecture with clear separation of concerns
  • OpenIddict OAuth2/OpenID Connect authentication
  • Entity Framework Core with SQL Server
  • Angular 19 with standalone components
  • Serilog structured logging
  • Health Checks for production monitoring
  • CORS support for cross-origin requests
  • Role-based access control directives

๐Ÿš€ Features

Backend (.NET 9)

Domain Layer
  • โœ… Entities and Value Objects
  • โœ… Aggregates and Aggregate Roots
  • โœ… Domain Events with Light Event Bus
  • โœ… Domain Services
  • โœ… Repository Interfaces
  • โŒ Specifications Pattern (Planned)
Application Layer
  • โœ… Application Services
  • โœ… DTOs and Mapping
  • โŒ CQRS Pattern (Planned)
  • โœ… FluentValidation Integration
  • โœ… Event Handlers
  • โœ… Use Case Implementation
Infrastructure Layer
  • โœ… Entity Framework Core 9
  • โœ… Generic Repository Pattern
  • โœ… Unit of Work Pattern
  • โœ… Database Migrations
  • โœ… SQL Server Integration
  • โœ… External Service Integration
Identity & Security
  • โœ… OpenIddict Integration
  • โœ… OAuth2/OpenID Connect
  • โœ… JWT Token Authentication
  • โœ… Role-based Authorization
  • โœ… CORS Configuration
  • โœ… Secure Token Storage
API Layer
  • โœ… RESTful API Design
  • โœ… Swagger/OpenAPI Documentation
  • โœ… Health Check Endpoints
  • โœ… Structured Logging with Serilog
  • โœ… Global Exception Handling
  • โœ… API Versioning Ready

Frontend (Angular 19)

Core Features
  • โŒ Standalone Components (Using Modules)
  • โœ… OAuth2/OIDC Authentication
  • โœ… Auth Guards and Interceptors
  • โœ… Role-based Directives
  • โœ… Reactive Forms
  • โœ… State Management Ready
UI Components
  • โœ… Responsive Landing Page
  • โœ… Dashboard with Role-based Access
  • โœ… Authentication Callback Handler
  • โœ… Navigation with Smooth Scrolling
  • โœ… Modern UI with SCSS
  • โœ… Mobile-responsive Design
Security & Performance
  • โœ… Token Refresh Management
  • โœ… Silent Token Renewal
  • โœ… Lazy Loading Ready
  • โœ… Production Build Optimization
  • โœ… PWA Ready Structure

๐Ÿ› ๏ธ Technology Stack

Backend

  • .NET 9.0 - Latest .NET framework
  • Entity Framework Core 9 - ORM
  • OpenIddict - OAuth2/OpenID Connect server
  • SQL Server - Database
  • Serilog - Structured logging
  • FluentValidation - Input validation
  • Fast Endpoints - RESTful API Engine

Frontend

  • Angular 19 - Frontend framework
  • TypeScript 5.6 - Type-safe JavaScript
  • RxJS - Reactive programming
  • SCSS - Styling
  • โŒ Design System (Not implemented. use your preferred design system)
  • OIDC Client - OAuth2/OIDC authentication

DevOps & Tools

  • Docker - Containerization ready
  • โŒ GitHub Actions (Not implemented)
  • Swagger/OpenAPI - API documentation
  • Scaler - OpenAPI Explorer
  • Health Checks - Production monitoring

๐Ÿšฆ Getting Started

Prerequisites

๐Ÿ“ฆ Template Installation

Install as .NET Template

  1. Install from NuGet

    dotnet new install Engrslan.SME.DDD
    
  2. Install from Local Source

    # Clone the repository
    git clone https://github.com/EngRslan/ddd-pattern-template.git
    cd ddd-pattern-template
    
    # Install the template locally
    dotnet new install .
    

Create New Project from Template

# Create with default settings
dotnet new engrslan-ddd -n YourProjectName

# Create with custom options
dotnet new engrslan-ddd -n YourProjectName \
  --UseAngular true \
  --UseDocker true \
  --IncludeSampleCode true \
  --UseIdentity true \
  --EnableHealthChecks true \
  --skipRestore false

Template Parameters

Parameter Type Default Description
--UseAngular bool true Include Angular frontend application with OIDC authentication, dashboard, and role-based directives
--UseDocker bool true Include Docker support with Dockerfile and docker-compose configurations
--IncludeSampleCode bool true Include sample entities, services, DTOs, and validators to demonstrate DDD patterns
--UseIdentity bool true Include OpenIddict Identity Server for OAuth2/OpenID Connect authentication
--EnableHealthChecks bool true Enable health check endpoints for production monitoring
--skipRestore bool true Skip automatic restore of NuGet and npm packages during project creation

Template Usage Examples

dotnet new engrslan-ddd -n MyApp

Creates a complete DDD application with Angular frontend, Identity Server, Docker support, sample code, and health checks.

API-Only (No Frontend)
dotnet new engrslan-ddd -n MyApi --UseAngular false

Creates a backend-only API without the Angular frontend.

Clean Template (No Samples)
dotnet new engrslan-ddd -n MyApp --IncludeSampleCode false

Creates the template structure without sample entities and services.

Minimal API (No Identity, No Docker)
dotnet new engrslan-ddd -n MyMinimalApi \
  --UseAngular false \
  --UseDocker false \
  --UseIdentity false \
  --IncludeSampleCode false

Creates a minimal DDD API without authentication, frontend, or containerization.

Auto-Restore Dependencies
dotnet new engrslan-ddd -n MyApp --skipRestore false

Automatically restores NuGet packages and runs npm install after project creation.

Post-Installation Steps

After creating a project from the template:

  1. Update the namespace - The template will rename Engrslan to your project name automatically
  2. Configure connection strings - Update database connections in appsettings.json files
  3. Run database migrations - Apply EF Core migrations to create the database schema
  4. Configure CORS - Update allowed origins for your environment
  5. Start development - Run Identity Server and API Host projects

Installation

  1. Create a new project from template

    # If template is already installed
    dotnet new engrslan-ddd -n YourProjectName
    cd YourProjectName
    
  2. Setup the database

    # Update connection strings in appsettings.json files
    
    # Create initial migration for Application DbContext
    cd src/HttpApi.Host
    dotnet ef migrations add Initial -c ApplicationDataContext -p ../EfCore -s .
    
    # Apply migrations to create the database
    dotnet ef database update -c ApplicationDataContext
    
  3. Install dependencies

    # Backend dependencies (if not auto-restored)
    dotnet restore
    
    # Frontend dependencies
    cd src/HttpApi.Host/ClientApp
    npm install
    
Option 2: Clone from GitHub
  1. Clone the repository

    git clone https://github.com/EngRslan/ddd-pattern-template.git
    cd ddd-pattern-template
    
  2. Setup the database

    # Update connection strings in appsettings.json files
    
    # Create initial migration for Application DbContext
    cd src/HttpApi.Host
    dotnet ef migrations add Initial -c ApplicationDataContext -p ../EfCore -s .
    
    # Apply migrations to create the database
    dotnet ef database update -c ApplicationDataContext
    
  3. Install dependencies

    # Backend dependencies
    dotnet restore
    
    # Frontend dependencies
    cd src/HttpApi.Host/ClientApp
    npm install
    
Running the Application
  1. Run the Identity Server (if using Identity)

    cd src/Identity
    dotnet run
    # Identity server will run on https://localhost:{{generated}}
    
  2. Run the API Host

    cd src/HttpApi.Host
    dotnet run
    # API will run on https://localhost:{{generated}}
    # Angular app will run on http://localhost:4200
    

Development

Backend Development
# Run with hot reload
dotnet watch run --project src/HttpApi.Host

# Run tests
dotnet test

# Add migration
dotnet ef migrations add MigrationName -c ApplicationDataContext -p src/EfCore -s src/HttpApi.Host

# Update database
dotnet ef database update -c ApplicationDataContext -p src/EfCore -s src/HttpApi.Host
Frontend Development
cd src/HttpApi.Host/ClientApp

# Development server
npm start

# Run tests
npm test

# Build for production
npm run build

# Lint
npm run lint

Configuration

Connection Strings

Update connection strings in:

  • src/HttpApi.Host/appsettings.json
  • src/Identity/appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=DddTemplate;Trusted_Connection=true;TrustServerCertificate=true;"
  }
}
CORS Settings

Configure allowed origins in appsettings.json:

{
  "AllowedOrigins": ["http://localhost:4200", "https://yourdomain.com"]
}

๐Ÿ“– Usage

Creating a New Entity

  1. Define the entity in Domain layer

For simple entities:

public class Product : Entity<Guid>
{
    public string Name { get; private set; }
    public decimal Price { get; private set; }
    
    public Product(string name, decimal price)
    {
        Name = name;
        Price = price;
    }
}

For aggregate roots with domain events and auditing:

public class Order : FullAuditedAggregateRoot<Guid>
{
    public string OrderNumber { get; private set; }
    public decimal TotalAmount { get; private set; }
    public OrderStatus Status { get; private set; }
    private readonly List<OrderItem> _items = new();
    public IReadOnlyCollection<OrderItem> Items => _items.AsReadOnly();
    
    public Order(string orderNumber)
    {
        OrderNumber = orderNumber;
        Status = OrderStatus.Pending;
        
        // Raise domain event
        AddDomainEvent(new OrderCreatedEvent(Id, orderNumber));
    }
    
    public void AddItem(Product product, int quantity)
    {
        var item = new OrderItem(product.Id, product.Name, product.Price, quantity);
        _items.Add(item);
        TotalAmount = _items.Sum(x => x.Price * x.Quantity);
        
        // Raise domain event
        AddDomainEvent(new OrderItemAddedEvent(Id, product.Id, quantity));
    }
    
    public void Complete()
    {
        Status = OrderStatus.Completed;
        AddDomainEvent(new OrderCompletedEvent(Id, TotalAmount));
    }
}
  1. Create repository interface
public interface IProductRepository : IRepository<Product, Guid>
{
    Task<Product> GetByNameAsync(string name);
}
  1. Implement repository in Infrastructure layer
public class ProductRepository : Repository<Product, Guid>, IProductRepository
{
    public async Task<Product> GetByNameAsync(string name)
    {
        return await FirstOrDefaultAsync(p => p.Name == name);
    }
}

Using Role-Based Directives


<div *appHasRole="'Admin'">
  Admin only content
</div>


<button *appHasAnyRole="['Admin', 'Manager']">
  Management Action
</button>


<div *appHasNotRole="'Guest'">
  Premium content
</div>

๐Ÿงช Testing

Unit Tests

dotnet test tests/Domain.Tests
dotnet test tests/Application.Tests

Integration Tests

dotnet test tests/HttpApi.Tests

Frontend Tests

cd src/HttpApi.Host/ClientApp
npm test
npm run test:coverage

๐Ÿ“Š Health Checks

The application includes comprehensive health checks:

  • /health - Overall health status
  • /health/ready - Readiness probe
  • /health/live - Liveness probe

๐Ÿ”’ Security

Authentication Flow

  1. User clicks login โ†’ Redirected to Identity Server
  2. User authenticates โ†’ Identity Server issues tokens
  3. Tokens stored in browser โ†’ Used for API calls
  4. Silent renewal โ†’ Tokens refreshed automatically

Security Best Practices

  • โœ… HTTPS enforced in production
  • โœ… CORS properly configured
  • โœ… JWT tokens with expiration
  • โœ… Role-based authorization
  • โœ… Input validation with FluentValidation
  • โœ… SQL injection protection with EF Core
  • โœ… XSS protection in Angular

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

How to Contribute

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow DDD principles and clean architecture
  • Write unit tests for new features
  • Update documentation as needed
  • Follow existing code style and conventions
  • Ensure all tests pass before submitting PR

๐Ÿ“š Documentation

๐Ÿ“ Roadmap

  • Support Permission-Based Access Control
  • Add API Versioning
  • Add Rich Documentation
  • Add Core Unit Tests
  • Add message queue integration (RabbitMQ/Azure Service Bus)
  • Add Blazor WebAssembly alternative frontend
  • Implement caching with Redis
  • Add GraphQL support
  • Add Docker Compose configuration
  • Add multi-tenancy Core support
  • Add support to use as a microservice module

๐Ÿ‘ค Credits

Developed by Muhammad Raslan

  • GitHub: @EngRslan
  • Email: [eng.m.rslan@hotmail.com]

๐Ÿ“„ License

This project is licensed under the MIT License with Commercial Resale Restriction.

  • โœ… Free to use for personal and commercial projects
  • โœ… Free to modify and customize as needed
  • โœ… Free to use for client projects
  • โŒ Cannot be resold as a template or product without permission

See the LICENSE file for full details.

๐Ÿ™ Acknowledgments

Architecture Inspiration

  • File organization and structure inspired by ABP Framework - A complete infrastructure to create modern web applications
  • Clean Architecture principles by Robert C. Martin (Uncle Bob)
  • Domain-Driven Design concepts by Eric Evans

External Dependencies

Backend Libraries
Frontend Libraries
  • Angular - Platform for building mobile and desktop apps
  • angular-oauth2-oidc - OAuth2 and OpenID Connect (OIDC) client
  • RxJS - Reactive Extensions Library for JavaScript
  • TypeScript - Typed superset of JavaScript
Development Tools
  • NSwag - TypeScript client code generator for OpenAPI/Swagger specifications
    • Automatically generates TypeScript contracts from your .NET API
    • Ensures type-safe API communication between backend and frontend
    • Reduces manual contract synchronization efforts

Special Thanks

  • Thanks to all contributors who have helped shape this template
  • The .NET and Angular communities for continuous support and inspiration
  • Built with โค๏ธ for the developer community

<p align="center"> Made with โค๏ธ by Muhammad Raslan </p>

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-beta3 68 9/12/2025
1.0.0-beta2 63 9/12/2025
1.0.0-beta1 67 9/12/2025