GhaylStackDocumentationv1.0.2
العربيةWebsite
Architecture

Architecture

Trace an API request

Follow brand creation from HTTP input to validation, authorization and persistence.

Start with a concrete request

Catalog's create-brand operation is POST /api/v1/catalog/brands. The body matches CreateBrandCommand: required name, optional description and logoUrl. Use a token issued for the intended tenant and a user with Permissions.Catalog.Brands.Create.

The following is an HTTP request shape. Replace the host and access token with your development values; it is not a credential or a script to run unchanged.

http
POST /api/v1/catalog/brands HTTP/1.1
Host: localhost:<api-port>
Authorization: Bearer <access-token>
Content-Type: application/json
Idempotency-Key: create-brand-training-001

{"name":"Training Supplies","description":"Development example"}

Understand the shared pipeline

The API calls tenant resolution before its platform pipeline. Authenticated users resolve through their tenant claim; a mismatched request header does not switch an ordinary user's tenant. The platform configures exception handling, forwarded headers, CORS, HTTPS, routing, authentication, localization, module middleware, rate limits, quotas and authorization. The ordering is implemented in Web/Extensions.cs.

For this endpoint, the Catalog group requires authorization and endpoint metadata requires the create permission. Do not treat a successful token check as proof that the user may create a brand. Group and endpoint permission requirements are combined by the authorization handler.

Move from transport to business behavior

CreateBrandEndpoint sends the command through IMediator. ValidationBehavior runs registered FluentValidation validators before the handler. The brand validator rejects an empty name, names above 128 characters, descriptions above 1024 and logo URLs above 512.

CreateBrandCommandHandler calls Brand.Create, checks whether the generated slug already exists, adds the entity and calls SaveChangesAsync. A duplicate name produces a conflict error. The handler returns the new identifier; the endpoint wraps it in a successful response. These details come from this feature, not a universal rule that every create operation has the same response shape.

Observe persistence and retries

CatalogDbContext configures the catalog schema and inherits tenant isolation and soft-delete behavior from BaseDbContext. Its model applies entity configurations before calling the base model builder. The effective tenant is therefore part of the data operation, not a freely supplied field in the JSON body.

The endpoint opts into HTTP idempotency. Reuse one key only when retrying the same logical operation. Use a new key for a new intended creation. A replay cache does not replace unique constraints or domain validation, and its behavior is separate from an event consumer's inbox.

Verify and diagnose

Test a valid creation, empty name, duplicate name, missing token, missing permission and an attempt to observe the record from another tenant. Use the response's trace information to correlate an error with server logs.

Symptom First place to inspect
404 for a new feature Route mapping and module registration
401 Token validity and authentication scheme
403 Permission, tenant state and organizational scope where required
Validation error Command shape and validator
Conflict Existing domain record or idempotency state
Missing table Migrator result and migrations assembly

Continue with adding a feature, authorization and persistence.

Implementation references

View MarkdownBack to top

Search documentation

Use ↑ ↓ to move, Enter to open and Esc to close.