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

# Module 4 Exercise: Design & Build Mass Balance with Ledgers

> Design a multi-ledger structure for Mangrove Biochar, create three batch types and three ledgers, configure allocations, and verify end-to-end mass balance.

<Panel>
  <Card title="Accounting Academy" className="accounting-academy-card">
    <div className="accounting-academy-content">
      <Steps className="my-0">
        <Step title="MODULE 1: Fundamentals" icon="bookmark" iconType="solid" stepNumber={1} titleSize="p">
          * [1.1: Core Concepts & the Data Lifecycle](/accounting-academy/module-1/1-1-core-concepts-data-lifecycle)
          * [1.2: Translating Methodologies to Mangrove](/accounting-academy/module-1/1-2-translating-methodologies-to-mangrove)
          * [1.3: Events and Datapoints](/accounting-academy/module-1/1-3-events-and-datapoints)
          * [Exercise: Design and Build](/accounting-academy/module-1/1-exercise-design-and-build)
        </Step>

        <Step title="MODULE 2: Calculations" icon="bookmark" iconType="solid" stepNumber={2} titleSize="p">
          * [2.1: Calculation Architecture](/accounting-academy/module-2/2-1-calculation-architecture)
          * [2.2: Expanding Your Data Model](/accounting-academy/module-2/2-2-expanding-your-data-model)
          * [Exercise: Multi-Step Calculations](/accounting-academy/module-2/2-exercise-multi-step-calculations)
        </Step>

        <Step title="MODULE 3: Batch Partitioning & LCA" icon="bookmark" iconType="solid" stepNumber={3} titleSize="p">
          * [3.1: What Is a Batch?](/accounting-academy/module-3/3-1-what-is-a-batch)
          * [3.2: Batch Partitioning Strategies](/accounting-academy/module-3/3-2-batch-partitioning)
          * [3.3: Life Cycle Assessment & Emissions](/accounting-academy/module-3/3-3-lca-and-emissions)
          * [3.4: Allocating Emissions to Batches](/accounting-academy/module-3/3-4-allocating-emissions-to-batches)
          * [Exercise: Batch Partitioning & LCA](/accounting-academy/module-3/3-exercise-batch-partitioning-and-lca)
        </Step>

        <Step title="MODULE 4: Mass Balance with Ledgers" icon="bookmark" iconType="solid" stepNumber={4} titleSize="p">
          * [4.1: Introduction to Mass Balance](/accounting-academy/module-4/4-1-intro-to-mass-balance)
          * [4.2: Designing the Ledger Structure](/accounting-academy/module-4/4-2-designing-the-ledger-structure)
          * [4.3: Multiple Batch Types for Different Stages](/accounting-academy/module-4/4-3-multiple-batch-types)
          * [Exercise: Design & Build Mass Balance](/accounting-academy/module-4/4-exercise-design-and-build-mass-balance)
        </Step>

        <Step title="MODULE 5: Integration Testing" icon="bookmark" iconType="solid" stepNumber={5} titleSize="p">
          * [5.1: The Complete Model Assembly](/accounting-academy/module-5/5-1-the-complete-model-assembly)
          * [5.2: Testing Patterns](/accounting-academy/module-5/5-2-testing-patterns)
          * [5.3: Common Integration Pitfalls](/accounting-academy/module-5/5-3-common-integration-pitfalls)
          * [Exercise: Integration Testing](/accounting-academy/module-5/5-exercise-integration-testing)
        </Step>

        <Step title="MODULE 6: Advanced Patterns & Production" icon="bookmark" iconType="solid" stepNumber={6} titleSize="p">
          * [6.1: Model Design Best Practices](/accounting-academy/module-6/6-1-model-design-best-practices)
          * [6.2: Advanced Techniques](/accounting-academy/module-6/6-2-advanced-techniques)
          * [6.3: Production Readiness](/accounting-academy/module-6/6-3-production-readiness)
          * [Exercise: Production Deployment](/accounting-academy/module-6/6-exercise-production-deployment)
        </Step>
      </Steps>
    </div>
  </Card>
</Panel>

<Check>
  **What you'll build in this exercise:**

  * Design a 3-ledger structure for the Mangrove Biochar project
  * Create 3 batch types: Feedstock Receipt, Biochar Produced, Carbon Delivered
  * Create 3 ledgers and configure allocations between them
  * Add test data across all stages and verify that mass balance holds
</Check>

This exercise brings together everything from Module 4: you'll design and build a **multi-ledger mass balance system** for Mangrove Biochar. By the end, material will flow from feedstock receipt through biochar production to carbon delivery — with ledger balances that reconcile at every stage.

