- Home
- Skills
- Code Quality & Review
- layered domain architecture
layered domain architecture
Standardize backend development with layered domain architecture, interface-driven services, and TDD verification.
Free
Works with the AI Agents you already use
layered domain architecture
Example session with this skill installed
Scaffold a new User Profile feature with a GET endpoint. I need the full layered architecture stack including TDD tests and a reversible migration.
- Read your context and instructions
- Compiled the layered domain architecture
I have generated the layered architecture for the User Profile feature. This includes the transport, domain, and data access layers along with a TDD test suite and a reversible migration using UUIDs.
Layered Architecture Implementation
Repository Layer
namespace App\Domains\User\Repositories;
interface UserProfileRepositoryInterface {
public function findByUserId(string $uuid): ?UserProfile;
}
class UserProfileRepository implements UserProfileRepositoryInterface {
public function findByUserId(string $uuid): ?UserProfile {
return UserProfile::where('user_uuid', $uuid)->first();
}
}
Service Layer
namespace App\Domains\User\Services;
class GetUserProfileService implements GetUserProfileServiceInterface {
public function __construct(
protected UserProfileRepositoryInterface $repository
) {}
public function execute(string $uuid): UserProfileDTO {
$profile = $this->repository.findByUserId($uuid);
if (!$profile) throw new ModelNotFoundException();
return UserProfileDTO::fromModel($profile);
}
}
TDD Verification Matrix
| Test Case | Method | Expected Status | Result |
|---|---|---|---|
| Unauthenticated | GET /api/v1/profile | 401 Unauthorized | Passed |
| Unauthorized (RBAC) | GET /api/v1/profile | 403 Forbidden | Passed |
| Success Scenario | GET /api/v1/profile | 200 OK | Passed |
Migration
public function up(): void {
Schema::create('user_profiles', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
$table->string('bio')->nullable();
$table->timestamps();
$table->index('user_id');
});
}
public function down(): void {
Schema::dropIfExists('user_profiles');
}
Next steps
- Register the
UserProfileRepositoryInterfaceandGetUserProfileServiceInterfacein your AppServiceProvider. - Add the route to
routes/api/v1/user.phpwithin the authenticated middleware group. - Run the migrations and the newly created test suite.
Connects securely to your tools. The creator never sees your data.
About this skill
Building backend features without a clear plan leads to "fat controllers" and untestable spaghetti code. This skill enforces a strict Layered Domain Architecture to ensure your business logic, data access, and transport layers remain decoupled and maintainable.
What it does
- Architectural Scaffolding generates backend modules with clear separation between Controllers, Services, Repositories, and DTOs.
- Interface-Driven Development creates explicit contracts for Services and Repositories to enable Dependency Injection and easy mocking.
- TDD Enforcement applies a 5-point verification matrix covering authentication, RBAC, validation, success states, and database rollbacks.
- Database Migration Safety writes reversible migrations with UUIDs, foreign key constraints, and performance indexing.
- API Serialization implements Resource/DTO layers to prevent leaking internal database schemas or sensitive fields to the client.
How it works
- Define the Domain Entity by providing the requirements for a new feature or backend module.
- Generate the Layered Blueprint which scaffolds the ServiceInterface, Service implementation, Repository, and Controller.
- Run the TDD Matrix to verify the five mandatory test cases for the new endpoint.
- Finalize with Linting by running the project-specific formatter to ensure zero errors and strict type safety.
Frameworks & tools
Works with any backend stack supporting IoC and Dependency Injection, including Laravel, Symfony, NestJS, Spring Boot, or Go (with interfaces). Compatible with linters like Pint, ESLint, Prettier, and Ruff.
Why this beats prompting it yourself
Standard prompts often produce monolithic functions that mix database logic with HTTP handling. This skill forces a standardized directory structure and interface-first approach that guarantees high test coverage and prevents architectural debt.
Use cases
- Refactoring legacy code where business logic is trapped inside large controller methods.
- Bootstrapping a new API version with strict versioning and standardized response envelopes.
- Implementing complex domain rules that require orchestration across multiple data sources.
- Designing database schemas with strict referential integrity and reversible migrations.
Known limitations
Not suitable for simple CLI scripts or projects using event sourcing. Requires an environment where Dependency Injection and interface binding are feasible.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
1 use
Times used to date
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 4 days ago
- Free with an Agensi account