# TrialBalanceLine

## Description

TrialBalanceLine represents a single account's balance within a TrialBalance snapshot. Each line records the account reference, optional account group for hierarchical aggregation, opening balance, period debits, period credits, and computed closing balance. Lines are always created as part of trial balance generation and are immutable once the snapshot is produced.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [generateTrialBalance](../commands/GenerateTrialBalance.md) - Trial balance lines are created as part of trial balance generation

### Query Definitions

- [GetTrialBalance](../queries/GetTrialBalance.md) - Trial balance lines are returned as part of the parent trial balance

### Models

- TrialBalanceLine

### Invariants

- Each trial balance line must reference a valid GL account from the active CoA
- Opening balance equals the closing balance from the immediately preceding period for the same account
- Closing balance equals opening balance plus period debits minus period credits
- Lines are ordered by account code in ascending order within each account group
- Lines are immutable once generated as part of a trial balance snapshot

### Relationships

- **References TrialBalance**: Each line belongs to a TrialBalance via trialBalanceId
- **References Account**: Each line references a GL Account via accountId (coa-management module)
- **References AccountGroup**: Each line optionally references an AccountGroup via accountGroupId (coa-management module)
