Fafp.Templates.WebApi 1.0.2

dotnet new install Fafp.Templates.WebApi@1.0.2
                    
This package contains a .NET Template Package you can call from the shell/command line.

Firefly AI Flow Platform β€” Web API Template

πŸ‡¬πŸ‡§ English | πŸ‡·πŸ‡Ί Русский

Production-ready template for creating ASP.NET Core 10 microservices.


ASP.NET C# License


Quick Start

# Install template
dotnet new install Fafp.Templates.WebApi

# Create project
dotnet new faf-webapi -n MyService

# Build and run
cd MyService
dotnet run

Template Parameters

Parameter Default Description
-n, --name (folder name) Project name (replaces WebApiTemplate)
--Port 8080 HTTP port for the service
--Author Kotrecon Author name
--AuthorEmail ermakov_k@mail.ru Author email
--AuthorUrl https://github.com/Kotrecon Author URL (GitHub profile)
--Title Web API Service Service title (used in OpenAPI/Scalar)
--Version 1.0.0 Service version (semver)
--Description ASP.NET Core Web API microservice Service description
--ServiceHost api.example.com Service host (used in nginx example)
-I, --IncludeTests true Include test project

Example with all parameters:

dotnet new faf-webapi -n OrderService \
    --Port 8082 \
    --Author "John Doe" \
    --AuthorEmail "john@example.com" \
    --Title "Order Service API" \
    --Version "1.0.0" \
    --Description "Service for processing orders" \
    --ServiceHost "orders.mycompany.com"

What's Included

Component Description
Clean Architecture Controllers β†’ Services β†’ Repositories
Result Pattern Type-safe error handling via Fafp.ResultPattern
Serilog Structured logging (JSON in prod, human-readable in dev)
OpenTelemetry Tracing, metrics, logs β†’ OTLP endpoint
JWT Authentication Bearer tokens, policy-based authorization
Health Checks Liveness + Readiness on separate port (8081)
CORS Configurable policy
Rate Limiting Request limiting for health endpoints
Correlation ID End-to-end X-Correlation-Id (Guid v7)
OpenAPI + Scalar Scalar UI with JWT authorization
API Versioning URL-based versioning (/api/v1/...)
Response Caching HTTP caching for public endpoints
202 tests Unit + Integration via TUnit + WebApplicationFactory

Project Structure

