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.
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.
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.
- If a value resolves to
unknown, enabledebug.enabledand use the debugging tools to trace its source. - Increase the
max_depthsetting when nested calls or structures are cut short. Higher values allow deeper analysis at the cost of speed. - Run a static analyzer such as PHPStan. Fixing ambiguous or inconsistent types also gives PHP autodoc better information to work with.
- Add custom extensions for domain-specific objects, helper methods or framework behavior that PHP autodoc cannot recognize by default.