Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Oi Laravel Ts Laravel Package

oi-lab/oi-laravel-ts

Generates TypeScript interfaces from Laravel Eloquent models, including relationships, casts, PHPDoc types, and DataObjects. Supports watch mode, namespace filtering, UUID/ULID key typing, and optional JSON-LD output.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strong alignment with Laravel ecosystem: Designed specifically for Laravel 11/12/13 with Eloquent model integration, making it a natural fit for PHP backend teams using Laravel.
  • Modular pipeline architecture: Clear separation between model analysis (PHP → schema) and TypeScript generation, allowing for future extensibility (e.g., adding new cast types or relationship handlers).
  • TypeScript-first mindset: Generates production-ready interfaces with proper typing for relationships, casts, and custom properties, reducing manual type definition work.

Integration Feasibility

  • Low friction for Laravel projects: Requires minimal setup (Composer install + config publish) and integrates seamlessly with existing Eloquent models.
  • Non-intrusive: Operates as a build-time tool (no runtime overhead) and generates static TypeScript files, avoiding runtime dependencies.
  • Watch mode support: Enables CI/CD-friendly workflows with automatic regeneration on model changes.

Technical Risk

  • Dependency on Eloquent conventions: Assumes standard Laravel model structures (e.g., $fillable, $casts). Custom model traits or non-standard attributes may require configuration tweaks.
  • TypeScript output quality: While robust, the generated interfaces rely on accurate PHP-to-TypeScript type mapping (e.g., custom casts, DataObjects). Edge cases (e.g., complex nested casts) may need manual overrides.
  • Namespace exclusions: Misconfigured excluded_namespaces or extended_namespaces could lead to broken imports or missing types in generated files.

Key Questions

  1. Model Complexity: How many custom casts/DataObjects exist in the codebase? Will they require manual overrides in custom_props?
  2. TypeScript Workflow: Is the team using a monorepo or separate frontend/backend repos? How will the generated .ts file be shared?
  3. CI/CD Integration: Should the generator run as a pre-commit hook, in CI, or on-demand? Does the team need a custom Artisan command wrapper?
  4. Performance: For large codebases (100+ models), will the initial generation or watch mode introduce noticeable latency?
  5. Testing Strategy: How will TypeScript tests (e.g., unit tests for generated interfaces) be managed? Will the generator’s output be version-controlled?

Integration Approach

Stack Fit

  • Laravel Backend: Ideal for teams using Laravel + TypeScript (e.g., with Inertia.js, Vue/React frontend).
  • PHP 8.2+: Leverages modern PHP features (e.g., named arguments, attributes) for accurate type extraction.
  • TypeScript Frontend: Generates interfaces consumable by frontend frameworks (React, Vue, Svelte) or API clients.

Migration Path

  1. Pilot Phase:
    • Start with a subset of critical models (e.g., User, Order) to validate output quality.
    • Configure excluded_namespaces to exclude third-party models initially.
  2. Incremental Rollout:
    • Enable discover_related_models gradually to avoid generating excessive interfaces upfront.
    • Use custom_props to handle edge cases before expanding to all models.
  3. Frontend Adoption:
    • Replace manual .d.ts files with generated interfaces.
    • Update API clients (e.g., Axios interceptors) to use the new types.

Compatibility

  • Laravel Versions: Tested on 11/12/13; verify compatibility with any custom Eloquent traits or model macros.
  • TypeScript Ecosystem: Output is compatible with modern tooling (e.g., tsc, ESLint, Prettier).
  • DataObject Support: Requires PHP DataObjects to follow standard patterns (e.g., __construct with typed properties).

Sequencing

  1. Setup:
    • Install package (composer require).
    • Publish config (php artisan vendor:publish).
    • Configure output_path and excluded_namespaces.
  2. Generate:
    • Run php artisan oi:gen-ts to produce initial output.
    • Review generated interfaces.ts for accuracy.
  3. Iterate:
    • Adjust custom_props or config as needed.
    • Enable watch mode (--watch) for development.
  4. Deploy:
    • Integrate generated file into frontend build process (e.g., copy to node_modules/@types or shared folder).
    • Update CI to regenerate on model changes.

Operational Impact

Maintenance

  • Configuration-Driven: Most maintenance involves updating config/oi-laravel-ts.php (e.g., adding new custom_props or adjusting excluded_namespaces).
  • Dependency Updates: Monitor for Laravel/PHP version compatibility; test after major releases.
  • Schema Drift: Regenerate interfaces after database migrations or model changes (watch mode automates this).

Support

  • Debugging: Use save_schema: true in config to inspect intermediate JSON schema for issues.
  • Common Issues:
    • Missing Types: Verify discover_related_models is enabled or manually add missing models to custom_props.
    • Type Mismatches: Override problematic casts in custom_props (e.g., email_verified_at: Date).
    • Build Errors: Ensure generated .ts file is included in TypeScript’s include paths.

Scaling

  • Large Codebases:
    • Use multi-file output (if supported in future versions) to avoid giant .ts files.
    • Exclude non-critical models with excluded_namespaces.
  • Performance:
    • Initial generation may take seconds for 100+ models; cache the output in CI.
    • Watch mode uses filesystem events; test on high-churn environments.

Failure Modes

Scenario Impact Mitigation
Model schema changes Broken TypeScript types Enable watch mode or CI regeneration.
Custom cast misconfiguration Incorrect TypeScript types Use custom_props to override.
Frontend build breaks Missing/incorrect interfaces Version-control generated files.
PHP version incompatibility Package fails to install/run Pin PHP version in composer.json.

Ramp-Up

  • Onboarding:
    • Document the config/oi-laravel-ts.php schema for the team.
    • Create a runbook for common issues (e.g., "How to add a custom cast type").
  • Training:
    • Demo the watch mode workflow for developers.
    • Show how to use generated interfaces in frontend code (e.g., Inertia.js props).
  • Tooling:
    • Add a Git pre-commit hook to regenerate interfaces before commits.
    • Integrate with frontend build tools (e.g., Vite/Webpack) to copy the .ts file.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony