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

Architecture

Module boundaries and contracts

Keep dependencies explicit and use the existing architecture checks when extending the platform.

Separate the public contract from implementation

A typical module has Modules.<Name>.Contracts and Modules.<Name>. Contracts contain commands, queries, DTOs, service interfaces and permission names that other modules may use. Runtime code contains handlers, entities, persistence configuration and endpoint registration.

Catalog demonstrates the split. Modules.Catalog.Contracts references Mediator abstractions and shared contracts. Its runtime references persistence, web infrastructure, its own contracts and Files contracts. Product image authorization uses the Files contract IFileAccessPolicy; it does not require Files' database context.

Decide which dependency belongs where

Need Suitable dependency Avoid
Ask another module for data or an operation Its published contract Referencing its feature handler directly
React to a completed business event Integration-event contract and handler Reading another module's private table
Persist your module's entities Your module's DbContext Adding unrelated entities to Identity
Reuse framework behavior The relevant building block Duplicating caching, mail or tenant resolution
Compose the application Module entry type in the host Business decisions in Program.cs

A shared contract is a versioned promise. Changing a DTO or command requires checking callers in both React clients and other modules. Treat an event payload change similarly: queued events may outlive the build that created them.

Keep features together

Within the runtime module, features live under Features/v1/<Area>/<Operation>. For example, Catalog's brand creation groups the endpoint, validator and handler while the command remains in Contracts. Open those files together when investigating a bug; spreading a single operation across generic service layers makes ownership harder to follow.

Domain entities enforce business invariants. Validators provide request-level input feedback. Endpoints describe transport behavior. Do not move a business decision into an endpoint merely because that file receives the HTTP request first.

Register the module intentionally

IModule exposes ConfigureServices, MapEndpoints and optional ConfigureMiddleware. An assembly-level FshModule attribute identifies its entry type and ordering. These existing identifiers are part of the current code; use the actual types when extending it.

The host supplies an explicit assembly list to AddModules. The loader reads registration attributes, registers validators and calls each module's service setup in order. Endpoint mapping happens later. Missing registration can leave valid code unreachable even though the solution builds.

Use architecture tests as a review aid

Run the focused suite after adding project references:

sh
dotnet test src/Tests/Architecture.Tests -c Release

Inspect ModuleArchitectureTests, ContractsPurityTests, BuildingBlocksIndependenceTests and CircularReferenceTests when a rule fails. Correct the dependency rather than bypassing the rule for convenience. The test suite also contains naming, endpoint and tenant-isolation conventions; read the failed assertion for the exact rule.

For verification, ask whether the new feature can be understood from its contract and owning module, whether another module can call it without runtime coupling, and whether its data remains tenant-scoped. Continue with adding a module for the composition checklist.

Implementation references

View MarkdownBack to top

Search documentation

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