NetSchema 3.0.3
dotnet tool install --global NetSchema --version 3.0.3
dotnet new tool-manifest
dotnet tool install --local NetSchema --version 3.0.3
#tool dotnet:?package=NetSchema&version=3.0.3
nuke :add-package NetSchema --version 3.0.3
NetSchema - N-Tier Architecture Generator
Complete N-Tier architecture generator for .NET 8 ??
One command to generate Core, DAL, Business, API, and Shared layers with Repository Pattern, AutoMapper, FluentValidation, and sample CRUD operations.
?? Features
? 5-Layer Architecture - Core, DAL, Business, API, Shared
? Repository Pattern - Generic CRUD with soft delete
? AutoMapper - Automatic DTO mappings
? FluentValidation - Request validation
? Sample CRUD - Working controller with Swagger
? Dependency Injection - Pre-configured DI
? EF Core - DbContext with query filters
?? Installation
Global Tool (Recommended)
dotnet tool install --global NetSchema
Update Existing
dotnet tool update --global NetSchema
?? Quick Start
1. Create a new solution
mkdir MyAwesomeApp
cd MyAwesomeApp
dotnet new sln -n MyApp
2. Generate N-Tier architecture
dotnet netschema generate
That's it! ??
?? Generated Structure
MyAwesomeApp/
??? MyApp.sln
??? App.Core/ # Domain Layer
? ??? Entities/
? ? ??? BaseEntity.cs
? ? ??? IAuditedEntity.cs
? ? ??? SampleEntity.cs
? ??? Enums/
? ? ??? SampleEnum.cs
? ??? Exceptions/
?
??? App.DAL/ # Data Access Layer
? ??? Persistence/
? ? ??? AppDbContext.cs
? ??? Repositories/
? ? ??? Interfaces/
? ? ? ??? IRepository.cs
? ? ??? Implementations/
? ? ??? Repository.cs
? ??? Handlers/
? ??? Migrations/
? ??? DALDependencyInjection.cs
?
??? App.Business/ # Business Logic Layer
? ??? DTOs/
? ? ??? SampleEntityDto.cs
? ??? Validators/
? ? ??? SampleEntityValidator.cs
? ??? MappingProfiles/
? ? ??? MappingProfile.cs
? ??? Services/
? ??? Helpers/
? ??? BusinessDependencyInjection.cs
?
??? App.API/ # Presentation Layer
? ??? Controllers/
? ? ??? SampleController.cs
? ??? Program.cs
? ??? appsettings.json
? ??? appsettings.Development.json
?
??? App.Shared/ # Shared Utilities
??? Implementations/
??? Interfaces/
?? Configuration
1. Update Connection String
Edit App.API/appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=MyAppDb;User Id=sa;Password=YourPassword123;TrustServerCertificate=True"
}
}
2. Create & Apply Migrations
cd App.API
dotnet ef migrations add InitialCreate
dotnet ef database update
3. Run the API
dotnet run
Open Swagger: https://localhost:5001/swagger
?? Example Usage
Generated Sample Controller
The generated SampleController includes:
- ? GET
/api/sample- Get all entities - ? GET
/api/sample/{id}- Get by ID - ? POST
/api/sample- Create new - ? PUT
/api/sample/{id}- Update existing - ? DELETE
/api/sample/{id}- Soft delete
Sample Request (POST)
POST /api/sample
{
"name": "John Doe",
"description": "Sample description"
}
Sample Response
{
"id": 1,
"name": "John Doe",
"description": "Sample description",
"createdDate": "2025-01-30T00:00:00Z"
}
?? Customization
Add Your Own Entities
- Create entity in
App.Core/Entities/:
public class User : BaseEntity, IAuditedEntity
{
public string FullName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
public bool IsDeleted { get; set; }
}
- Add DbSet to
AppDbContext:
public DbSet<User> Users { get; set; }
- Create migration:
dotnet ef migrations add AddUserEntity
dotnet ef database update
?? Advanced Features
Repository Pattern
// Inject in your service
private readonly IRepository<User> _userRepository;
// CRUD operations
var users = await _userRepository.GetAllAsync();
var user = await _userRepository.GetByIdAsync(x => x.Id == userId);
await _userRepository.AddAsync(newUser);
await _userRepository.UpdateAsync(user);
await _userRepository.DeleteAsync(user); // Soft delete
await _userRepository.RemoveAsync(user); // Hard delete
AutoMapper
// In MappingProfile.cs
CreateMap<User, UserDto>();
CreateMap<CreateUserDto, User>();
FluentValidation
// In Validators/CreateUserValidator.cs
public class CreateUserValidator : AbstractValidator<CreateUserDto>
{
public CreateUserValidator()
{
RuleFor(x => x.Email).NotEmpty().EmailAddress();
RuleFor(x => x.FullName).NotEmpty().MaximumLength(200);
}
}
??? Architecture Overview
???????????????????????????????????????????????
? App.API (Presentation) ?
? Controllers, Swagger, Program.cs ?
???????????????????????????????????????????????
?
???????????????????????????????????????????????
? App.Business (Business Logic) ?
? Services, DTOs, Validators, Mappings ?
???????????????????????????????????????????????
?
???????????????????????????????????????????????
? App.DAL (Data Access) ?
? DbContext, Repositories, Migrations ?
???????????????????????????????????????????????
?
???????????????????????????????????????????????
? App.Core (Domain) ?
? Entities, Interfaces, Enums ?
???????????????????????????????????????????????
?? Package Versions
- EF Core: 8.0.0
- AutoMapper: 12.0.1
- FluentValidation: 11.9.0
- Swashbuckle: 6.5.0
?? Troubleshooting
Tool not found
dotnet tool uninstall --global NetSchema
dotnet tool install --global NetSchema
Solution not found
Make sure you're in a directory with a .sln file, or create one:
dotnet new sln -n MyApp
Migrations error
cd App.API
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
?? Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- 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
?? License
This project is licensed under the MIT License - see the LICENSE file for details.
????? Author
Emil Huseyn
GitHub: @emilhuseyn
?? Star History
If you like this project, please give it a ? on GitHub!
?? Resources
?? Learn More
<div align="center"> Made with ?? by <a href="https://github.com/emilhuseyn">Emil Huseyn</a> </div>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
Version 3.0.3 - Documentation Update: Enhanced README with complete usage guide, step-by-step quick start instructions, architecture diagrams and examples, troubleshooting section added, better customization examples, complete API endpoint documentation, migration and configuration guides. Features: One command to generate 5-layer architecture, Repository Pattern with soft delete, AutoMapper and FluentValidation integration, Sample CRUD controller with Swagger, Dependency Injection pre-configured. Quick Start: 1. dotnet tool install --global NetSchema 2. mkdir MyApp and cd MyApp 3. dotnet new sln -n MyApp 4. dotnet netschema generate. GitHub: https://github.com/emilhuseyn/NetSchema