Key concepts
Before diving into the step-by-step process, it’s important to understand how Midaz structures data for regulatory reporting:
OperationRoute and the code field
The OperationRoute entity is central to COSIF mapping. Each OperationRoute has a code field (max 100 characters) designed specifically to store external reference codes such as COSIF account codes. When transactions are processed, each operation is associated with an OperationRoute. By aggregating operations grouped by OperationRoute.code, you can calculate balances per COSIF account — which is exactly what a trial balance requires.TransactionRoute
A TransactionRoute groups multiple OperationRoutes (sources and destinations) into a reusable template. When creating transactions, you reference a TransactionRoute, and Midaz validates that operations follow the defined rules.Step-by-step process
1. Prepare your Chart of Accounts in Midaz
Configure your Organizations, Ledgers, Assets, Account Types, and Accounts according to your business needs. The key entities for trial balance generation are:- Account Types — define the nature of each account (asset, liability, equity, revenue, expense) using the keyValue field.
- OperationRoutes — map each type of operation to a COSIF code via the code field.
- TransactionRoutes — group OperationRoutes into transaction templates with validation rules.
2. Create OperationRoutes with COSIF codes
For each COSIF account in your chart of accounts, create corresponding OperationRoutes with the COSIF code in the code field. Example OperationRoutes for a Brazilian financial institution: OperationRoute for checking account debits (source):| COSIF Code | Description | Account Types |
|---|---|---|
| 1.1.1.10-8 | Checking Accounts - Individuals | checking_account_pf |
| 1.1.1.20-5 | Checking Accounts - Companies | checking_account_pj |
| 1.2.3.00-0 | Investment Accounts | investment_account |
| 7.1.1.00-0 | Service Revenue | revenue_services |
| 8.1.1.00-0 | Administrative Expenses | expense_admin |
3. Create TransactionRoutes
Group your OperationRoutes into TransactionRoutes that represent common transaction patterns.When creating a TransactionRoute, you pass an array of OperationRoute UUIDs. When retrieving a TransactionRoute via the API, it returns the full OperationRoute objects with all their details.
4. Process transactions with routes
When creating transactions, reference the TransactionRoute. Each operation will be associated with its corresponding OperationRoute and COSIF code:The
asset and value are defined at the send level. Individual operations in from and to use accountAlias (not account). The value is expressed in the smallest unit of the asset (e.g., cents for BRL, so 4550 = R$ 45.50).5. Understanding the data flow
Midaz stores all the financial data needed for trial balance generation:- Operations — each operation includes a
routefield containing the OperationRoute UUID - OperationRoutes — contain the
codefield with COSIF codes for aggregation - Account Balances — current positions per account
route field that references the OperationRoute UUID (not the COSIF code directly). To aggregate by COSIF code, Reporter joins operations with their corresponding OperationRoutes to access the code field:
cursor, limit, and type. Operations are retrieved per account.
Reporter connects directly to the Midaz database for report generation, enabling efficient batch queries and aggregations. The APIs above are available for custom integrations and ad-hoc queries.
6. Generate your report with Reporter
Reporter uses a template-driven architecture to generate reports. The process involves:- Select or create a template — templates use Pongo2 syntax (Django-like) with custom aggregation tags
- Configure data sources — Reporter queries Midaz database tables directly
- Apply filters — specify date ranges, account types, or other criteria
- Generate the report — Reporter aggregates data and renders the template
- Export in your chosen format (XML, TXT, HTML, PDF, CSV, JSON)
{% sum_by collection by "field" %}— sum values by field{% count_by collection if condition %}— count records matching condition{% calc expression %}— arithmetic calculations
7. Export and integrate
You can:- Export a ready-to-share PDF for auditors and regulators
- Generate XML files formatted for BACEN submission
- Integrate with your existing reporting workflows or accounting systems
Practical example — Complete Midaz setup
Below is a fictional institution, DigitalBank, showing how Midaz entities connect to support a trial balance:
Organization
Organization
Assets
Assets
Account Types
Account Types
COSIF codes are defined in OperationRoutes via the
code field, not in Account Types. Account Types define the nature of accounts and are used by OperationRoutes for validation rules.OperationRoutes with COSIF codes
OperationRoutes with COSIF codes
TransactionRoute for PIX
TransactionRoute for PIX
Sample Transaction
Sample Transaction
Trial Balance output example
After joining operations with their OperationRoutes and aggregating by the
code field, your trial balance would look like:
| COSIF Code | Description | Debits (R$) | Credits (R$) | Balance (R$) |
|---|---|---|---|---|
| 1.1.1.10-8 | Checking - PF | 150,000.00 | 145,000.00 | 5,000.00 |
| 1.1.1.20-5 | Checking - PJ | 89,000.00 | 92,500.00 | -3,500.00 |
| 1.2.3.00-0 | Investments | 50,000.00 | 48,000.00 | 2,000.00 |
| Total | 289,000.00 | 285,500.00 | 3,500.00 |
- XML — structured for BACEN regulatory submission
- PDF — professional report for auditors and stakeholders
- TXT — flat file for legacy system integration
Summary
The key to generating accurate trial balances with Midaz is proper use of the
code field in OperationRoutes:
- Create OperationRoutes with COSIF codes in the
codefield - Group into TransactionRoutes for transaction validation
- Process transactions referencing the appropriate routes
- Join operations with OperationRoutes using the
routefield (UUID) to access COSIF codes - Aggregate by OperationRoute.code to calculate balances per COSIF account
- Generate reports with Reporter using templates that perform the aggregation automatically
- Regulatory compliance with COSIF standards
- Automatic balance aggregation by account code
- Validation of transaction operations
- Flexible reporting in multiple formats

