PHPackages                             scafera/layered - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. scafera/layered

ActiveLibrary[Framework](/categories/framework)

scafera/layered
===============

Layered architecture conventions for the Scafera framework

v1.0.5(1mo ago)0191MITPHPPHP &gt;=8.4

Since Apr 13Pushed 1mo agoCompare

[ Source](https://github.com/scafera/layered)[ Packagist](https://packagist.org/packages/scafera/layered)[ Docs](https://github.com/scafera/layered)[ RSS](/packages/scafera-layered/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

scafera/layered
===============

[](#scaferalayered)

Scafera Layered is an opinionated architecture package for the Scafera framework. It defines and enforces a strict, layered approach for building applications.

> **Provides:** Opinionated layered architecture for Scafera — defines six layers (`Controller/`, `Service/`, `Repository/`, `Integration/`, `Entity/`, `Command/`) with downward-only dependencies, and enforces them at build time via validators, advisors, and code generators run through `scafera validate` and `scafera make:*`.
>
> **Depends on:** A Scafera host project where the kernel discovers this package via `extra.scafera-architecture` in `composer.json`. User code lives in the six layer directories under `src/`.
>
> **Extension points:**
>
> - Layer directories — user code goes in `src/Controller/`, `src/Service/`, `src/Repository/`, `src/Integration/`, `src/Entity/`, `src/Command/`; each has naming/location rules enforced at build time
> - Generators — `scafera make:controller`, `make:service`, `make:command` scaffold a class + test with conventions baked in; support nested names (e.g. `Order/Create`)
> - Validators and advisors — contributed via kernel's `scafera.validator` and `scafera.advisor` tags; run by `scafera validate` in CI
> - Kernel primitives — user controllers use `#[Route]` (kernel), commands use `#[AsCommand]` (kernel)
>
> **Not responsible for:** Capability concerns — persistence (`scafera/database`), presentation (`scafera/frontend`), authentication (`scafera/auth`), forms (`scafera/form`), logging (`scafera/log`), assets (`scafera/asset`), external integrations (`scafera/integration`), translations (`scafera/translate`), file handling (`scafera/file`) · implicit execution via event subscribers or listeners (blocked by `ImplicitExecutionValidator`) · flexible or non-layered architectures (use a different architecture package).

Philosophy
----------

[](#philosophy)

In Scafera, architecture is not a guideline — it is an installed package.

This package enforces every convention at validation time via `scafera validate`, designed to run in CI. Violations are caught before code ships, not after.

All execution is explicit: no event subscribers, no listeners, no auto-discovered side effects. If behavior is not visible in the code being read, it does not happen.

Architecture model
------------------

[](#architecture-model)

The package organizes application code into six layers:

LayerPurpose`Controller/`Single-action invokables — delegate to services, no business logic`Service/`All business logic lives here`Repository/`Data access repositories`Integration/`Third-party service wrappers (Stripe, Mailgun, external APIs)`Entity/`Domain data`Command/`CLI entry points via `#[AsCommand]`Dependencies flow downward. Repository and Integration are siblings — both called by Service, neither depends on the other:

```
Controller → Service → Repository   → Entity
Command  ↗         ↘ Integration ↗

```

Validators
----------

[](#validators)

Twelve validators enforce the layered conventions:

ValidatorRule**Tests directory**Tests must be in `tests/` only**Controller location**Controllers must live in `src/Controller/`**Controller naming**No `Controller` suffix; single-word names at root, multi-word in subfolders**Single-action controllers**Must use `__invoke()`, no other public methods (except `__construct`)**Controller test parity**Every controller must have a matching test**Command test parity**Every command must have a matching test**Service location**Only recognized directories under `src/`**Service final**All services must be declared `final`**Namespace conventions**PSR-4 namespace must match file path**Layer dependencies**Enforces downward-only dependency flow; Integration sits alongside Repository as a sibling**Integration naming**Must be in vendor subfolder; class name must not repeat vendor prefix**No implicit execution**No `EventSubscriberInterface` or `#[AsEventListener]` in userlandAdvisors
--------

[](#advisors)

Non-blocking hints that never affect the exit code:

AdvisorWhat it checks**Test sync**Warns when a controller or command is modified in git but its test is notThe test sync advisor requires git and gracefully skips with a reason when prerequisites are not met.

Generators
----------

[](#generators)

Scaffold new files with conventions baked in:

GeneratorCommandWhat it creates**Controller**`scafera make:controller `Single-action controller + test**Service**`scafera make:service `Final service class + test**Command**`scafera make:command `Console command + testAll generators support nested names (e.g. `Order/Create`, `Report/Generate`) and reject convention-violating suffixes like `Controller` or `Command`.

Project structure
-----------------

[](#project-structure)

```
src/
├── Controller/    ← single-action, attribute routing
│   ├── Home.php
│   └── Order/
│       ├── Create.php
│       └── List.php
├── Command/       ← #[AsCommand], delegate to services
├── Service/       ← all business logic
├── Repository/    ← data access
├── Integration/   ← third-party service wrappers
└── Entity/        ← domain data
tests/
├── Controller/    ← one test per controller
├── Command/       ← one test per command
└── Service/       ← unit tests where needed

```

When to use
-----------

[](#when-to-use)

Use this package when you want:

- Strong conventions and predictable structure
- Clear separation of responsibilities
- Automated enforcement of architectural rules

Avoid this package if you require a flexible or custom architecture with minimal constraints.

Installation
------------

[](#installation)

```
composer require scafera/layered
```

The kernel discovers it automatically via the `scafera-architecture` Composer extra field.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4
- scafera/kernel

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

51d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e9233f415f42755f68dc3006e2853b76c34de54b04c9535202b70aa147790e6a?d=identicon)[samaphp](/maintainers/samaphp)

---

Top Contributors

[![samaphp](https://avatars.githubusercontent.com/u/531627?v=4)](https://github.com/samaphp "samaphp (38 commits)")

---

Tags

phparchitecturelayeredscafera

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/scafera-layered/health.svg)

```
[![Health](https://phpackages.com/badges/scafera-layered/health.svg)](https://phpackages.com/packages/scafera-layered)
```

###  Alternatives

[pestphp/pest-plugin-arch

The Arch plugin for Pest PHP.

4253.7M5.1k](/packages/pestphp-pest-plugin-arch)[pestphp/pest-plugin-stressless

Stressless plugin for Pest

68943.9k18](/packages/pestphp-pest-plugin-stressless)[alleyinteractive/pest-plugin-wordpress

WordPress Pest Integration

273.9k1](/packages/alleyinteractive-pest-plugin-wordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
