AgentSkillsCN

dotnet-project-structure

. NET 10 项目结构与脚手架模板,适用于迁移后的 PHP 应用程序。适用于新建 .NET 项目、设置文件夹结构,或为 ASP.NET Core MVC 或 Minimal APIs 生成样板代码时使用。

SKILL.md
--- frontmatter
name: dotnet-project-structure
description: .NET 10 project structure and scaffolding templates for migrated PHP applications. Use when creating new .NET projects, setting up folder structure, or generating boilerplate code for ASP.NET Core MVC or Minimal APIs.

.NET 10 Project Structure Guide

Use this skill when setting up the .NET 10 project structure for migrated PHP applications.

Recommended Project Structure

ASP.NET Core MVC (from Laravel/Symfony)

code
src/ProjectName.Web/
├── Controllers/              # MVC Controllers
│   ├── HomeController.cs
│   └── Api/                  # API Controllers
├── Models/
│   ├── Entities/             # EF Core entities (from Eloquent models)
│   ├── DTOs/                 # Data Transfer Objects
│   └── ViewModels/           # View-specific models
├── Services/
│   ├── Interfaces/           # Service contracts
│   └── Implementations/      # Service implementations
├── Data/
│   ├── ApplicationDbContext.cs
│   └── Migrations/           # EF Core migrations
├── Views/                    # Razor views (from Blade/Twig)
│   ├── Shared/
│   │   ├── _Layout.cshtml
│   │   └── _Partial.cshtml
│   └── Home/
├── Infrastructure/
│   ├── Extensions/           # DI and service extensions
│   └── Middleware/           # Custom middleware
├── wwwroot/                  # Static files
│   ├── css/
│   ├── js/
│   └── images/
├── appsettings.json          # Configuration
├── appsettings.Development.json
└── Program.cs                # Entry point

ASP.NET Core Minimal APIs (from Slim/Lumen)

code
src/ProjectName.Api/
├── Endpoints/                # Minimal API endpoint groups
│   ├── ProductEndpoints.cs
│   └── UserEndpoints.cs
├── Models/
│   ├── Entities/
│   └── DTOs/
├── Services/
│   ├── Interfaces/
│   └── Implementations/
├── Data/
│   └── ApplicationDbContext.cs
├── Infrastructure/
│   ├── Extensions/
│   └── Middleware/
├── appsettings.json
└── Program.cs

Template Files

See the templates directory for starter files:

PHP to .NET Structure Mapping

PHP (Laravel).NET 10
app/Http/Controllers/Controllers/
app/Models/Models/Entities/
app/Services/Services/Implementations/
app/Repositories/Data/ (or keep as Repositories)
resources/views/Views/
resources/views/layouts/Views/Shared/
public/wwwroot/
routes/web.phpProgram.cs or Controllers/
routes/api.phpControllers/Api/ or Endpoints/
config/appsettings.json
database/migrations/Data/Migrations/
app/Http/Middleware/Infrastructure/Middleware/
app/Providers/Infrastructure/Extensions/

Naming Conventions

ConceptPHP.NET
Filessnake_case.phpPascalCase.cs
ClassesPascalCasePascalCase
MethodscamelCasePascalCase
Variables$camelCasecamelCase
Properties$snake_case or $camelCasePascalCase
ConstantsUPPER_SNAKE_CASEPascalCase
InterfacesInterface suffixI prefix (IService)

Best Practices

  1. One class per file - Each .cs file contains one class
  2. Interface-first - Create IService interfaces for all services
  3. DTOs for boundaries - Use DTOs between layers, not entities
  4. Extension methods for DI - Group related service registrations
  5. Async everywhere - Use async/await for I/O operations
  6. Nullable reference types - Enable and handle nullability properly