$ show fumeapp/modeltyper
ModelTyper is a Laravel package that generates TypeScript interfaces and types from Eloquent models. It provides artisan commands (`model:typer` and `model:typer-mappings`) to inspect model columns, accessors, relationships, counts, exists, sums, enums, and custom interfaces, producing accurate TypeScript definitions. The architecture follows Laravel package conventions with a service provider, invokable action classes, and a custom override of Laravel's ModelInspector to support custom relationships and nullable return types. The codebase is well-structured, with comprehensive test coverage and support for multiple output formats (CLI, JSON, file). It is actively maintained and supports Laravel 11.33+ and PHP 8.2+.
The LLM identified 4 files worth highlighting for reuse:
A simple, self-contained invokable class that converts a string to snake_case, camelCase, or PascalCase based on a provided case parameter. It uses Laravel's Str helper but could be easily extracted to a standalone utility. Demonstrates clean single-responsibility pattern.
Maps a PHP return type string to a TypeScript type using a provided mappings array. Handles nullable types (prefixed with '?') and unknown types gracefully. This is a reusable pattern for any code generation tool that needs to convert type strings between languages.
Generates TypeScript enum or const object definitions from a PHP backed enum reflection. Supports docblock comments, const vs plain enum syntax, and both object literal and enum output modes. Demonstrates non-obvious handling of PHP enum reflection and TypeScript template generation.
A well-documented static array mapping Laravel cast types (e.g., 'datetime', 'json', 'boolean') to TypeScript types. This is a reusable reference for any project needing to translate Laravel schema types to TypeScript. The mappings are comprehensive and include Laravel 11 additions.