Engrslan.SME.DDD
1.0.0-beta3
dotnet new install Engrslan.SME.DDD::1.0.0-beta3
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.
๐ Table of Contents
- ๐ License
- ๐ฏ Overview
- ๐ Features
- ๐ Project Structure
- ๐ ๏ธ Technology Stack
- ๐ฆ Getting Started
- ๐ฆ Template Installation
- ๐ Usage
- ๐งช Testing
- ๐ Health Checks
- ๐ Security
- ๐ค Contributing
- ๐ Documentation
- ๐ Roadmap
- ๐ค Credits
- ๐ Acknowledgments
๐ 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
- .NET 9 SDK
- Node.js 20+
- SQL Server or SQL Server Express
- Visual Studio 2022 or Visual Studio Code
- Angular CLI
npm install -g @angular/cli
๐ฆ Template Installation
Install as .NET Template
Install from NuGet
dotnet new install Engrslan.SME.DDD
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
Full-Featured Application (Default)
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:
- Update the namespace - The template will rename
Engrslan
to your project name automatically - Configure connection strings - Update database connections in appsettings.json files
- Run database migrations - Apply EF Core migrations to create the database schema
- Configure CORS - Update allowed origins for your environment
- Start development - Run Identity Server and API Host projects
Installation
Option 1: Using the NuGet Template (Recommended)
Create a new project from template
# If template is already installed dotnet new engrslan-ddd -n YourProjectName cd YourProjectName
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
Install dependencies
# Backend dependencies (if not auto-restored) dotnet restore # Frontend dependencies cd src/HttpApi.Host/ClientApp npm install
Option 2: Clone from GitHub
Clone the repository
git clone https://github.com/EngRslan/ddd-pattern-template.git cd ddd-pattern-template
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
Install dependencies
# Backend dependencies dotnet restore # Frontend dependencies cd src/HttpApi.Host/ClientApp npm install
Running the Application
Run the Identity Server (if using Identity)
cd src/Identity dotnet run # Identity server will run on https://localhost:{{generated}}
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
- 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));
}
}
- Create repository interface
public interface IProductRepository : IRepository<Product, Guid>
{
Task<Product> GetByNameAsync(string name);
}
- 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
- User clicks login โ Redirected to Identity Server
- User authenticates โ Identity Server issues tokens
- Tokens stored in browser โ Used for API calls
- 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - 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
- Domain-Driven Design
- Clean Architecture
- OpenIddict Documentation
- Angular Documentation
- Entity Framework Core
๐ 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
- OpenIddict - Flexible OpenID Connect server framework
- Entity Framework Core - Modern object-database mapper for .NET
- Serilog - Simple .NET logging with structured events
- FluentValidation - Popular .NET validation library
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 |