diff --git a/docs/en/docs/tutorial/middleware.md b/docs/en/docs/tutorial/middleware.md index 5da549cb7e..3d78170aea 100644 --- a/docs/en/docs/tutorial/middleware.md +++ b/docs/en/docs/tutorial/middleware.md @@ -82,9 +82,20 @@ app.add_middleware(MiddlewareB) This results in the following execution order: -* **Request**: MiddlewareB → MiddlewareA → route - -* **Response**: route → MiddlewareA → MiddlewareB +```mermaid +sequenceDiagram + participant Client + participant B as Middleware B
(added last · outermost) + participant A as Middleware A
(added first · innermost) + participant App as FastAPI app + + Client ->> B: Request + B ->> A: Request + A ->> App: Request + App -->> A: Response + A -->> B: Response + B -->> Client: Response +``` This stacking behavior ensures that middlewares are executed in a predictable and controllable order.