Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
e02dd10
refactor(ui): move non-component exports out of component files
pdevito3 Oct 18, 2026
b3bc753
perf(frontend): keep lazy route code out of the entry chunk
pdevito3 Oct 18, 2026
b97fa0e
refactor(filter-builder): remove the barrel file
pdevito3 Oct 18, 2026
d7c28fe
refactor(frontend): remove the unused svg barrel file
pdevito3 Oct 18, 2026
7f7f029
fix(ui): fit the theme toggle in the collapsed sidebar
pdevito3 Oct 18, 2026
3332047
fix(ui): make the destructive color readable in dark mode
pdevito3 Oct 18, 2026
4284e19
refactor(ui): remove the unused combobox filter hook
pdevito3 Oct 18, 2026
2e8d5e0
refactor(frontend): remove the leftovers of the file split
pdevito3 Oct 18, 2026
3fe096e
refactor(frontend): rename the Notifications toast container to Toaster
pdevito3 Oct 18, 2026
e040e86
feat(api): generate the frontend API contract with Kubb
pdevito3 Oct 18, 2026
dc631d1
fix(api): run no hosted services in the build-time OpenAPI run
pdevito3 Oct 18, 2026
7d750c4
ci: pin the actions and limit the token to read
pdevito3 Oct 18, 2026
51803dc
ci: build the frontend and run the tests
pdevito3 Oct 18, 2026
a357aa2
fix(api): keep problem+json for error responses
pdevito3 Oct 18, 2026
9259c27
fix(api): keep the default JSON input rules at run time
pdevito3 Oct 18, 2026
47603ce
fix(api): tie the pagination header to list operation names
pdevito3 Oct 18, 2026
091dc91
fix(deps): update Microsoft.AspNetCore.OpenApi to 10.0.13
pdevito3 Oct 18, 2026
67b32dd
chore(deps): align Microsoft.Extensions.ApiDescription.Server with Mi…
pdevito3 Oct 18, 2026
966ea67
test: check the pagination header of the tenant list
pdevito3 Oct 18, 2026
aba35f4
fix(api): document the validation problem for 400 responses
pdevito3 Oct 18, 2026
d23cedc
ci: cache NuGet packages and harden the checkout
pdevito3 Oct 18, 2026
c587ab9
chore: mark the OpenAPI document as generated
pdevito3 Oct 18, 2026
2c505bd
docs: describe the limits of the committed OpenAPI document
pdevito3 Oct 18, 2026
a680364
test(frontend): add Vitest and cover parsePagination
pdevito3 Oct 18, 2026
6f69a3c
refactor(api): use AxiosRequestConfig in place of the ApiClientReques…
pdevito3 Oct 18, 2026
0819214
docs(frontend): describe the two error modes of the generated clients
pdevito3 Oct 18, 2026
2b12324
docs(frontend): tell where the ui variants and hooks are
pdevito3 Oct 18, 2026
365f72e
fix(frontend): read the pagination header in any case
pdevito3 Oct 18, 2026
38acbd3
ci: run the frontend unit tests
pdevito3 Oct 18, 2026
7be1d6d
fix(api): document the validation problem for 422 responses
pdevito3 Oct 18, 2026
d98d4ea
test(api): cover the OpenAPI transformers
pdevito3 Oct 18, 2026
421059e
docs(rules): require the value-type fields of request DTOs
pdevito3 Oct 18, 2026
6918c1b
test: add and list tenants as the trusted machine client
pdevito3 Oct 18, 2026
262f752
test: remove the unused WebMotions usings from the tenant tests
pdevito3 Oct 18, 2026
d4f330a
fix(domain): key the invalid email error by the request field
pdevito3 Oct 18, 2026
e889bf8
docs(rules): make the Email example agree with EmailAddress
pdevito3 Oct 18, 2026
9a6b6a9
fix(api): return 400 for a filters or sortOrder value that QueryKit c…
pdevito3 Oct 18, 2026
a63bfa4
fix(api): remove the 400 that RemoveUserPermission cannot return
pdevito3 Oct 18, 2026
8161b28
fix(api): document the 401 on each operation that requires authentica…
pdevito3 Oct 18, 2026
c7591e4
fix(api): serve only the API versions that each endpoint declares
pdevito3 Oct 18, 2026
7ddc066
docs(rules): register a new API version in SupportedVersions
pdevito3 Oct 18, 2026
d66b305
fix(api): return 400 for a filter value that does not convert to the …
pdevito3 Oct 18, 2026
366fc86
fix(api): filter and sort the list endpoints on the DTO
pdevito3 Oct 18, 2026
06de115
perf(api): reuse one JsonSerializerOptions for the X-Pagination header
pdevito3 Oct 18, 2026
6cf12be
refactor(api): set the X-Pagination header in a result filter
pdevito3 Oct 18, 2026
a957796
docs(api): describe the pagination result filter
pdevito3 Oct 18, 2026
3b4c00a
test(frontend): cover the api-client interceptor through a generated …
pdevito3 Oct 18, 2026
2a96eca
test(api): read a number in a JSON string with the runtime JSON options
pdevito3 Oct 18, 2026
cb7106b
build(frontend): type-check kubb.config.ts
pdevito3 Oct 18, 2026
433e935
refactor(frontend): build the Kubb config from a list of OpenAPI docu…
pdevito3 Oct 18, 2026
b17fc8b
refactor(frontend): base ProblemDetails on the generated contract type
pdevito3 Oct 18, 2026
46d2cf7
refactor(frontend): remove the unused apiFetch and fetchWithoutToast
pdevito3 Oct 18, 2026
850ad04
fix(frontend): validate the X-Pagination header with the generated Zo…
pdevito3 Oct 18, 2026
4b916a6
test(api): give each OpenAPI document rule its own test
pdevito3 Oct 18, 2026
cb438c0
test(api): expect a 401 with no body from each secured operation
pdevito3 Oct 18, 2026
10ee48a
docs: state that the OpenAPI endpoints exist only in Development
pdevito3 Oct 18, 2026
bfdce50
docs(api): use a neutral entity in the required-field example
pdevito3 Oct 18, 2026
6c2b326
chore(api): generate the contract again for the changes on main
pdevito3 Oct 18, 2026
77b674b
fix(api): order the rows by Id after a custom sort
pdevito3 Oct 18, 2026
bfe932f
test(api): make sure that a sort returns the users in order
pdevito3 Oct 18, 2026
5cb6f34
fix(api): remove the duplicate 422 attribute on AddUser
pdevito3 Oct 18, 2026
5fd420e
refactor(api): remove the unused Resources.Extensions using in the co…
pdevito3 Oct 18, 2026
f884955
fix(api): count the rows of a page asynchronously
pdevito3 Oct 18, 2026
e403fd1
fix(api): append X-Pagination to Access-Control-Expose-Headers
pdevito3 Oct 18, 2026
82624d0
fix(api): use the JSON names as the keys of the body validation errors
pdevito3 Oct 18, 2026
8037c22
fix(api): use the request field name as the key of the role errors
pdevito3 Oct 18, 2026
9e6f7bf
fix(api): name the query parameters in camelCase
pdevito3 Oct 18, 2026
968006e
fix(api): return 409 for a duplicate unique value
pdevito3 Oct 18, 2026
7d50548
docs(frontend): use the generated clients in the rule examples
pdevito3 Oct 18, 2026
dd6f6c3
build(frontend): generate a contract for each OpenAPI document in the…
pdevito3 Oct 18, 2026
4183e2e
build(frontend): turn off the Kubb telemetry
pdevito3 Oct 18, 2026
7dd2f7f
ci: rename the API contract workflow to CI
pdevito3 Oct 18, 2026
17fd271
test(frontend): cover problem-details and the other error branches of…
pdevito3 Oct 18, 2026
5839767
test(api): cover each status that DomainProblemDetails maps
pdevito3 Oct 18, 2026
55a83c7
docs(api): link the upstream issue for the AV0029 and AV0030 suppression
pdevito3 Oct 18, 2026
6fe9b7e
docs(api): link the Microsoft docs for the GetDocument.Insider check
pdevito3 Oct 18, 2026
9489837
perf(api): index the default sort of the user list
pdevito3 Oct 18, 2026
a1cf26d
fix(api): return 400 for a page number or a page size less than 1
pdevito3 Oct 18, 2026
04f2a8e
fix(api): key the duplicate tenant name conflict by the name field
pdevito3 Oct 18, 2026
32a10bc
fix(api): use the request field names as the keys of the tenant and p…
pdevito3 Oct 18, 2026
082448a
refactor(api): remove the CORS expose entry for X-Pagination
pdevito3 Oct 18, 2026
7c15cdc
test(api): make sure that a list with no sort returns the users by la…
pdevito3 Oct 18, 2026
e8b73d8
refactor(api): make the page data setters of PagedList private
pdevito3 Oct 18, 2026
22c9302
docs(api): describe what the default API version applies to
pdevito3 Oct 18, 2026
9003822
docs(frontend): use a generated client in the apiClient example and g…
pdevito3 Oct 18, 2026
63c72f9
test(frontend): make sure that a list client returns the full respons…
pdevito3 Oct 18, 2026
120a491
ci: delete the committed contract files before the contract is genera…
pdevito3 Oct 18, 2026
dbade37
docs: name each generated folder of the API contract
pdevito3 Oct 18, 2026
7d087c9
docs(rules): sort by Id after a custom sort in the list query example
pdevito3 Oct 18, 2026
59a45aa
docs(skills): make the backend-feature templates obey the query and r…
pdevito3 Oct 18, 2026
f0263ec
docs(rules): declare the 400 of a list action in the controller template
pdevito3 Oct 18, 2026
1c65efe
fix(api): update QueryKit to 1.16.1 so that a filter on the permissio…
pdevito3 Oct 18, 2026
3b39217
docs(api): say that the pagination header filter runs only for contro…
pdevito3 Oct 18, 2026
b400b93
Merge origin/main into feat/kubb-contracts
pdevito3 Oct 18, 2026
a55828a
fix(api): key each QueryKit error by the parameter that failed
pdevito3 Oct 18, 2026
80db63f
fix(api): key each 422 and 409 by the request field
pdevito3 Oct 18, 2026
61cc105
docs(skills): add the step that generates the API contract to the bac…
pdevito3 Oct 18, 2026
4d88830
fix(api): limit pageNumber so that the page offset fits in an int
pdevito3 Oct 18, 2026
aa199f7
test(api): show that the user list breaks a tie on the sort by Id
pdevito3 Oct 18, 2026
1b31a7a
build(frontend): pin pnpm 10 and allow only the esbuild build script
pdevito3 Oct 18, 2026
13a6d33
Merge remote-tracking branch 'origin/main' into feat/kubb-contracts
pdevito3 Oct 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .agents/skills/backend-feature/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ Add a GetOrdersByCustomer query that returns orders for a specific customer
- Add DbSet to AppDbContext
- Ensure `ApplyConfigurationsFromAssembly` is called in OnModelCreating

