Automatic API documentation
and TypeScript types for PHP projects

PHP autodoc analyzes your actual PHP code to generate accurate API documentation and TypeScript types, keeping your frontend and backend in sync without manual work.

Get Started
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rules\Enum;

class OrderController
{
    public function update(Request $request, Order $order): JsonResponse
    {
        $validated = $request->validate([
            'status' => ['required', new Enum(OrderStatus::class)],
        ]);

        if ($order->status === OrderStatus::Completed) {
            return response()->json([
                'status_updated' => false,
                'message' => 'Completed orders can’t be changed',
                'order' => array_filter($order->toArray()),
            ], 400);
        }

        $order->update([
            'status' => $validated['status'],
        ]);

        return response()->json([
            'status_updated' => true,
            'products' => $order->products->map(fn ($product) => [
                'id' => $product->id,
                'name' => $product->name,
                'updated_at' => $product->updated_at,
            ]),
        ]);
    }
}

PATCH/api/orders/{order}

Parameters

Path

orderinteger
required

Request Body

application/json
statusinteger

1234
required

Responses

Bodyapplication/json
status_updatedboolean
required
productsarray<object>
required
idinteger
required
namestring
required
updated_atstring<date-time> or null
required
Bodyapplication/json
status_updatedboolean
required
messagestring
Completed orders can’t be changed
required
orderobject
required
idinteger
required
statusinteger

1234
required
created_atstring<date-time>
updated_atstring<date-time>

Introduction

PHP API Documentation and TypeScript Type Generator

PHP autodoc generates OpenAPI 3.1.0 documentation and TypeScript types from your PHP code. It reads native types, analyzes the code, and uses PHPDoc when available. As your code changes, the generated documentation and types stay aligned with it.

For Laravel projects, autodoc-laravel adds support for routes, request validation, Eloquent models, API resources, and other Laravel features.

See the installation guide to add PHP autodoc to a Laravel project or any other PHP application.

To see what the generated documentation looks like, check the live demo.

TypeScript export

Keep your backend and frontend types aligned without maintaining the same structures twice. autodoc ts command scans your frontend for @autodoc tags and updates the TypeScript declarations they identify.

You can export API request and response types, classes, enums, PHPStan type aliases, and custom PHPDoc expressions. autodoc-laravel adds support for Laravel models and other framework-specific structures.

See TypeScript export for configuration and examples.

How it works

PHP autodoc is built on nikic/PHP-Parser and phpstan/phpdoc-parser. It analyzes type hints, return statements, branching logic, array shapes, enums and generics, while tracking variable assignments, mutations and type narrowing.

Every resolved value becomes an AutoDoc\DataTypes\Type object. The same type representation drives both OpenAPI schemas and TypeScript declarations, and is available to custom extensions when your project needs domain-specific handling.

When a type cannot be resolved exactly, PHP autodoc uses a less specific type and keeps going. More complete type declarations and PHPDoc improve the generated output. PHPStan can help find missing or inconsistent types.

Tips to improve the generated documentation
  1. If a value resolves to unknown, enable debug.enabled and use the debugging tools to trace its source.
  2. Increase the max_depth setting when nested calls or structures are cut short. Higher values allow deeper analysis at the cost of speed.
  3. Run a static analyzer such as PHPStan. Fixing ambiguous or inconsistent types also gives PHP autodoc better information to work with.
  4. Add custom extensions for domain-specific objects, helper methods or framework behavior that PHP autodoc cannot recognize by default.