trace-request-lifecycle

Traces full request lifecycle from Router through Middleware, Controller, UseCase, Repository to Response. Documents HTTP methods, routes, middleware stack, response codes, and error handling paths.

59 stars

Best use case

trace-request-lifecycle is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Traces full request lifecycle from Router through Middleware, Controller, UseCase, Repository to Response. Documents HTTP methods, routes, middleware stack, response codes, and error handling paths.

Teams using trace-request-lifecycle should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/trace-request-lifecycle/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/trace-request-lifecycle/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/trace-request-lifecycle/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How trace-request-lifecycle Compares

Feature / Agenttrace-request-lifecycleStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Traces full request lifecycle from Router through Middleware, Controller, UseCase, Repository to Response. Documents HTTP methods, routes, middleware stack, response codes, and error handling paths.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Request Lifecycle Tracer

## Overview

Traces the complete lifecycle of an HTTP request or CLI command through all application layers — from entry point through middleware, handler, business logic, persistence, and back to response. Documents the full chain with data transformations at each step.

## Tracing Process

### Step 1: Identify the Request Entry

```bash
# Find route definition for the target endpoint
Grep: "#\\[Route\\(" --glob "**/*.php" -A 2
Grep: "Route::(get|post|put|delete)" --glob "**/routes/*.php"

# Find the handler for this route
# Read the route config or controller to identify the handler method
```

### Step 2: Trace Middleware Stack

```bash
# Symfony middleware (event listeners on kernel.request)
Grep: "kernel.request|kernel.controller|kernel.response" --glob "**/*.php"
Grep: "implements EventSubscriberInterface" --glob "**/*.php"

# Laravel middleware
Grep: "class.*Middleware" --glob "**/Middleware/**/*.php"
Grep: "'middleware'" --glob "**/Kernel.php"

# PSR-15 middleware
Grep: "implements MiddlewareInterface" --glob "**/*.php"

# Authentication middleware
Grep: "authenticat|JWT|Bearer|token" --glob "**/Middleware/**/*.php"

# Authorization middleware
Grep: "authoriz|permission|role|access" --glob "**/Middleware/**/*.php"
```

### Step 3: Trace Controller/Action

```bash
# Read the handler method
Read: controller/action file

# Find what it receives (Request object/DTO)
Grep: "function.*\\(.*Request|function.*\\(.*DTO|function.*\\(.*Command" in handler

# Find what it calls (service/use case)
Grep: "\\$this->.*->handle|\\$this->.*->execute|\\$this->.*->dispatch" in handler

# Find response construction
Grep: "return.*Response|return.*JsonResponse|return.*json\\(" in handler
```

### Step 4: Trace Use Case / Service

```bash
# Read the use case/service method
Read: use case file

# Find domain operations
Grep: "\\$this->.*Repository->find|\\$this->.*->save" in use case

# Find domain method calls
Grep: "\\$.*->create|\\$.*->update|\\$.*->process" in use case

# Find event dispatching
Grep: "dispatch|publish|raise" in use case
```

### Step 5: Trace Repository Operations

```bash
# Read repository implementation
Grep: "implements.*Repository" --glob "**/Infrastructure/**/*.php"

# Find query patterns
Grep: "->createQueryBuilder|->find\\(|->findOneBy" in repository

# Find persistence operations
Grep: "->persist|->flush|->save|->insert|->update" in repository
```

### Step 6: Trace Response Construction

```bash
# Response mapping
Grep: "->toArray|->toResponse|->jsonSerialize" in handler/response class

# Error responses
Grep: "ExceptionListener|ExceptionHandler|ErrorHandler" --glob "**/*.php"

# HTTP status codes used
Grep: "Response\\(.*[0-9]{3}|status.*[0-9]{3}|HTTP_" --glob "**/*.php"
```

## Output Format

```markdown
## Request Lifecycle

### Endpoint: POST /api/orders

#### Route Definition
- **Method:** POST
- **Path:** /api/orders
- **Controller:** `CreateOrderAction::__invoke`
- **Route file:** `config/routes/api.yaml:15`

#### Request Flow

```
Client Request (POST /api/orders, JSON body)
    │
    ▼
[1] Router (matches POST /api/orders → CreateOrderAction)
    │
    ▼
[2] Middleware Stack
    ├── CorsMiddleware — adds CORS headers
    ├── AuthenticationMiddleware — validates JWT token
    ├── RateLimitMiddleware — checks rate limits
    └── JsonRequestMiddleware — parses JSON body
    │
    ▼
[3] Controller/Action: CreateOrderAction::__invoke(CreateOrderRequest $request)
    │  Input: CreateOrderRequest (validated DTO)
    │  - customerId: string (from JWT)
    │  - items: array [{productId, quantity}]
    │  - shippingAddress: {street, city, zip}
    │
    ▼
[4] Use Case: CreateOrderUseCase::execute(CreateOrderCommand $command)
    │  Transforms: CreateOrderRequest → CreateOrderCommand
    │
    ├── [4a] CustomerRepository::find(customerId)
    │         Returns: Customer entity
    │
    ├── [4b] ProductRepository::findByIds(productIds)
    │         Returns: Product[] entities
    │
    ├── [4c] Order::create(customer, items, address)
    │         Domain logic: validates, calculates total
    │         Raises: OrderCreated event
    │
    ├── [4d] OrderRepository::save(order)
    │         Persists: INSERT into orders + order_items
    │
    └── [4e] EventBus::dispatch(OrderCreated)
             Async: sends to message queue
    │
    ▼