10. **Generate the API Contract**
- Build the Server, then run `pnpm generate:api` in `frontend/`
- Commit the generated files with the change. Do not edit them by hand

---

## Process: New Property
Expand Down Expand Up @@ -231,6 +235,10 @@ Add a GetOrdersByCustomer query that returns orders for a specific customer
dotnet ef migrations add Add[PropertyName]To[EntityName]
```

10. **Generate the API Contract**
- Build the Server, then run `pnpm generate:api` in `frontend/`
- Commit the generated files with the change. Do not edit them by hand

---

## Process: New Feature
Expand Down Expand Up @@ -292,7 +300,8 @@ Add a GetOrdersByCustomer query that returns orders for a specific customer
[HttpPost("{id}/submit", Name = "SubmitOrder")]
[ProducesResponseType(typeof(OrderDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<OrderDto>> SubmitOrder(string id)
{
var command = new SubmitOrder.Command(id);
Expand All @@ -305,6 +314,10 @@ Add a GetOrdersByCustomer query that returns orders for a specific customer
- Request DTO if the action needs input parameters
- Custom response DTO if different from standard entity DTO

7. **Generate the API Contract**
- Build the Server, then run `pnpm generate:api` in `frontend/`
- Commit the generated files with the change. Do not edit them by hand

---

## Important Guidelines
Expand Down Expand Up @@ -372,6 +385,7 @@ public LineItem AddLineItem(Product product, int quantity)
- [ ] Add any needed FluentValidation validators
- [ ] Consider what additional business methods the entity needs
- [ ] Run `dotnet ef migrations add Add[EntityName]` to create migration
- [ ] Run `pnpm generate:api` in `frontend/` and commit the generated contract

### New Property Checklist
- [ ] Property added with private setter in entity
Expand All @@ -385,6 +399,7 @@ public LineItem AddLineItem(Product product, int quantity)
- [ ] A new foreign key to an entity ID has a prefix check with `EntityId.IsValid` in the entity validation
- [ ] Run `dotnet build` to verify compilation
- [ ] Run `dotnet ef migrations add Add[PropertyName]To[EntityName]`
- [ ] Run `pnpm generate:api` in `frontend/` and commit the generated contract

### New Feature Checklist
- [ ] Domain method added to entity with proper guards
Expand All @@ -393,6 +408,7 @@ public LineItem AddLineItem(Product product, int quantity)
- [ ] Controller endpoint added with proper attributes
- [ ] Additional DTOs created if needed
- [ ] Run `dotnet build` to verify compilation
- [ ] Run `pnpm generate:api` in `frontend/` and commit the generated contract

## Reference Files

Expand Down
49 changes: 34 additions & 15 deletions .agents/skills/backend-feature/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public class [EntityName] : BaseEntity

private static void Validate[EntityName]([EntityName] entity)
{
ValidationException.ThrowWhenNullOrWhitespace(entity.Name, "Please provide a name.");
ValidationException.ThrowWhenNullOrWhitespace(entity.Name, "name", "Please provide a name.");

// Check the prefix of each ID foreign key, as User checks its TenantId.
// ValidationException.ThrowWhenNullOrWhitespace(entity.TenantId, "Please provide a tenant.");
// ValidationException.Must(EntityId.IsValid(entity.TenantId, Tenant.IdPrefix), "Please provide a valid tenant ID.");
// ValidationException.ThrowWhenNullOrWhitespace(entity.TenantId, "tenantId", "Please provide a tenant.");
// ValidationException.Must(EntityId.IsValid(entity.TenantId, Tenant.IdPrefix), "tenantId", "Please provide a valid tenant ID.");
}

// Business methods
Expand Down Expand Up @@ -165,9 +165,15 @@ public sealed record [EntityName]ForUpdateDto
```csharp
namespace FullstackTemplate.Server.Domain.[EntityName]s.Dtos;

