# Account

## Description

Account is the fundamental GL account entity in the ERP system. Every journal entry, sub-ledger posting, and financial report ultimately references one or more GL accounts. Each account carries only the core chart-of-accounts fields: company, code, name, account type, and status.

Accounts are scoped directly to a company. The account follows a simple lifecycle (ACTIVE <-> INACTIVE) that governs posting eligibility.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Active: createAccount
    Active --> Inactive: deactivateAccount
    Inactive --> Active: reactivateAccount
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| deactivate | ACTIVE | INACTIVE | [deactivateAccount](../command/DeactivateAccount.md) |
| reactivate | INACTIVE | ACTIVE | [reactivateAccount](../command/ReactivateAccount.md) |

### Command Definitions

- [createAccount](../command/CreateAccount.md) - Create a new ACTIVE GL account for a company
- [updateAccount](../command/UpdateAccount.md) - Update mutable fields of an existing account
- [deactivateAccount](../command/DeactivateAccount.md) - Transition account from ACTIVE to INACTIVE
- [reactivateAccount](../command/ReactivateAccount.md) - Transition account from INACTIVE to ACTIVE

### Query Definitions

- [GetAccount](../query/GetAccount.md) - Retrieve an account by id or by company-scoped code
- [ListAccounts](../query/ListAccounts.md) - List accounts within a company with optional filters (type, status)

### Models

- Account

### Invariants

- Accounts are created in ACTIVE status
- Account code is required, must be a structured numeric identifier, and must be unique within its company
- Account name is required and must be non-empty
- Account type must be one of ASSET, LIABILITY, EQUITY, REVENUE, or EXPENSE
- Only ACTIVE accounts can receive new journal postings
- Deactivation exposes a pre-deactivation hook for the general-ledger module to block the transition when open or unreconciled balances exist
- All account operations emit audit events via the audit module recording the acting user, timestamp, company reference, account code, and relevant field values

### Relationships

- **References Company**: Each account belongs to a company via companyId
- **Referenced By Downstream Modules**: Accounts are referenced by general-ledger, AP, AR, and fixed-asset modules
