> 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/storage/architecture.md).

# Architecture

Storage has two runtime paths: filesystem access and upload persistence.

## Filesystem access flow

1. `fs()` calls `FileSystemFactory::get()`
2. config is imported if needed
3. requested adapter (or `fs.default`) is resolved
4. adapter is wrapped in `FileSystem`
5. wrapper is cached per adapter name in the process

Practical effect: repeated `fs('local')` calls reuse the same wrapper instance.

## Wrapper model

`FileSystem` is a delegating wrapper around one adapter.

Unsupported adapter methods are rejected with exceptions instead of being ignored.

## Upload flow

`UploadedFile` runs this sequence:

1. parse upload metadata
2. detect extension + MIME from the local temp file
3. load MIME policy (defaults + optional config)
4. validate the temp file and destination strategy
5. write locally or forward the temp file content to a remote adapter
6. optionally run post-save image modification against the saved path

Practical effect: upload inspection and staging still depend on the local adapter, even when the final destination is remote.

## Cloud composition

Cloud backends are composed from:

* adapter implementation
* cloud app/token service wiring from config

This keeps app-level usage consistent (`fs()` + wrapper API) while backend auth/token lifecycle stays in services/config.


---

# 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/storage/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.