using Microsoft.AspNetCore.Mvc;
using Resources;

public sealed class [EntityName]ParametersDto : BasePaginationParameters
{
[FromQuery(Name = "filters")]
public string? Filters { get; set; }

[FromQuery(Name = "sortOrder")]
public string? SortOrder { get; set; }
}
```
Expand Down Expand Up @@ -352,7 +358,7 @@ using FullstackTemplate.Server.Domain.[EntityName]s.Dtos;
using FullstackTemplate.Server.Domain.[EntityName]s.Mappings;
using MediatR;
using Microsoft.EntityFrameworkCore;
using QueryKit;
using FullstackTemplate.Server.Resources;

public static class Get[EntityName]List
{
Expand All @@ -364,15 +370,21 @@ public static class Get[EntityName]List
{
var queryKitConfig = new CustomQueryKitConfiguration();

// The filter and the sort run on the DTO, so a caller can query only the fields that the contract shows
var query = dbContext.[EntityName]s
.AsNoTracking()
.ApplyQueryKitFilter(request.Parameters.Filters, queryKitConfig)
.ApplyQueryKitSort(request.Parameters.SortOrder, queryKitConfig);
.To[EntityName]DtoQueryable();

var dtos = query.To[EntityName]DtoQueryable();
if (!string.IsNullOrWhiteSpace(request.Parameters.Filters))
query = query.ApplyFilters(request.Parameters.Filters, queryKitConfig);

// Paging needs a fixed order, or a row can show on two pages or on none
query = string.IsNullOrWhiteSpace(request.Parameters.SortOrder)
? query.OrderBy(e => e.Name).ThenBy(e => e.Id)
: query.ApplySortOrder(request.Parameters.SortOrder, queryKitConfig).ThenBy(e => e.Id);

return await PagedList<[EntityName]Dto>.CreateAsync(
dtos,
query,
request.Parameters.PageNumber,
request.Parameters.PageSize,
cancellationToken);
Expand Down Expand Up @@ -420,14 +432,12 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[Authorize]
[HttpGet(Name = "Get[EntityName]List")]
[ProducesResponseType(typeof(PagedList<[EntityName]Dto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<PagedList<[EntityName]Dto>>> Get[EntityName]List(
[FromQuery] [EntityName]ParametersDto parameters)
{
var query = new Get[EntityName]List.Query(parameters);
var result = await mediator.Send(query);

Response.AddPaginationHeader(result.Pagination);

return Ok(result);
}

Expand All @@ -437,7 +447,10 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[Authorize]
[HttpPost(Name = "Add[EntityName]")]
[ProducesResponseType(typeof([EntityName]Dto), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
// Declare a 409 if this write can add or change a unique value
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status409Conflict)]
public async Task<ActionResult<[EntityName]Dto>> Add[EntityName](
[FromBody] [EntityName]ForCreationDto dto)
{
Expand All @@ -456,7 +469,10 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[HttpPut("{id}", Name = "Update[EntityName]")]
[ProducesResponseType(typeof([EntityName]Dto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
// Declare a 409 if this write can add or change a unique value
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status409Conflict)]
public async Task<ActionResult<[EntityName]Dto>> Update[EntityName](
string id,
[FromBody] [EntityName]ForUpdateDto dto)
Expand All @@ -473,6 +489,7 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[HttpDelete("{id}", Name = "Delete[EntityName]")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult> Delete[EntityName](string id)
{
var command = new Delete[EntityName].Command(id);
Expand Down Expand Up @@ -882,7 +899,8 @@ public [EntityName] [Action](string reason)
[HttpPost("{id}/[action-route]", Name = "[Action][EntityName]")]
[ProducesResponseType(typeof([EntityName]Dto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<[EntityName]Dto>> [Action][EntityName](string id)
{
var command = new [Action][EntityName].Command(id);
Expand All @@ -897,7 +915,8 @@ public async Task<ActionResult<[EntityName]Dto>> [Action][EntityName](string id)
[HttpPost("{id}/[action-route]", Name = "[Action][EntityName]")]
[ProducesResponseType(typeof([EntityName]Dto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<[EntityName]Dto>> [Action][EntityName](
string id,
[FromBody] [Action][EntityName]Dto dto)
Expand Down
47 changes: 25 additions & 22 deletions .claude/rules/backend/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[Authorize]
[HttpGet(Name = "Get[EntityName]List")]
[ProducesResponseType(typeof(PagedList<[EntityName]Dto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<PagedList<[EntityName]Dto>>> Get[EntityName]List(
[FromQuery] [EntityName]ParametersDto parameters)
{
var query = new Get[EntityName]List.Query(parameters);
var result = await mediator.Send(query);

Response.AddPaginationHeader(result);

return Ok(result);
}

Expand All @@ -65,7 +63,8 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[Authorize]
[HttpPost(Name = "Add[EntityName]")]
[ProducesResponseType(typeof([EntityName]Dto), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<[EntityName]Dto>> Add[EntityName](
[FromBody] [EntityName]ForCreationDto dto)
{
Expand All @@ -84,7 +83,8 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[HttpPut("{id}", Name = "Update[EntityName]")]
[ProducesResponseType(typeof([EntityName]Dto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<[EntityName]Dto>> Update[EntityName](
string id,
[FromBody] [EntityName]ForUpdateDto dto)
Expand All @@ -101,6 +101,7 @@ public sealed class [EntityName]sController(IMediator mediator) : ControllerBase
[HttpDelete("{id}", Name = "Delete[EntityName]")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult> Delete[EntityName](string id)
{
var command = new Delete[EntityName].Command(id);
Expand Down Expand Up @@ -202,12 +203,20 @@ public async Task<ActionResult<CustomerDto>> AddCustomer(CustomerForCreationDto
/// <returns>The created customer.</returns>
/// <response code="201">Returns the newly created customer.</response>
/// <response code="400">If the request data is invalid.</response>
/// <response code="422">If the request breaks a business rule.</response>
[HttpPost]
[ProducesResponseType(typeof(CustomerDto), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<CustomerDto>> AddCustomer(CustomerForCreationDto dto)
```

A 400 comes from model binding or model validation, and its body is a `ValidationProblemDetails` with an `errors` field. Declare that type on each 400, so that the OpenAPI document states the real shape.

A 422 comes from a domain rule (`ValidationException`) or a FluentValidation rule (`FluentValidation.ValidationException`). `Exceptions/DomainProblemDetails.cs` maps both to 422 with an `errors` field, so the body also has the `ValidationProblemDetails` shape. Declare the 422 on each write action (POST, PUT, PATCH, and DELETE), also when the action has no request body. A domain rule can fail in any write.

A 409 comes from a duplicate unique value (`ConflictException`, or a unique index that stops the save). Its body also has the `ValidationProblemDetails` shape. Declare the 409 on each write action that can add or change a unique value.

### 7. Use Appropriate Authorization

```csharp
Expand Down Expand Up @@ -241,18 +250,17 @@ public async Task<ActionResult<IEnumerable<ProductDto>>> GetPublicProducts() { .

## Pagination Headers

For list endpoints, add pagination metadata to response headers. The `PagedList<T>` class contains all pagination information:
A list endpoint returns a `PagedList<T>`. `PaginationHeaderFilter` adds the page data to the `X-Pagination` response header for each `PagedList<T>` result. Do not add the header in the controller.

The name of a list endpoint must end in `List`. The frontend client of such an endpoint returns the full response, so that the caller can read the header. If a `PagedList<T>` endpoint has a different name, or another endpoint has a name that ends in `List`, the Debug build fails.

```csharp
[HttpGet]
[HttpGet(Name = "GetCustomerList")]
public async Task<ActionResult<PagedList<CustomerDto>>> GetCustomerList(
[FromQuery] CustomerParametersDto parameters)
{
var query = new GetCustomerList.Query(parameters);
var result = await mediator.Send(query);

Response.AddPaginationHeader(result);

return Ok(result);
}
```
Expand All @@ -269,7 +277,8 @@ For domain-specific operations beyond CRUD:
[HttpPost("{id}/submit", Name = "SubmitOrder")]
[ProducesResponseType(typeof(OrderDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<OrderDto>> SubmitOrder(string id)
{
var command = new SubmitOrder.Command(id);
Expand All @@ -284,7 +293,8 @@ public async Task<ActionResult<OrderDto>> SubmitOrder(string id)
[HttpPost("{id}/cancel", Name = "CancelOrder")]
[ProducesResponseType(typeof(OrderDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status422UnprocessableEntity)]
public async Task<ActionResult<OrderDto>> CancelOrder(
string id,
[FromBody] CancelOrderDto dto)
Expand Down Expand Up @@ -334,17 +344,10 @@ public sealed class CustomersController(IMediator mediator) : ControllerBase

### Register New Versions

Update `ApiVersioningExtension.cs`:
Add the version to `SupportedVersions` in `ApiVersioningExtension.cs`. Each version in this list gets its own OpenAPI document. See the "API versioning" section of `docs/backend.md` for all the steps.

```csharp
public static ApiVersionSet GetApiVersionSet(this WebApplication app)
{
return app.NewApiVersionSet()
.HasApiVersion(new ApiVersion(1, 0))
.HasApiVersion(new ApiVersion(2, 0)) // Add new version
.ReportApiVersions()
.Build();
}
public static readonly ApiVersion[] SupportedVersions = [new ApiVersion(1, 0), new ApiVersion(2, 0)];
```

## Anti-Patterns to Avoid
Expand Down
15 changes: 14 additions & 1 deletion .claude/rules/backend/dtos-and-mappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ public sealed record [EntityName]ForUpdateDto

### 4. Parameters DTO (Query String)

Used for filtering, sorting, and pagination on list endpoints.
Used for filtering, sorting, and pagination on list endpoints. Give each query parameter a camelCase name with `[FromQuery(Name = ...)]`, the same as the keys of the errors of the problem. `BasePaginationParameters` names `pageNumber` and `pageSize`.

```csharp
namespace FullstackTemplate.Server.Domain.[EntityName]s.Dtos;

public sealed class [EntityName]ParametersDto : BasePaginationParameters
{
[FromQuery(Name = "filters")]
public string? Filters { get; set; }

[FromQuery(Name = "sortOrder")]
public string? SortOrder { get; set; }
}
```
Expand Down Expand Up @@ -229,6 +232,16 @@ public string Name { get; init; } = default!; // Required, always set
public string? Description { get; init; } // Optional, nullable
```

On a request DTO, mark each non-nullable value-type property (`Guid`, `int`, `bool`, and more) with `required`. Without it, a missing field binds to the default value, for example `Guid.Empty`. Then the request gets a 422 from a domain rule, not a 400, but the contract says that the field is required.

```csharp
public sealed record OrderForCreationDto
{
public required Guid CustomerId { get; init; } // A missing customerId gives 400
public string Notes { get; init; } = default!;
}
```

### 4. Keep DTOs Flat

Prefer flat structures over nested objects for API responses:
Expand Down
Loading
Loading