# Request / Response Flow

This chart shows how a browser request moves through the MindVisionCode framework and how a response is built and returned.

```text
Browser Request
    |
    v
public/index.php
    |-- loads autoload.php / vendor autoload
    |-- starts the session
    |-- creates App + Router
    |-- loads routes/web.php
    |
    v
Request::capture()
    |
    v
Dispatcher::dispatch()
    |
    +--> no route matched ----> Response::notFound()
    |
    +--> route matched -------> Route::dispatch()
                                   |
                                   v
                               App::call()
                                   |
                                   +--> controller method
                                   |       |
                                   |       v
                                   |   Controller action
                                   |       |
                                   |       +--> repository / service / view model
                                   |       +--> Database::query() / execute()
                                   |       +--> view() / json() / redirect()
                                   |
                                   +--> closure route
                                           |
                                           v
                                   direct response data

Dispatcher::normalizeResponse()
    |
    +--> Response object --------> Response::send()
    +--> array ------------------> Response::json() --> Response::send()
    +--> string -----------------> Response::send()

Final result:
Browser receives HTML, JSON, or a redirect
```

## Response building paths

### View response

```text
Controller -> view() -> View::render() -> template -> layout -> Response
```

### JSON response

```text
Controller -> json() -> Response::json() -> Response::send()
```

### Redirect response

```text
Controller -> redirect() -> Response::redirect() -> Response::send()
```

## Key classes

- `public/index.php` bootstraps the app
- `Core\Dispatcher` matches routes and handles errors
- `Core\Route` extracts route parameters
- `Core\App` invokes controller methods or closures
- `Core\Controller` gives actions helper methods
- `Core\View` renders templates into a layout
- `Core\Response` sends the final output
