# `PhoenixKitAgent.Library`
[🔗](https://github.com/BeamLabEU/phoenix_kit_agent/blob/v0.1.0/lib/phoenix_kit_agent/library.ex#L1)

The module's own Storage library, where attachment bytes are kept.

It is a **hidden** system library (`Libraries.create_system_library/2` with
`hidden: true`): the site does not list it, not in Media's switcher nor in the
media pickers, its files get only expiring URLs, and `media.view_all` opens
none of them — only their uploader and an Owner/Admin may read one (an
Owner/Admin reads any file of Storage by design). It is found again by its
fixed slug and created on first use.

Inside it every user has a folder named by their `user_uuid`, at the library
root, created on demand. The folder only keeps things in order: Storage
rights are per file, the protection is the hidden library and the module
being the only way to the bytes.

# `ensure_library`

```elixir
@spec ensure_library() ::
  {:ok, PhoenixKit.Modules.Storage.Library.t()} | {:error, Ecto.Changeset.t()}
```

The module's library, created when it does not exist yet. Two callers racing
to create it both get the one library. `{:error, changeset}` when the slug
or the name is taken by a library the module did not create.

# `ensure_user_folder`

```elixir
@spec ensure_user_folder(String.t()) ::
  {:ok, PhoenixKit.Modules.Storage.Folder.t()}
  | {:error, :invalid_user_uuid | Ecto.Changeset.t()}
```

The user's folder in the module's library, created (with the library) when it
does not exist yet.

# `library`

```elixir
@spec library() :: PhoenixKit.Modules.Storage.Library.t() | nil
```

The module's library, or `nil` while it has not been created.

# `slug`

```elixir
@spec slug() :: String.t()
```

The fixed slug the module finds its library by.

# `user_folder`

```elixir
@spec user_folder(String.t()) :: PhoenixKit.Modules.Storage.Folder.t() | nil
```

The user's folder in the module's library, or `nil` while there is none.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