webapi/
β”œβ”€β”€ .git/
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .template.config/
β”‚   └── template.json
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ architecture/
β”‚   β”‚   β”œβ”€β”€ adr.md
β”‚   β”‚   β”œβ”€β”€ adr.ru.md
β”‚   β”‚   β”œβ”€β”€ api.md
β”‚   β”‚   β”œβ”€β”€ api.ru.md
β”‚   β”‚   β”œβ”€β”€ architecture.md
β”‚   β”‚   β”œβ”€β”€ architecture.ru.md
β”‚   β”‚   β”œβ”€β”€ auth-flow.md
β”‚   β”‚   β”œβ”€β”€ auth-flow.ru.md
β”‚   β”‚   β”œβ”€β”€ deployment.md
β”‚   β”‚   β”œβ”€β”€ deployment.ru.md
β”‚   β”‚   β”œβ”€β”€ observability.md
β”‚   β”‚   β”œβ”€β”€ observability.ru.md
β”‚   β”‚   β”œβ”€β”€ operability.md
β”‚   β”‚   └── operability.ru.md
β”‚   β”œβ”€β”€ configuration.md
β”‚   β”œβ”€β”€ configuration.ru.md
β”‚   β”œβ”€β”€ index.md
β”‚   β”œβ”€β”€ index.ru.md
β”‚   β”œβ”€β”€ quickstart.md
β”‚   β”œβ”€β”€ quickstart.ru.md
β”‚   β”œβ”€β”€ roadmap.md
β”‚   β”œβ”€β”€ roadmap.ru.md
β”‚   β”œβ”€β”€ testing.md
β”‚   └── testing.ru.md
β”œβ”€β”€ Faf.Templates.WebApi.csproj
β”œβ”€β”€ global.json
β”œβ”€β”€ icon.png
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ README.ru.md
β”œβ”€β”€ WebApiTemplate.slnx
β”‚
β”œβ”€β”€ WebApiTemplate/
β”‚   β”œβ”€β”€ Configuration/Options/
β”‚   β”‚   β”œβ”€β”€ ApiMetadataOptions.cs
β”‚   β”‚   β”œβ”€β”€ AppSettings.cs
β”‚   β”‚   β”œβ”€β”€ ContactInfo.cs
β”‚   β”‚   β”œβ”€β”€ JwtOptions.cs
β”‚   β”‚   └── OpenTelemetryOptions.cs
β”‚   β”œβ”€β”€ Contracts/Dto/Request/Logging/
β”‚   β”‚   β”œβ”€β”€ SetLogLevelRequest.cs
β”‚   β”‚   └── SetLogLevelValidator.cs
β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   └── LoggingController.cs
β”‚   β”œβ”€β”€ Extensions/
β”‚   β”‚   β”œβ”€β”€ ConfigurationExtensions.cs
β”‚   β”‚   β”œβ”€β”€ ObservabilityExtensions.cs
β”‚   β”‚   β”œβ”€β”€ CorrelationId/
β”‚   β”‚   β”‚   β”œβ”€β”€ CorrelationIdExtensions.cs
β”‚   β”‚   β”‚   └── CorrelationIdMiddleware.cs
β”‚   β”‚   β”œβ”€β”€ Cors/
β”‚   β”‚   β”‚   └── CorsExtensions.cs
β”‚   β”‚   β”œβ”€β”€ ExceptionHandler/
β”‚   β”‚   β”‚   β”œβ”€β”€ ExceptionHandlerExtensions.cs
β”‚   β”‚   β”‚   └── ExceptionHandlerMiddleware.cs
β”‚   β”‚   β”œβ”€β”€ HealthChecks/
β”‚   β”‚   β”‚   └── HealthCheckExtensions.cs
β”‚   β”‚   β”œβ”€β”€ RateLimiting/
β”‚   β”‚   β”‚   └── RateLimitingExtensions.cs
β”‚   β”‚   └── RequestResponseLogging/
β”‚   β”‚       β”œβ”€β”€ RequestResponseLoggingExtensions.cs
β”‚   β”‚       └── RequestResponseLoggingMiddleware.cs
β”‚   β”œβ”€β”€ HealthChecks/
β”‚   β”‚   β”œβ”€β”€ DatabaseHealthChecker.cs
β”‚   β”‚   β”œβ”€β”€ IDatabaseHealthChecker.cs
β”‚   β”‚   β”œβ”€β”€ MinimalResponseWriter.cs
β”‚   β”‚   └── ReadinessHealthCheck.cs
β”‚   β”œβ”€β”€ Security/
β”‚   β”‚   β”œβ”€β”€ AuthenticationExtensions.cs
β”‚   β”‚   └── AuthorizationExtensions.cs
β”‚   β”œβ”€β”€ Program.cs
β”‚   β”œβ”€β”€ WebApiTemplate.csproj
β”‚   β”œβ”€β”€ appsettings.json
β”‚   β”œβ”€β”€ appsettings.Development.json
β”‚   └── appsettings.Production.json
β”‚
└── WebApiTemplate.Tests/
    β”œβ”€β”€ Configuration/Options/
    β”‚   β”œβ”€β”€ ApiMetadataOptionsTests.cs
    β”‚   β”œβ”€β”€ AppSettingsTests.cs
    β”‚   β”œβ”€β”€ ContactInfoTests.cs
    β”‚   β”œβ”€β”€ JwtOptionsTests.cs
    β”‚   └── OpenTelemetryOptionsTests.cs
    β”œβ”€β”€ Contracts/Dto/
    β”‚   └── SetLogLevelRequestTests.cs
    β”œβ”€β”€ Controllers/
    β”‚   β”œβ”€β”€ ApiVersioningTests.cs
    β”‚   └── LoggingControllerTests.cs
    β”œβ”€β”€ Extensions/
    β”‚   β”œβ”€β”€ ConfigurationExtensionsTests.cs
    β”‚   β”œβ”€β”€ ObservabilityExtensionsTests.cs
    β”‚   β”œβ”€β”€ CorrelationId/
    β”‚   β”‚   └── CorrelationIdMiddlewareTests.cs
    β”‚   β”œβ”€β”€ Cors/
    β”‚   β”‚   └── CorsExtensionsTests.cs
    β”‚   β”œβ”€β”€ ExceptionHandler/
    β”‚   β”‚   └── ExceptionHandlerMiddlewareTests.cs
    β”‚   └── RequestResponseLogging/
    β”‚       └── RequestResponseLoggingMiddlewareTests.cs
    β”œβ”€β”€ HealthChecks/
    β”‚   β”œβ”€β”€ MinimalResponseWriterTests.cs
    β”‚   └── ReadinessHealthCheckTests.cs
    β”œβ”€β”€ Helpers/
    β”‚   └── RecursiveValidator.cs
    β”œβ”€β”€ Integration/
    β”‚   β”œβ”€β”€ Infrastructure/
    β”‚   β”‚   └── TestWebApplicationFactory.cs
    β”‚   β”œβ”€β”€ AuthenticationTests.cs
    β”‚   β”œβ”€β”€ AuthorizationTests.cs
    β”‚   β”œβ”€β”€ CorrelationIdE2ETests.cs
    β”‚   β”œβ”€β”€ DevTokenEndpointTests.cs
    β”‚   └── MetadataEndpointTests.cs
    β”œβ”€β”€ Security/
    β”‚   β”œβ”€β”€ AuthenticationExtensionsTests.cs
    β”‚   └── AuthorizationExtensionsTests.cs
    β”œβ”€β”€ WebApiTemplate.Tests.csproj
    └── coverlet.runsettings

Endpoints

API (port 8080)

Endpoint Method Description Access
/api/v1/logging/level GET Get current logging level AuditViewer
/api/v1/logging/level PUT Change logging level (runtime) AdminOnly
/api/v1/logging/categories GET List categories with overrides AuditViewer
/api/metadata GET Service info (cached 1 hour) Anonymous
/dev/token POST Generate test JWT (Development only) Anonymous

Health Checks (port 8081 β€” internal only)

Endpoint Method Description Access
/health/live GET Liveness probe Internal
/health/ready GET Readiness probe Internal
/health GET Aggregated status Internal

OpenAPI (Development only)

URL Description
http://localhost:8080/scalar/v1 Scalar UI (interactive docs)
http://localhost:8080/openapi/v1.json OpenAPI 3.1 document

Configuration

appsettings.json

{
  "Kestrel": {
    "Endpoints": {
      "Api": { "Url": "http://0.0.0.0:8080" },
      "Health": { "Url": "http://0.0.0.0:8081" }
    }
  },
  "AppSettings": {
    "ServiceName": "MyService",
    "Port": 8080
  },
  "Jwt": {
    "Key": "YourSuperSecretKeyAtLeast32CharactersLong!",
    "Issuer": "MyService",
    "Audience": "MyService"
  },
  "OpenTelemetry": {
    "Endpoint": "http://otel-collector:4317",
    "Protocol": "Grpc",
    "Headers": {},
    "UseConsoleExporter": false
  },
  "ApiMetadata": {
    "Title": "SERVICE_TITLE_PLACEHOLDER",
    "Version": "SERVICE_VERSION_PLACEHOLDER",
    "Description": "SERVICE_DESCRIPTION_PLACEHOLDER",
    "Developer": {
      "Name": "AUTHOR_PLACEHOLDER",
      "Email": "AUTHOR_EMAIL_PLACEHOLDER",
      "Url": "AUTHOR_URL_PLACEHOLDER"
    }
  }
}

Environment Variables

Variable Required Description
ASPNETCORE_ENVIRONMENT Yes Production / Development
Jwt__Key Yes JWT signing key (min 32 chars)
OpenTelemetry__Endpoint No OTLP endpoint (default: http://localhost:4317)

Testing

cd MyService.Tests
dotnet test

Result: 202 tests (unit + integration), coverage via coverlet.

Dependencies

  • Fafp.ResultPattern 1.0.0 β€” type-safe error handling
  • Serilog.AspNetCore β€” structured logging
  • OpenTelemetry.* β€” tracing and metrics
  • Microsoft.AspNetCore.Authentication.JwtBearer β€” JWT
  • Scalar.AspNetCore β€” OpenAPI UI
  • TUnit β€” testing framework

Roadmap

βœ… v1.0.0 β€” Base template

  • Clean Architecture
  • Result Pattern integration
  • Serilog + OpenTelemetry
  • JWT + Health Checks
  • 202 tests (TUnit)
  • NuGet template package

πŸ“‹ v1.1.0 β€” Docker & DevOps

  • Dockerfile (multi-stage build)
  • docker-compose.yml (service + PostgreSQL + OTel Collector)
  • .dockerignore
  • GitHub Actions CI/CD workflow

Author

Kotrecon

Solution Architect from Saint Petersburg. Specialization: .NET, C#, JS, Python, AI/ML, RAG, Agents, DevOps, GitHub, GitLab, CI/CD, Industrial Automation, Industrial Software, DB, PostgreSQL.

Email | GitHub


License

MIT


This package has 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.2 214 7/8/2026
1.0.1 184 7/8/2026