PHPackages                             doctreen/doctreen - 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. [API Development](/categories/api)
4. /
5. doctreen/doctreen

ActiveLibrary[API Development](/categories/api)

doctreen/doctreen
=================

Code-first API docs + OpenAPI 3.1 export + runtime validation for PHP. Define your route shape once with a fluent schema builder and get an interactive docs UI, OpenAPI 3.1 export, and 422-on-invalid-request validation. Laravel-first. PHP port of the doctreen npm package.

v0.1.1(today)00MITPHPPHP &gt;=8.2CI passing

Since Aug 1Pushed todayCompare

[ Source](https://github.com/CanDgrmc/doctreen-php)[ Packagist](https://packagist.org/packages/doctreen/doctreen)[ Docs](https://doctreen.dev)[ RSS](/packages/doctreen-doctreen/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

DocTreen for PHP
================

[](#doctreen-for-php)

**One schema per route. Get docs, OpenAPI 3.1 export, *and* runtime validation. No YAML.**

PHP port of the [doctreen](https://www.npmjs.com/package/doctreen) npm package — code-first API documentation for Laravel (Symfony and PSR-15 planned).

> **Status: early development.** Phases 1–3 are in place: schema builder, `->doc()` route macro, interactive docs UI (shared with the npm package), OpenAPI 3.1 export with `$ref` dedup / callbacks / webhooks (parity-tested against the npm exporter's output), 422 request validation with query &amp; path-param coercion, status-aware response validation, config-level default errors, schema drift detection (cache-backed store, `/docs/drift.json`, guarded reset), runnable integration flows (docs-UI runner + `doctreen-flow` CLI), a spec-driven mock server (`doctreen mock` — CRUD short-circuits, latency/error injection, optional Faker), and PHP codegen (`doctreen codegen types|client` — readonly DTOs + a zero-dependency typed client). The full CLI is in place (`mock`, `codegen`, `lint openapi`, `emit-openapi`, `drift report|reset`, `doctreen-flow`). Next up: Symfony and PSR-15 adapters.

The idea
--------

[](#the-idea)

```
use Doctreen\Schema\S;

Route::post('/users', [UserController::class, 'store'])->doc([
    'description' => 'Create a user',
    'request'  => ['body' => S::object(['name' => S::string(), 'email' => S::string()])],
    'response' => S::object(['id' => S::number(), 'name' => S::string(), 'email' => S::string()]),
    'errors'   => [409 => 'Email already in use'],
]);
```

That single declaration will drive:

- `GET /docs` — interactive docs UI (the same zero-dependency UI the npm package ships)
- `GET /docs/openapi.json` — OpenAPI 3.1 export
- `POST /users` with an invalid body — structured `422` before your handler runs

Install
-------

[](#install)

```
composer require doctreen/doctreen
```

Requires PHP ≥ 8.2. Zero runtime dependencies — the Laravel service provider is auto-discovered and simply never loads outside Laravel.

CLI
---

[](#cli)

```
# Spec-driven mock server (from a live docs URL or a spec file)
vendor/bin/doctreen mock --from https://api.example.com/docs --port 4000

# Typed PHP codegen: readonly DTOs + a zero-dependency client
vendor/bin/doctreen codegen types  --from openapi.json --out src/Api/Types.php  --namespace 'App\Api'
vendor/bin/doctreen codegen client --from openapi.json --out src/Api/Client.php --namespace 'App\Api'

# Headless flow runner (same flow JSON the docs UI runs)
vendor/bin/doctreen-flow run doctreen-flows/onboarding.json --input email=a@b.c --report json

# Lint your spec, emit it offline, watch for drift in CI
vendor/bin/doctreen lint openapi --url http://localhost:8000/docs --fail-on warning
vendor/bin/doctreen emit-openapi --app . --out openapi.json
vendor/bin/doctreen drift report --url https://api.example.com/docs --fail-on-mismatch
```

Roadmap
-------

[](#roadmap)

1. **Core** — schema builder · route registry · `->doc()` macro · docs UI · OpenAPI 3.1 export · request validation (422)
2. **Contract safety** — status-aware response validation · default errors · schema drift detection
3. **Tooling** — mock server · PHP codegen (typed DTOs + client) · flows
4. **Polish** — `lint openapi` · `emit-openapi` · `drift report` / `drift reset` CLI
5. **Beyond Laravel** — Symfony and PSR-15 adapters

License
-------

[](#license)

MIT

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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 ~0 days

Total

2

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8db5327d6724a6d0f2b9d5cfae547689db43e23770dacff83a0c4f163a6ab68a?d=identicon)[CanDgrmc](/maintainers/CanDgrmc)

---

Top Contributors

[![CanDgrmc](https://avatars.githubusercontent.com/u/18559925?v=4)](https://github.com/CanDgrmc "CanDgrmc (3 commits)")

---

Tags

middlewareapilaravelschemavalidationdocumentationopenapirequest validationapi-docscode-firstmock-serverlaravel-docsopenapi-3-1schema-drift

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k38.9M144](/packages/darkaonline-l5-swagger)[juststeveking/laravel-redoc

A simple API documentation package for Laravel using OpenAPI and Redoc

92321.6k1](/packages/juststeveking-laravel-redoc)

PHPackages © 2026

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