Skip to content

Instantly share code, notes, and snippets.

@dandean
Last active October 16, 2025 20:19
Show Gist options
  • Select an option

  • Save dandean/6e437ade8ab5241d7e87c34114f2770d to your computer and use it in GitHub Desktop.

Select an option

Save dandean/6e437ade8ab5241d7e87c34114f2770d to your computer and use it in GitHub Desktop.
Nest Lifecycle
sequenceDiagram
    participant Client
    participant Middleware
    participant Guards
    participant Interceptors
    participant Pipes
    participant Controller
    participant ExceptionFilters
    participant Response

    Client->>Middleware: HTTP Request
    
    Middleware->>Guards: Continue
    Note right of Middleware: Can throw → Exception Filters
    
    Guards->>Interceptors: Authorized
    Note right of Guards: Can throw → Exception Filters
    
    Interceptors->>Pipes: Pre-process
    Note right of Interceptors: Can throw → Exception Filters
    
    Pipes->>Controller: Validated data
    Note right of Pipes: Can throw → Exception Filters
    
    Controller->>Interceptors: Result
    Note right of Controller: Can throw → Exception Filters
    
    Interceptors->>Response: Post-process
    Response->>Client: HTTP Success

    Note over ExceptionFilters: Any exception from any stage<br/>jumps directly here
    ExceptionFilters->>Response: Error Response
    Response->>Client: HTTP Error
Loading
flowchart LR
    Start([HTTP Request]) --> Middleware[Middleware]
    Middleware --> Guards[Guards]
    Guards --> InterceptorsPre[Interceptors<br/>Pre-process]
    InterceptorsPre --> Pipes[Pipes<br/>Validation]
    Pipes --> Controller[Controller<br/>Handler]
    Controller --> InterceptorsCatch{Interceptor<br/>catches?}
    InterceptorsCatch --> HandleError[Process Error<br/>with catchError]
    InterceptorsCatch --> InterceptorsPost[Interceptors<br/>Post-process]
    HandleError --> InterceptorsPost
    InterceptorsPost --> Response[HTTP Response]
    
    %% Exception paths - magenta lines
    Middleware --> ExceptionFilters[Exception Filters]
    Guards --> ExceptionFilters
    InterceptorsPre --> ExceptionFilters
    Pipes --> InterceptorsCatch
    HandleError --> ExceptionFilters
    InterceptorsPost --> ExceptionFilters
    
    ExceptionFilters --> ErrorResponse[HTTP Error]
    
    Response --> Success([Client Success])
    ErrorResponse --> Error([Client Error])
    
    %% Styling
    linkStyle 0 stroke:#2196f3,stroke-width:2px
    linkStyle 1 stroke:#2196f3,stroke-width:2px
    linkStyle 2 stroke:#2196f3,stroke-width:2px
    linkStyle 3 stroke:#2196f3,stroke-width:2px
    linkStyle 4 stroke:#2196f3,stroke-width:2px
    linkStyle 5 stroke:#2196f3,stroke-width:2px
    linkStyle 6 stroke:#2196f3,stroke-width:2px
    linkStyle 7 stroke:#2196f3,stroke-width:2px
    linkStyle 8 stroke:#2196f3,stroke-width:2px
    
    linkStyle 10 stroke:#e91e63,stroke-width:2px
    linkStyle 11 stroke:#e91e63,stroke-width:2px
    linkStyle 12 stroke:#e91e63,stroke-width:2px
    linkStyle 13 stroke:#e91e63,stroke-width:2px
    linkStyle 14 stroke:#e91e63,stroke-width:2px
    linkStyle 15 stroke:#e91e63,stroke-width:2px
    
    style Start fill:#e1f5fe
    style Success fill:#c8e6c9
    style Error fill:#ffcdd2
    style ExceptionFilters fill:#fff3e0
    style InterceptorsCatch fill:#f3e5f5
    style HandleError fill:#f3e5f5
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment