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

# Architecture

Stormbit's core is a modular lending engine. The LendingManager orchestrates the loan lifecycle, hooks inject custom logic at each step, and modules handle collateral custody. All option execution flows through the Insurance Layer (the on-chain leg of the options engine).

```mermaid
graph TD
    LM[LendingManager] --> IL[Insurance Layer]
    LM --> TL[Term Library]
    LM --> LL[Loan Library]
    LM --> H[Hooks]
    LM --> M[Modules]
    LM --> L[Liquidator]
```

***

**LendingManager** — Central orchestrator. Entry points: `termInitialize`, `termModifyPosition`, `loanInitialize`, `allocate`, `repay`. Upgradeable via UUPS. Pausable.

**Insurance Layer** — The contract component behind the collar. Prices the option legs from LTV, term, and volatility; books the premium; routes hedge execution to external options venues; settles payoffs at maturity.

**Hooks** — Custom logic at lifecycle events. Implement `IHooks` to inject behavior at term creation, deposit, allocation, and repayment. Built-in: AaveV3 (idle yield), P2P (manual approval), Timelock (delayed execution).

**Modules** — Collateral validators. Implement `ILoanModule` to handle custom collateral types. Built-in: ERC20LTV (BTC/ETH with LTV validation), ERC721 (NFT collateral), Attestation (credential-based lending).

**Liquidator** — Dutch auction for defaulted loans. Price declines over time. First buyer wins.

**Router** — Batch operations in one transaction. Command pattern execution.

**Oracle** — Chainlink and Pyth price feeds. 18 decimal normalization. Staleness checks.

***

Build custom hooks or modules to extend the protocol:

* [Building Hooks](/developers/building-hooks.md) — `IHooks` interface and examples
* [Building Modules](/developers/building-modules.md) — `ILoanModule` interface and examples
* [Contract Addresses](/developers/contract-addresses.md) — Deployed contracts per network


---

# 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://docs.stormbit.finance/developers/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.
