> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/renderer/architecture.md).

# Architecture

Renderer keeps template rendering deliberately thin.

## Runtime shape

A normal render flow looks like this:

1. `RendererFactory::get()` resolves an adapter name
2. the factory builds or reuses one `Renderer` for that adapter
3. `Renderer` forwards `render(...)` to the adapter instance
4. the adapter loads the matching view file and returns the rendered string

## Factory lifecycle

`RendererFactory::get(?string $adapter = null)` is the main entry point.

The factory is registered through the DI container the first time you use it.

Inside that factory service, one `Renderer` instance is cached per adapter name. In practice that means:

* repeated calls for the same adapter reuse the same wrapper and adapter objects
* switching adapter names creates a separate cached instance
* changing view config after an adapter has already been resolved does not refresh that cached adapter automatically

## Adapter resolution

The factory supports only the built-in adapter map:

* `html` -> `HtmlAdapter`
* `twig` -> `TwigAdapter`

Any other adapter name is rejected before instance creation.

## Shared wrapper behavior

`Quantum\Renderer\Renderer` does not implement its own rendering logic.

It stores one adapter implementing `TemplateRendererInterface` and forwards calls to that adapter.

This matters for two reasons:

* `render(...)` behavior is defined by the selected adapter
* calling an adapter-specific method through `Renderer` only works when that method actually exists on the resolved adapter

If you call a missing method, the package throws a renderer exception instead of failing silently.

## View resolution boundary

The package does not search arbitrary template paths.

Both built-in adapters look only in:

* the current module's `Views/` directory
* the shared `shared/views/` directory

If your application needs another source, you need to place files under those locations or provide a custom adapter implementation outside this package.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/renderer/architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
