> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thredfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chart of Accounts

> Understanding the chart of accounts hierarchy and structure

## Overview

The **Chart of Accounts** is the complete list of ledger accounts for a business, organized in a hierarchical tree structure. It serves as the foundation for all financial reporting and is automatically created when a business is onboarded.

***

## Hierarchy Structure

Accounts are organized in a parent-child hierarchy:

```
Assets (Level 0)
├── Current Assets (Level 1)
│   ├── Cash (Level 2)
│   │   ├── Petty Cash (Level 3)
│   │   └── Business Current Account (Level 3)
│   └── Accounts Receivable (Level 2)
└── Non-Current Assets (Level 1)
    └── Fixed Assets (Level 2)
        ├── Equipment (Level 3)
        └── Furniture (Level 3)
```

### Hierarchy Fields

| Field                 | Description                             |
| --------------------- | --------------------------------------- |
| `hierarchy_level`     | Depth in the tree (0 = root account)    |
| `parent_account_code` | Code of parent account (null for roots) |
| `has_children`        | Boolean indicating sub-accounts exist   |
| `sub_accounts`        | Array of nested child accounts          |

***

## Account Organization

The standard chart of accounts follows this top-level structure:

<CardGroup cols={2}>
  <Card title="Balance Sheet Accounts" icon="scale-balanced">
    **Assets** - What the business owns

    **Liabilities** - What the business owes

    **Equity** - Owner's stake
  </Card>

  <Card title="Income Statement Accounts" icon="chart-line">
    **Revenue** - Income earned

    **Expenses** - Costs incurred
  </Card>
</CardGroup>

***

## Retrieving the Chart of Accounts

Two endpoints are available:

### Flat List (Paginated)

Use [List Chart of Accounts](/api-reference/chart-of-accounts/list-chart-of-accounts) for:

* Filtering by account type
* Searching by name or code
* Paginated results
* Period-specific balances

```
GET /v1/platform/businesses/{business_id}/general-ledger/chart-of-accounts/
```

### Hierarchical Tree

Use [Get Chart of Accounts Hierarchy](/api-reference/chart-of-accounts/get-chart-of-accounts-hierarchy) for:

* Complete tree structure
* Nested sub-accounts
* Visual hierarchy representation
* Account counts

```
GET /v1/platform/businesses/{business_id}/general-ledger/chart-of-accounts/hierarchy/
```

***

## Response Structure

### Hierarchy Response

The hierarchy endpoint returns accounts as a nested tree:

```json theme={null}
{
  "hierarchy": [
    {
      "id": "...",
      "code": "1000",
      "name": "Assets",
      "account_type": "asset",
      "hierarchy_level": 0,
      "has_children": true,
      "current_balance": 50000000,
      "current_balance_formatted": "£500,000.00",
      "sub_accounts": [
        {
          "id": "...",
          "code": "1100",
          "name": "Current Assets",
          "account_type": "asset",
          "hierarchy_level": 1,
          "has_children": true,
          "current_balance": 35000000,
          "sub_accounts": [
            {
              "id": "...",
              "code": "1101",
              "name": "Business Current Account",
              "hierarchy_level": 2,
              "has_children": false,
              "current_balance": 1250050,
              "sub_accounts": []
            }
          ]
        }
      ]
    },
    {
      "id": "...",
      "code": "2000",
      "name": "Liabilities",
      "account_type": "liability",
      "hierarchy_level": 0,
      "sub_accounts": [...]
    }
  ],
  "total_accounts": 45
}
```

***

## Balance Calculations

Account balances follow double-entry bookkeeping rules:

<Tabs>
  <Tab title="Debit Accounts">
    **Assets & Expenses** increase with debits

    ```
    Balance = Debits - Credits
    ```

    Positive balance = Normal (what you own/spent)
  </Tab>

  <Tab title="Credit Accounts">
    **Liabilities, Equity & Revenue** increase with credits

    ```
    Balance = Credits - Debits
    ```

    Positive balance = Normal (what you owe/earned)
  </Tab>
</Tabs>

### Parent Account Balances

Parent accounts aggregate balances from all descendants:

```
Assets (£500,000)
├── Current Assets (£350,000)
│   ├── Cash (£125,000)
│   └── Receivables (£225,000)
└── Fixed Assets (£150,000)
```

***

## Common Use Cases

<AccordionGroup>
  <Accordion title="Display account tree in UI">
    Use the hierarchy endpoint to fetch the complete tree, then render recursively:

    ```javascript theme={null}
    function renderAccount(account, depth = 0) {
      const indent = '  '.repeat(depth);
      console.log(`${indent}${account.code} - ${account.name}: ${account.current_balance_formatted}`);
      account.sub_accounts?.forEach(child => renderAccount(child, depth + 1));
    }

    response.hierarchy.forEach(root => renderAccount(root));
    ```
  </Accordion>

  <Accordion title="Filter accounts by type">
    Use the list endpoint with `account_type` parameter:

    ```
    GET /v1/.../chart-of-accounts/?account_type=expense
    ```
  </Accordion>

  <Accordion title="Get period-specific balances">
    Use the list endpoint with period filters:

    ```
    GET /v1/.../chart-of-accounts/?period_year=2024&period_month=11
    ```
  </Accordion>
</AccordionGroup>
