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

Scribe Laravel Package

knuckleswtf/scribe

Generate human-friendly API docs from your Laravel codebase. Scribe outputs a sleek single-page HTML doc with code samples and “Try It Out”, plus Postman collections and OpenAPI specs. It can extract params from validation/FormRequests and auto-generate sample responses.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Integration: Scribe is purpose-built for Laravel, leveraging its routing, validation, and API resource systems. It extracts metadata from Laravel’s core components (e.g., FormRequest, Route::apiResource, #[BodyParam] attributes) to auto-generate documentation, reducing manual effort.
  • OpenAPI/Postman Alignment: Generates OpenAPI 3.0/3.1 specs and Postman collections, ensuring compatibility with modern API tooling. The OpenAPI 3.1 support (configurable via openapi.version) aligns with industry standards.
  • Extensibility: Supports custom strategies (e.g., for validation rules, API resources) and hooks (e.g., afterExtracting), allowing TPMs to tailor documentation to edge cases (e.g., legacy endpoints, non-standard responses).
  • UI/UX Layer: Provides a human-readable HTML doc with interactive "Try It Out" panels, reducing reliance on external tools like Swagger UI.

Integration Feasibility

  • Low Friction: Requires minimal setup (install via Composer, publish config, run php artisan scribe:generate). No need to modify existing routes or controllers—it infers endpoints from Laravel’s routing system.
  • Dependency Compatibility: Supports Laravel 10+ (tested up to v13) and PHP 8.1+. Dependencies like symfony/yaml (v8) and parsedown/parsedown (PHP 8.4 compatible) are well-maintained.
  • Validation Rule Extraction: Automatically parses Laravel’s FormRequest classes and validator rules (including sometimes, nested arrays) to document request schemas accurately.
  • Response Handling: Supports Eloquent API Resources, Transformers, and streamed responses, ensuring dynamic data structures (e.g., polymorphic relationships) are documented.

Technical Risk

  • Dynamic Response Generation: Scribe calls endpoints to fetch sample responses, which may:
    • Expose sensitive data if endpoints return PII or auth tokens. Mitigation: Use ignore_endpoints in config or mock responses.
    • Fail silently for protected routes (e.g., auth middleware). Mitigation: Configure ignore_middleware or use afterExtracting hooks to filter endpoints.
  • Complex Validation Rules: Nested or custom validation logic (e.g., Rule::unique) may not render perfectly in OpenAPI. Risk: Manual overrides via @property annotations or custom strategies.
  • Performance Overhead: Generating docs for large APIs (100+ endpoints) may require significant runtime. Mitigation: Cache generated files or run during off-peak hours.
  • Breaking Changes: Major versions (e.g., 5.x) may require config updates. Risk: Test thoroughly during upgrades (e.g., OpenAPI 3.1 syntax changes).

Key Questions for TPM

  1. Scope of Documentation:
    • Should Scribe document all routes or only a subset (e.g., /api/v1/*)? Use ignore_endpoints or route groups.
    • Are there internal/undocumented endpoints (e.g., admin panels) that need exclusion?
  2. Data Sensitivity:
    • How should authenticated endpoints (e.g., /user/profile) be handled? Options: Mock responses, ignore middleware, or use afterExtracting.
  3. Customization Needs:
    • Are there non-standard responses (e.g., custom error formats, GraphQL-like payloads) requiring custom strategies?
    • Should the UI theme (e.g., colors, branding) be customized? Extend via Blade templates or CSS overrides.
  4. CI/CD Integration:
    • Should doc generation be automated in CI (e.g., GitHub Actions) to ensure freshness? Example workflow:
      - name: Generate API Docs
        run: php artisan scribe:generate
      - name: Deploy Docs
        uses: peaceiris/actions-gh-pages@v3
        with: publish_dir=storage/scribe
      
  5. OpenAPI Version:
    • Should the team adopt OpenAPI 3.1 (nullable syntax) or stick with 3.0.3 for broader tooling compatibility?
  6. Testing:
    • How will doc accuracy be validated? Options: Manual review, automated tests against the OpenAPI spec, or integration with tools like Spectral.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Scribe is Laravel-first, with deep integration into:
    • Routing: Auto-discovers routes via RouteServiceProvider.
    • Validation: Extracts rules from FormRequest classes and Validator facade.
    • API Resources: Supports Illuminate\Http\Resources\ApiResource and Spatie\Transformers.
    • Middleware: Can ignore protected routes (e.g., auth:api) via config.
  • Tooling Compatibility:
    • Postman: Generates .json collections for direct import.
    • Swagger/OpenAPI: Outputs specs consumable by tools like Redoc, Stoplight, or API Gateway.
    • GraphQL: Limited support (focuses on REST; may need custom strategies for GraphQL APIs).
  • PHP Extensions:
    • Requires PHP 8.1+ (for attributes like #[BodyParam]).
    • Uses Symfony YAML (v8) and Parsedown for Markdown parsing.

Migration Path

  1. Assessment Phase:
    • Audit existing API routes and validation logic to identify gaps (e.g., undocumented endpoints, complex rules).
    • Review current documentation tools (e.g., manual Swagger specs, Postman collections) to define scope.
  2. Pilot Integration:
    • Install Scribe in a staging environment:
      composer require knuckleswtf/scribe
      php artisan vendor:publish --provider="Knuckles\Scribe\ScribeServiceProvider"
      php artisan scribe:generate
      
    • Test with a subset of endpoints (e.g., /api/v1/products) to validate:
      • Request/response schemas.
      • Interactive "Try It Out" functionality.
      • OpenAPI spec accuracy.
  3. Configuration:
    • Customize config/scribe.php:
      'base_url' => env('APP_URL'),
      'ignore_endpoints' => [
          'admin/*',
          'health-check',
      ],
      'openapi.version' => '3.1.0', // or '3.0.3'
      
    • Extend via custom strategies (e.g., for #[Deprecated] attributes) or hooks (e.g., afterExtracting).
  4. CI/CD Pipeline:
    • Add doc generation to CI (e.g., post-merge to main):
      php artisan scribe:generate --output=storage/scribe
      
    • Deploy generated files to a static host (e.g., GitHub Pages, Netlify) or integrate with existing docs.
  5. Phased Rollout:
    • Phase 1: Document public APIs (e.g., /api/v1/*).
    • Phase 2: Add internal APIs (e.g., /api/internal/*) with sensitivity controls.
    • Phase 3: Customize UI/theme and automate validation (e.g., Spectral tests).

Compatibility

  • Laravel Versions: Officially supports 10–13; test for 9.x if needed (may require legacy branches).
  • PHP Versions: 8.1+ (PHP 8.4 fixes in v5.7.0).
  • Dependencies:
    • Symfony YAML v8: Required for OpenAPI generation.
    • Parsedown: Updated for PHP 8.4 compatibility.
    • No Conflicts: Replaces spatie/data-transfer-object with its own DTO implementation.
  • Edge Cases:
    • Dynamic Routes: Handles optional/required path params (e.g., /users/{user}).
    • Polymorphic Relations: Documents responses with morphTo or belongsToMany.
    • Custom Responses: Supports non-JSON formats (e.g., problem+json) via content_types.

Sequencing

  1. Pre-requisites:
    • Ensure Laravel app is fully routed (no dynamic route registration at runtime).
    • Validate validation rules are in FormRequest classes or Validator facade.
  2. Core Setup:
    • Install package and publish config.
    • Generate initial docs and review for accuracy.
  3. Customization:
    • Add custom strategies for unsupported features (e.g., GraphQL).
    • Extend Blade templates for UI changes.
  4. Automation:
    • Integrate into CI/CD.
    • Set up monitoring (e.g., alert on doc generation failures).
  5. Post-Launch:
    • Deprecation: Use #[Deprecated] attributes to mark endpoints.
    • Feedback Loop: Gather input from devs/consumers to refine docs.

Operational Impact

**Main

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.
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager