PHPackages                             421c/autodoc-php - 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. 421c/autodoc-php

ActiveLibrary[API Development](/categories/api)

421c/autodoc-php
================

Automatic OpenApi documentation and TypeScript generation tool for PHP projects

v1.16.1(3mo ago)12745↓50%11MITPHPPHP ^8.1

Since Mar 5Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/421C/autodoc-php)[ Packagist](https://packagist.org/packages/421c/autodoc-php)[ RSS](/packages/421c-autodoc-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (33)Used By (1)

PHP autodoc
===========

[](#php-autodoc)

PHP autodoc automatically generates up-to-date OpenAPI 3.1.0 documentation and TypeScript types directly from your PHP code – no PHPDoc annotations required.

Instead of relying on AI or manually written comments, PHP autodoc reads your actual PHP code and native types to extract accurate type information. PHPDoc annotations are supported if present, but completely optional.

For Laravel projects, [autodoc-laravel](https://github.com/421C/autodoc-laravel) offers seamless integration with routes, request validation, database models, API resources, and more.

**Visit [phpautodoc.com](https://phpautodoc.com) to see full documentation.**

TypeScript export
-----------------

[](#typescript-export)

Define your types once in PHP and let PHP autodoc generate the matching TypeScript types automatically to keep your frontend and backend types in sync.

PHP autodoc supports exporting API request/response structures, classes, enums, PHPStan type aliases and custom PHPDoc type expressions as TypeScript types. [PHP autodoc-laravel](https://github.com/421C/autodoc-laravel) extends this functionality by offering support for Laravel models and other Laravel-specific structures that need custom handling.

See [TypeScript section in our documentation](https://phpautodoc.com) for more info and examples.

How it works?
-------------

[](#how-it-works)

PHP autodoc uses PHP parser and PHPDoc parser to analyze your code and convert it into `AutoDoc\DataTypes\Type` objects. These objects can be used in your [custom PHP autodoc extensions](https://phpautodoc.com/docs/extensions) and are also utilized in generating OpenAPI 3.1.0 schemas and TypeScript types. If you are using a static analysis tool like [PHPStan](https://phpstan.org/), you will find that autodoc works well without any changes to your codebase.

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

[](#installation)

### Using Laravel

[](#using-laravel)

To install PHP autodoc in a Laravel project, simply install the `421c/autodoc-laravel` package.

```
composer require 421c/autodoc-laravel

```

Then copy configuration file to your project using the command below.

```
php artisan vendor:publish --provider="AutoDoc\Laravel\Providers\AutoDocServiceProvider"

```

Open your `config/autodoc.php` file and set `openapi_export_dir` setting to a directory where you want to save OpenApi 3.1.0 schema JSON files generated by this package. Make sure this directory exists and is writable.

In your configuration file you can also specify URL to your API docs page with `laravel.url` setting. If you left it unchanged, you can visit `/api-docs` route to see the generated documentation.

### Manual installation

[](#manual-installation)

If you are not using Laravel framework, you can set up PHP autodoc using the following steps:

1. Install `421c/autodoc-php` package.

```
composer require 421c/autodoc-php

```

2. Create a class that extends `AutoDoc\AbstractRouteLoader` and define a `getRoutes` method. See more information in code comments below.

```
use AutoDoc\AbstractRouteLoader;
use AutoDoc\Route;

class RouteLoader extends AbstractRouteLoader
{
    public function getRoutes(): iterable
    {
        /**
         * In this method you may `return` an array of routes or `yield`
         * the routes using generator syntax like in this example.
         */

        yield new Route(
            uri: '/api/test/x',
            method: 'get',
            className: TestController::class,
            classMethod: 'x',
        );

        /**
         * You may construct the Route objects so that they point to either
         * class methods or closures.
         */

        yield new Route(
            uri: '/api/test/y',
            method: 'post',
            closure: (
                /**
                 * @return array
                 */
                function () {
                    // ...
                }
            ),
        );
    }
}
```

3. Copy the configuration file located at `vendor/421c/autodoc-php/config/autodoc.php` to your project.
4. Find `route_loader` setting and set it to your route loader class from 2. step.

```
/**
 * Class that will be used to load and analyze routes.
 * This class must extend `AutoDoc\AbstractRouteLoader`.
 */
'route_loader' => RouteLoader::class,
```

5. Find `openapi_export_dir` setting and set it to directory where you want to store OpenApi 3.1.0 schema JSON files generated by this package. Make sure it exists and is writable.

```
/**
 * Directory where OpenApi schema files will be exported.
 */
'openapi_export_dir' => '/path/to/openapi',
```

6. Depending on your project setup, define a new route that will accept a GET request and return the OpenApi JSON schema. In this route, add the following code:

```
$autodocConfig = new \AutoDoc\Config(require '/path/to/your/config/autodoc.php');
$workspace = \AutoDoc\Workspace::getDefault($autodocConfig);

echo $workspace->getJson();
```

You can read more about workspaces [here](https://phpautodoc.com/docs/workspaces).

7. Create another route that will be used to view your documentation. In this route, add the following code:

```
$autodocConfig = require '/path/to/your/config/autodoc.php';

// The route you created in previous step.
$openApiUrl = '/docs/openapi-json';

$docViewer = new \AutoDoc\DocViewer(
    title: $autodocConfig['api']['title'],
    openApiUrl: $openApiUrl,
    theme: $autodocConfig['ui']['theme'],
    logo: $autodocConfig['ui']['logo'],
    hideTryIt: $autodocConfig['ui']['hide_try_it'],
);

$docViewer->renderPage();
```

Now you can visit this route and see the generated documentation.

To improve the generated documentation, see [tips to improve the generated documentation](https://phpautodoc.com/#tips-to-improve-the-generated-documentation).

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~11 days

Recently: every ~4 days

Total

31

Last Release

96d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43956161?v=4)[Edžus](/maintainers/edzus)[@edzus](https://github.com/edzus)

---

Top Contributors

[![edzus](https://avatars.githubusercontent.com/u/43956161?v=4)](https://github.com/edzus "edzus (2 commits)")[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/421c-autodoc-php/health.svg)

```
[![Health](https://phpackages.com/badges/421c-autodoc-php/health.svg)](https://phpackages.com/packages/421c-autodoc-php)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.0k7.8M57](/packages/dedoc-scramble)[zircote/swagger-php

Generate interactive documentation for your RESTful API using PHP attributes (preferred) or PHPDoc annotations

5.3k132.9M468](/packages/zircote-swagger-php)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[phpdocumentor/phpdocumentor

Documentation Generator for PHP

4.4k3.1M878](/packages/phpdocumentor-phpdocumentor)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[jane-php/jane-php

All jane libraries into one repository

678254.7k4](/packages/jane-php-jane-php)

PHPackages © 2026

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