PHPackages                             michael4d45/effect-schema-generator - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. michael4d45/effect-schema-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

michael4d45/effect-schema-generator
===================================

Generate TypeScript interfaces and Effect schemas from PHP Spatie Data classes

v0.6.0(5d ago)0300↓29.7%MITPHPPHP ^8.3CI passing

Since Jan 12Pushed 4d agoCompare

[ Source](https://github.com/Michael4d45/Laravel-Effect-Generator)[ Packagist](https://packagist.org/packages/michael4d45/effect-schema-generator)[ RSS](/packages/michael4d45-effect-schema-generator/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (9)Versions (30)Used By (0)

Laravel Effect Schema Generator
===============================

[](#laravel-effect-schema-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/78d9aa9b7e78d6d4d53b331dcc8d0c31be12ac523b282a73f06bea89e651fe06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d69636861656c346434352f6566666563742d736368656d612d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/michael4d45/effect-schema-generator) [![Total Downloads](https://camo.githubusercontent.com/3e2138f301616a7ab74c837c03afb1c4913dbb1d51b1231ec274c93ce49cfcaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69636861656c346434352f6566666563742d736368656d612d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/michael4d45/effect-schema-generator) [![GitHub Tests Action Status](https://camo.githubusercontent.com/4f86131297e063302b6e4698f5cedbb7e29d7ed9fcadef357ed77f76a2656b60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4d69636861656c346434352f4c61726176656c2d4566666563742d47656e657261746f722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Michael4d45/Laravel-Effect-Generator/actions)

Generate TypeScript interfaces and Effect schemas from PHP Spatie Data classes. This package bridges your PHP domain models to your TypeScript frontend contracts by generating AST-based representations and transforming them into valid TypeScript code.

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

[](#installation)

You can install the package via composer:

```
composer require michael4d45/effect-schema-generator
```

You can publish the config file with:

```
php artisan vendor:publish --tag="effect-schema-config"
```

Usage
-----

[](#usage)

Define your Spatie Data classes as usual:

```
namespace App\Data;

use Spatie\LaravelData\Data;

class UserData extends Data
{
    public function __construct(
        public int $id,
        public string $name,
        public string $email,
    ) {}
}
```

Then run the generator command:

```
php artisan effect-schema:transform
```

This will generate TypeScript interfaces and Effect schemas in your configured output directory (defaults to `resources/ts/schemas`).

Commands
--------

[](#commands)

```
php artisan effect-schema:transform        # Generate schemas
php artisan effect-schema:transform --dry-run # Preview output
```

Features
--------

[](#features)

- **AST-based generation**: Robust transformation from PHP to TypeScript.
- **Spatie Data support**: Deep integration with `spatie/laravel-data`.
- **Effect Schema**: Generates not just interfaces, but runtime-validatable Effect schemas.
- **Configurable Transformers**: Easily extend the generator with custom type mappings.
- **PHPDoc Parsing**: Uses PHPDoc annotations to refine or override types.

Generated File Structure
------------------------

[](#generated-file-structure)

The generator creates TypeScript files that mirror your PHP namespace structure. For example:

```
PHP Namespaces:                  Generated TypeScript:
├── App\Data\                  ├── resources/ts/schemas/
│   ├── UserData.php           │   └── App/Data.ts
│   └── Models\                │   └── App/Data/Models.ts
│       └── GameSessionData    │
└── App\Enums\                 └── App/Enums.ts
    └── Role.php

```

Each TypeScript file contains:

- TypeScript interfaces (for the decoded types)
- Encoded interfaces (for the serialized types)
- Effect Schema definitions (for runtime validation)

### Example Output

[](#example-output)

Given this PHP Data class:

```
namespace App\Data;

use Spatie\LaravelData\Data;
use Carbon\Carbon;

class UserData extends Data
{
    public function __construct(
        public int $id,
        public string $name,
        public string $email,
        public bool $is_admin,
        public ?Carbon $email_verified_at,
    ) {}
}
```

The generator produces this TypeScript file (`App/Data.ts`):

```
import { Schema as S } from "effect";

export interface UserData {
  readonly id: number;
  readonly name: string;
  readonly email: string;
  readonly is_admin: boolean;
  readonly email_verified_at: Date | null;
}

export interface UserDataEncoded {
  readonly id: number;
  readonly name: string;
  readonly email: string;
  readonly is_admin: boolean;
  readonly email_verified_at: string | null;
}

export const UserDataSchema: S.Schema = S.Struct({
  id: S.Number,
  name: S.String,
  email: S.String,
  is_admin: S.Boolean,
  email_verified_at: S.NullOr(S.DateFromString),
});
```

### Complex Types

[](#complex-types)

The generator handles complex types, relationships, and collections:

```
namespace App\Data;

use Spatie\LaravelData\Data;
use Illuminate\Support\Collection;

class ApiResponseData extends Data
{
    /**
     * @param Collection $users
     */
    public function __construct(
        public Collection $users,
        public ?UserData $currentUser,
    ) {}
}
```

Generates:

```
import { Schema as S } from "effect";
import { UserData, UserDataEncoded, UserDataSchema } from "./User";

export interface ApiResponseData {
  readonly users: readonly UserData[];
  readonly currentUser: UserData | null;
}

export interface ApiResponseDataEncoded {
  readonly users: readonly UserDataEncoded[];
  readonly currentUser: UserDataEncoded | null;
}

export const ApiResponseDataSchema = S.Struct({
  users: S.Array(
    S.suspend((): S.Schema => UserDataSchema)
  ),
  currentUser: S.NullOr(
    S.suspend((): S.Schema => UserDataSchema)
  ),
});
```

### Enums

[](#enums)

PHP enums are converted to TypeScript type unions with corresponding schemas:

```
namespace App\Enums;

enum Role: string
{
    case HOST = 'host';
    case PLAYER = 'player';
    case SPECTATOR = 'spectator';
}
```

Generates:

```
import { Schema as S } from "effect";

export type Role = "host" | "player" | "spectator";
export const RoleSchema = S.Union(
  S.Literal("host"),
  S.Literal("player"),
  S.Literal("spectator")
);
```

Configuration
-------------

[](#configuration)

The published config supports discoverers for data classes and enums.

```
return [
  // Discoverers for Spatie Data classes
  'data_discoverers' => [
    [
      'class' => EffectSchemaGenerator\Discovery\SpatieDataClassDiscoverer::class,
      'paths' => [app_path('Data')],
    ],
  ],

  // Discoverers for native PHP enums
  'enum_discoverers' => [
    [
      'class' => EffectSchemaGenerator\Discovery\NativeEnumDiscoverer::class,
      'paths' => [app_path('Enums')],
    ],
  ],

  'transformers' => [
    // ...
  ],

  'phpdoc_overrides_types' => true,

  'output' => [
    'directory' => resource_path('js/schemas'),
    'file_extension' => '.ts',
    'clear_output_directory_before_write' => true,
  ],
];
```

Key options:

- `data_discoverers`: list of discoverer definitions (`class` + `paths`) used to find Spatie Data classes.
- `enum_discoverers`: list of discoverer definitions (`class` + `paths`) used to find PHP enums.
- `transformers`: custom type transformation and writer plugins.
- `output.directory`: destination for generated TypeScript files.
- `output.file_extension`: generated file extension (default `.ts`).
- `output.clear_output_directory_before_write`: when `true`, delete current output directory contents before writing new files.

To add a custom discoverer plugin, implement either `EffectSchemaGenerator\Discovery\DataClassDiscoverer` or `EffectSchemaGenerator\Discovery\EnumDiscoverer`, then register it in the corresponding discoverer list.

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance99

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.9% 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 ~2 days

Total

29

Last Release

5d ago

### Community

Maintainers

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

---

Top Contributors

[![Michael4d45](https://avatars.githubusercontent.com/u/2423882?v=4)](https://github.com/Michael4d45 "Michael4d45 (58 commits)")[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (12 commits)")

---

Tags

laraveltypescriptspatie-dataschema generatoreffect-ts

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/michael4d45-effect-schema-generator/health.svg)

```
[![Health](https://phpackages.com/badges/michael4d45-effect-schema-generator/health.svg)](https://phpackages.com/packages/michael4d45-effect-schema-generator)
```

###  Alternatives

[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

178.2k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

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