# Architecture

Fathom Lending's contract architecture is facilitating seamless interactions between various components of the protocol. The architecture consists of several core smart contracts that handle different aspects of the lending and borrowing process. This modular approach ensures that each contract has a well-defined role, enhancing maintainability and scalability.

These smart contracts are the [AAVE V3 direct fork](https://docs.aave.com/developers). They are battle-tested on various networks and are considered safe.

**Key Contracts and Their Roles**

1. **LendingPool**: The central contract that manages deposits, withdrawals, borrowing, and repayments. It interacts with other contracts to execute these operations and maintain the protocol's state.
2. **LendingPoolCore**: Stores the protocol's internal data, such as user balances, reserve configurations, and interest rate models. It serves as the data layer for the LendingPool contract.
3. **LendingPoolConfigurator**: Allows authorized entities to configure the protocol's parameters, such as interest rate models, collateral factors, and reserve assets. It ensures that the protocol can be updated and optimized as needed.
4. **InterestRateStrategy**: Determines the interest rates for borrowing and lending based on the utilization rates of the asset pools. Multiple strategies can be implemented to accommodate different assets and market conditions.
5. **CollateralManager**: Manages collateral for borrowers, ensuring that loans are properly collateralized and initiating the liquidation process when necessary.
6. **PriceOracle**: Provides real-time price data for assets, enabling accurate calculation of collateral values and ensuring that loans remain adequately collateralized.

**Contract Interactions and Data Flow**

The interaction between contracts in Fathom Lending follows a well-defined flow to ensure efficiency and security. Here’s how these interactions typically occur:

1. **User Interaction**: Users interact with the LendingPool contract to deposit assets, borrow funds, repay loans, and withdraw assets.
2. **Data Access**: The LendingPool contract interacts with the LendingPoolCore contract to access and update user balances, reserve configurations, and other protocol data.
3. **Interest Calculation**: When users deposit or borrow assets, the LendingPool contract calls the InterestRateStrategy contract to determine the applicable interest rates based on current utilization rates.
4. **Collateral Management**: When a user borrows assets, the LendingPool contract interacts with the CollateralManager contract to verify collateral requirements and manage collateral deposits.
5. **Price Updates**: The PriceOracle contract continuously updates asset prices, which are used by the LendingPool and CollateralManager contracts to assess collateral values and determine liquidation thresholds.
6. **Liquidation**: If a borrower's collateral falls below the required threshold, the CollateralManager contract initiates the liquidation process, interacting with the LendingPool contract to repay the loan and sell the collateral.


---

# Agent Instructions: 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:

```
GET https://docs.fathom.fi/lending/architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