[5] Response Construction
    │  Transforms: Order entity → OrderResponse DTO
    │  OrderResponse: {id, status, total, items[], createdAt}
    │
    ▼
[6] HTTP Response
    Status: 201 Created
    Headers: Content-Type: application/json, Location: /api/orders/{id}
    Body: {"id": "...", "status": "pending", "total": 150.00, ...}
```

#### Error Paths

| Error | Where | HTTP Status | Response |
|-------|-------|-------------|----------|
| Invalid JSON | Middleware [2] | 400 | {"error": "Invalid JSON"} |
| Unauthorized | Middleware [2] | 401 | {"error": "Token expired"} |
| Validation fail | Action [3] | 422 | {"errors": {"items": "..."}} |
| Customer not found | UseCase [4a] | 404 | {"error": "Customer not found"} |
| Out of stock | Domain [4c] | 409 | {"error": "Product out of stock"} |
| DB error | Repository [4d] | 500 | {"error": "Internal error"} |

#### Data Transformation Chain

```
JSON Body → CreateOrderRequest (DTO)
  → CreateOrderCommand (CQRS Command)
    → Order Entity (Domain)
      → OrderResponse (DTO)
        → JSON Response
```

#### Key Files in Chain

| Step | File | Line | Purpose |
|------|------|------|---------|
| Route | config/routes/api.yaml | 15 | Route definition |
| Action | src/Api/Action/CreateOrderAction.php | 22 | HTTP handler |
| Request | src/Api/Request/CreateOrderRequest.php | 1 | Input validation |
| Command | src/Application/Command/CreateOrderCommand.php | 1 | CQRS command |
| UseCase | src/Application/UseCase/CreateOrderUseCase.php | 15 | Orchestration |
| Entity | src/Domain/Order/Order.php | 45 | Domain logic |
| Repo | src/Infrastructure/Repository/DoctrineOrderRepo.php | 30 | Persistence |
| Response | src/Api/Response/OrderResponse.php | 1 | Output mapping |
```

## Lifecycle Quality Indicators

| Indicator | Good | Warning |
|-----------|------|---------|
| Input validation | At boundary (Request/DTO) | In controller logic |
| Business logic | In Domain/UseCase | In controller |
| Error handling | Exception handler | Try-catch everywhere |
| Response mapping | Dedicated Response class | Array building in controller |
| Side effects | Via events (async) | Direct calls in handler |

## Integration

This skill is used by:
- `data-flow-analyst` — provides lifecycle documentation
- `trace-data-transformation` — traces DTO transformations
- `explain-business-process` — maps processes to request flows

Related Skills

trace-data-transformation

59
from dykyi-roman/awesome-claude-code

Maps data transformation chains — Request DTO to Command to Entity to Response DTO. Identifies mappers, serializers, type conversions, and data loss points across layer boundaries.

yii-knowledge

59
from dykyi-roman/awesome-claude-code

Yii framework knowledge base. Provides Yii3 modular architecture, DDD integration, PSR-7/PSR-15 compliance, persistence, DI, security (RBAC, auth), event system (PSR-14), queue/jobs, infrastructure components (cache, rate limiter, HTTP client), testing, and antipatterns for Yii PHP projects.

troubleshooting-template

59
from dykyi-roman/awesome-claude-code

Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.

testing-knowledge

59
from dykyi-roman/awesome-claude-code

Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.

task-progress-knowledge

59
from dykyi-roman/awesome-claude-code

TaskCreate pattern guidelines for progress tracking in coordinator agents

symfony-knowledge

59
from dykyi-roman/awesome-claude-code

Symfony framework knowledge base. Provides architecture, DDD integration, persistence, DI, security, messenger, workflow, events, infrastructure components, testing, and antipatterns for Symfony PHP projects.

suggest-testability-improvements

59
from dykyi-roman/awesome-claude-code

Suggests testability improvements for PHP code. Provides DI refactoring suggestions, mock opportunities, interface extraction, testing strategy recommendations.

suggest-simplification

59
from dykyi-roman/awesome-claude-code

Suggests code simplification opportunities. Identifies extract method candidates, complex expressions, redundant code, refactoring opportunities.

stability-patterns-knowledge

59
from dykyi-roman/awesome-claude-code

Stability Patterns knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Circuit Breaker, Retry, Rate Limiter, Bulkhead, and resilience audits.

solid-knowledge

59
from dykyi-roman/awesome-claude-code

SOLID principles knowledge base for PHP 8.4 projects. Provides quick reference for SRP, OCP, LSP, ISP, DIP with detection patterns, PHP examples, and antipattern identification. Use for architecture audits and code quality reviews.

scan-codebase-structure

59
from dykyi-roman/awesome-claude-code

Scans directory tree to identify architectural layers (Domain, Application, Infrastructure, Presentation), detect framework (Symfony, Laravel, custom), count files per layer, and build project structure map.

scalability-knowledge

59
from dykyi-roman/awesome-claude-code

Scalability knowledge base. Provides vertical vs horizontal scaling, stateless design, session management, connection pooling, capacity planning, and PHP-FPM tuning for scalability audits.