```mermaid theme={null}
flowchart LR
    subgraph L1["Ledger 1: Feedstock Inventory"]
        FR1["Feedstock<br/>Batch 1<br/>5t"]
        FR2["Feedstock<br/>Batch 2<br/>8t"]
    end

    subgraph L2["Ledger 2: Biochar Production"]
        BP1["Production<br/>Batch 1<br/>1.5t"]
        BP2["Production<br/>Batch 2<br/>2.4t"]
    end

    subgraph L3["Ledger 3: Carbon Delivered"]
        CD1["Delivery<br/>Batch 1<br/>4.2 tCO2e"]
        CD2["Delivery<br/>Batch 2<br/>6.7 tCO2e"]
    end

    L1 -->|"Allocation<br/>(conversion)"| L2
    L2 -->|"Allocation<br/>(carbon content)"| L3

    style FR1 fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style FR2 fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style BP1 fill:#ffa726,stroke:#f57c00,stroke-width:2px,color:#000
    style BP2 fill:#ffa726,stroke:#f57c00,stroke-width:2px,color:#000
    style CD1 fill:#66bb6a,stroke:#388e3c,stroke-width:2px,color:#000
    style CD2 fill:#66bb6a,stroke:#388e3c,stroke-width:2px,color:#000
```

**Prerequisites:** Complete [Lesson 4.1](/accounting-academy/module-4/4-1-intro-to-mass-balance), [Lesson 4.2](/accounting-academy/module-4/4-2-designing-the-ledger-structure), and [Lesson 4.3](/accounting-academy/module-4/4-3-multiple-batch-types). Your project should have the batch partitioning and LCA setup from the Module 3 exercise.

***

## Part 1: Design (30 min)

### 1. Identify accumulation points

Map the physical process for Mangrove Biochar. Where does material "sit" before moving to the next stage?

| Stage | Accumulation Point  | What Happens Here                                             |
| ----- | ------------------- | ------------------------------------------------------------- |
| 1     | Feedstock inventory | Biomass is received and stored before pyrolysis               |
| 2     | Biochar produced    | Biochar is produced from pyrolysis and stored before delivery |
| 3     | Carbon delivered    | Biochar is delivered to a site and sequestered                |

### 2. Define each ledger

For each accumulation point, define the ledger attributes:

| Ledger              | Unit           | Credit Source (batch type) | Debit Source                     |
| ------------------- | -------------- | -------------------------- | -------------------------------- |
| Feedstock Inventory | Dry tonnes     | Feedstock Receipt batches  | Allocation to Biochar Production |
| Biochar Production  | Biochar tonnes | Biochar Produced batches   | Allocation to Carbon Delivered   |
| Carbon Delivered    | tCO2e          | Carbon Delivered batches   | Allocation to reports            |

### 3. Map allocations between ledgers

Define how material flows between ledgers:

| From                | To                 | Method                                                    | Conversion                                                                                        |
| ------------------- | ------------------ | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| Feedstock Inventory | Biochar Production | By production run — each run consumes feedstock           | Feedstock consumed (dry tonnes) → biochar produced (biochar tonnes) using yield ratio             |
| Biochar Production  | Carbon Delivered   | By delivery — each delivery draws from produced inventory | Biochar delivered (tonnes) → carbon sequestered (tCO2e) using carbon content % and CO2 conversion |

<Tip>
  The conversion factors are project-specific. For Mangrove Biochar, a typical yield ratio is \~30% (5 dry tonnes feedstock → 1.5 tonnes biochar) and carbon content is \~80% (1.5 tonnes biochar × 0.80 × 3.67 = 4.4 tCO2e).
</Tip>

***

## Part 2: Build in Mangrove (1.5 hrs)

### Step 1: Create 3 batch types

In your project's <a href="/production-accounting/fundamentals" target="_blank" rel="noopener noreferrer">Production Accounting</a>

settings, create these batch types:

<CardGroup cols={3}>
  <Card icon="wheat" title="Feedstock Receipt">
    | Setting            | Value              |
    | ------------------ | ------------------ |
    | **Partition**      | Per-delivery       |
    | **Tracking ID**    | Supplier ticket #  |
    | **Primary output** | Dry mass (tonnes)  |
    | **Source events**  | Feedstock Delivery |
  </Card>

  <Card icon="fire" title="Biochar Produced">
    | Setting            | Value                 |
    | ------------------ | --------------------- |
    | **Partition**      | Per production run    |
    | **Tracking ID**    | Run ID                |
    | **Primary output** | Biochar mass (tonnes) |
    | **Source events**  | Production Run        |
  </Card>

  <Card icon="truck" title="Carbon Delivered">
    | Setting            | Value             |
    | ------------------ | ----------------- |
    | **Partition**      | Per-delivery      |
    | **Tracking ID**    | Delivery ticket # |
    | **Primary output** | Net tCO2e         |
    | **Source events**  | Biochar Delivery  |
  </Card>
</CardGroup>

### Step 2: Create 3 ledgers

Create a ledger for each stage and link it to the corresponding batch type:

<Steps>
  <Step title="Feedstock Inventory ledger">
    Unit: **dry tonnes**. Credited by Feedstock Receipt batches.
  </Step>

  <Step title="Biochar Production ledger">
    Unit: **biochar tonnes**. Credited by Biochar Produced batches. Receives allocations from Feedstock Inventory.
  </Step>

  <Step title="Carbon Delivered ledger">
    Unit: **tCO2e**. Credited by Carbon Delivered batches. Receives allocations from Biochar Production.
  </Step>
</Steps>

### Step 3: Configure allocations

Set up the material flow between ledgers:

1. **Feedstock Inventory → Biochar Production**
   * When a Production Run batch is created, it should consume feedstock from Ledger 1
   * Configure the allocation to debit from Feedstock Inventory based on feedstock consumed per run
   * Apply the yield ratio conversion (e.g., 5t feedstock → 1.5t biochar)
2. **Biochar Production → Carbon Delivered**
   * When a Carbon Delivered batch is created, it should draw from Ledger 2
   * Configure the allocation to debit from Biochar Production based on biochar delivered
   * Apply the carbon content conversion (e.g., biochar tonnes × carbon % × 3.67 = tCO2e)

### Step 4: Create test data

<a href="/data-collection/add-data" target="_blank" rel="noopener noreferrer">Add events</a>

representing one month of operations across all stages:

**2 Feedstock Deliveries:**

| Delivery | Date   | Dry Mass (t) | Supplier |
| -------- | ------ | ------------ | -------- |
| FS-001   | Jan 3  | 5            | Farm A   |
| FS-002   | Jan 10 | 8            | Farm B   |

**2 Production Runs:**

| Run    | Date   | Feedstock Consumed (t) | Biochar Produced (t) |
| ------ | ------ | ---------------------- | -------------------- |
| PR-001 | Jan 7  | 5                      | 1.5                  |
| PR-002 | Jan 14 | 8                      | 2.4                  |

**2 Biochar Deliveries:**

| Delivery | Date   | Biochar Delivered (t) | Carbon Content % |
| -------- | ------ | --------------------- | ---------------- |
| DEL-001  | Jan 15 | 1.5                   | 80%              |
| DEL-002  | Jan 22 | 2.4                   | 80%              |

### Step 5: Generate batches and verify mass balance

1. Go to **Production Accounting** and <a href="/production-accounting/generate-batches" target="_blank" rel="noopener noreferrer">generate batches</a>

   for January.
2. Verify that **6 batches** are created (2 per stage).
3. Check each ledger's balance:

| Ledger              | Expected Credits                    | Expected Debits                              | Expected Balance   |
| ------------------- | ----------------------------------- | -------------------------------------------- | ------------------ |
| Feedstock Inventory | +5t, +8t = 13t                      | -5t, -8t = -13t (allocated to production)    | 0t (all consumed)  |
| Biochar Production  | +1.5t, +2.4t = 3.9t                 | -1.5t, -2.4t = -3.9t (allocated to delivery) | 0t (all delivered) |
| Carbon Delivered    | +4.4 tCO2e, +7.0 tCO2e = 11.4 tCO2e | None yet (not reported)                      | 11.4 tCO2e         |

<Warning>
  If ledger balances don't reconcile, check: (1) allocations are configured correctly between ledgers, (2) conversion factors match your test data, (3) each batch type credits the correct ledger.
</Warning>

### Step 6: Verify end-to-end traceability

For each Carbon Delivered batch, trace the chain back to the source:

1. Open a Carbon Delivered batch (e.g., DEL-001, 4.4 tCO2e)
2. Verify it links to a Biochar Produced batch (PR-001, 1.5t biochar)
3. Verify that links to a Feedstock Receipt batch (FS-001, 5t feedstock)
4. Confirm the conversion math: 5t × 30% yield = 1.5t biochar × 80% carbon × 3.67 = 4.4 tCO2e

***

## Success criteria

You have completed the Module 4 exercise when:

* **3 batch types** created — Feedstock Receipt, Biochar Produced, Carbon Delivered
* **3 ledgers** created — Feedstock Inventory (dry tonnes), Biochar Production (biochar tonnes), Carbon Delivered (tCO2e)
* **Allocations configured** — material flows from Ledger 1 → Ledger 2 → Ledger 3 with appropriate conversion factors
* **Test data created** — at least 2 events per stage (feedstock deliveries, production runs, biochar deliveries)
* **6 batches generated** — 2 per stage, each crediting the correct ledger
* **Ledger balances reconcile** — credits minus debits match expected values at each stage
* **End-to-end traceability** — any Carbon Delivered batch can be traced back through production to the original feedstock receipt

***

## What's next

You now have a complete multi-stage mass balance system. In [Module 5: Integration Testing](/accounting-academy/module-5/5-1-the-complete-model-assembly) you'll learn how to test your full project end-to-end — verifying that events, models, batches, ledgers, and reports all work together correctly.
