# Core Architecture

### Contract Structure

The system consists of two main contracts:

* [`RepoTokenLinkedListStorageV1`](https://developers.term.finance/periphery-contracts/blue-sheets/solidity-api-latest/repotokenlinkedlist.sol-repotokenlinkedliststoragev1): Defines the storage layout
* [`RepoTokenLinkedList`](https://developers.term.finance/periphery-contracts/blue-sheets/solidity-api-latest/repotokenlinkedlist.sol-repotokenlinkedlist): Implements the core trading logic and access control

#### Key Dependencies

* OpenZeppelin Upgradeable contracts for:
  * Access Control
  * Pausable functionality
  * Reentrancy protection
  * UUPS upgradeability pattern
* Integration with Term Protocol contracts:
  * [`TermController`](https://developers.term.finance/latest/protocol-class/termcontroller)
  * [`TermDiscountRateAdapter`](https://developers.term.finance/periphery-contracts/blue-sheets/solidity-api-latest/termdiscountrateadapter.sol)
  * [`TermRepoServicer`](https://developers.term.finance/latest/term-repo-class/term-servicer-group/termreposervicer)

### Storage Structure

#### Listing Management

```solidity
struct Listing {
    address seller;
    address token;
    uint256 amount;
    uint256 next;
    uint256 prev;
}

struct Queue {
    uint256 head;
    uint256 tail;
}
```

The contract uses a linked list implementation for efficient listing management, with separate queues for each RepoToken.
