> ## 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.

# 5.1: The Complete Model Assembly

> Review the full data flow from events through models to batches and ledgers, and build a configuration checklist for model completeness.

<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 learn in this lesson:**

  * Review the complete end-to-end data flow of a production-ready project
  * Build a configuration checklist for model completeness
  * Understand testing strategy: unit, integration, and end-to-end testing
  * Identify the key verification points in the data pipeline
</Check>

You've built individual components across Modules 1-4: event types, models, batch partitioning, LCA emissions, and ledger structures. Now it's time to step back and see how all the pieces fit together — and verify that nothing is missing before going to production.

## The complete Mangrove Biochar data flow

Here is the full end-to-end pipeline for your training project:

```mermaid theme={null}
flowchart TB
    subgraph Inputs["Data Inputs (5 Event Types)"]
        FR["Feedstock<br/>Receipt"]
        LA["Lab<br/>Analysis"]
        BD["Biochar<br/>Delivery"]
        EC["Energy<br/>Consumption"]
        TR["Transportation"]
    end

    subgraph Models["Models"]
        PM["Production<br/>Model"]
        QM["Quantification<br/>Model (LCA)"]
    end

    subgraph Batches["Batch Partitioning"]
        B1["Batch 1<br/>(Delivery 1)"]
        B2["Batch 2<br/>(Delivery 2)"]
        B3["Batch N<br/>(Delivery N)"]
    end

    subgraph Ledgers["Ledgers"]
        L1["Feedstock<br/>Inventory"]
        L2["Biochar<br/>Production"]
        L3["Carbon<br/>Delivered"]
    end

    FR --> PM
    LA --> PM
    BD --> PM
    EC --> QM
    TR --> QM
    PM --> B1
    PM --> B2
    PM --> B3
    QM --> B1
    QM --> B2
    QM --> B3
    B1 --> L1
    B2 --> L2
    B3 --> L3

    L3 --> RPT["Reports"]

    style FR fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style LA fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style BD fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style EC fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style TR fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style PM fill:#66bb6a,stroke:#388e3c,stroke-width:2px,color:#000
    style QM fill:#ffa726,stroke:#f57c00,stroke-width:2px,color:#000
    style B1 fill:#ef5350,stroke:#c62828,stroke-width:2px,color:#000
    style B2 fill:#ef5350,stroke:#c62828,stroke-width:2px,color:#000
    style B3 fill:#ef5350,stroke:#c62828,stroke-width:2px,color:#000
    style L1 fill:#ab47bc,stroke:#7b1fa2,stroke-width:2px,color:#000
    style L2 fill:#ab47bc,stroke:#7b1fa2,stroke-width:2px,color:#000
    style L3 fill:#ab47bc,stroke:#7b1fa2,stroke-width:2px,color:#000
    style RPT fill:#78909c,stroke:#455a64,stroke-width:2px,color:#000
```

<Note>
  The data flow goes in one direction: **events → models → batches → ledgers → reports**. Each layer depends on the one before it. A missing link at any layer will cause downstream failures.
</Note>

## Configuration checklist

Before testing, walk through this checklist to verify every component is properly configured:

<Steps>
  <Step title="Event types and datapoints">
    * All required event types are created in **Data Inputs > Input Settings**
    * Each event type has the correct datapoints with appropriate value types
    * Datapoint slugs match what the models expect
    * Required vs. optional flags are set correctly
  </Step>

  <Step title="Static inputs and constants">
    * Emission factors are stored as <a href="/production-accounting/data-inputs" target="_blank" rel="noopener noreferrer">static inputs</a>

      in the resource library
    * Conversion constants (e.g., 3.67) are defined in the model
    * Values and units are correct
  </Step>

  <Step title="Models">
    * All <a href="/production-accounting/models" target="_blank" rel="noopener noreferrer">model nodes</a>

      reference the correct datapoint slugs
    * Operators are appropriate for each calculation step
    * Intermediate nodes produce expected values in the Console
    * Output datapoint types match what the batch type expects
    * Model version is saved and validated
  </Step>

  <Step title="Batch types and partitioning">
    * Batch type is configured with the correct partition cadence
    * Output datapoint types in the batch type match the model outputs
    * Feedstock partitioning is configured if needed
  </Step>

  <Step title="Ledgers and allocations">
    * Ledgers are configured for each stage (if using <a href="/production-accounting/mass-balance-accounting" target="_blank" rel="noopener noreferrer">mass balance</a>

      )
    * Batch types are linked to the correct ledgers
    * Allocation rules between ledgers are set up
  </Step>
</Steps>

## Testing strategy

Testing a production accounting project has three levels:

<Tabs>
  <Tab title="Unit testing">
    Test individual components in isolation.

    **What to test:**

    * Each model node produces the correct output for known inputs
    * Each event type accepts valid data and rejects invalid data
    * Each emission factor produces the expected result

    **How:** Use the Model Editor Console with manually entered values. Test one calculation step at a time.
  </Tab>

  <Tab title="Integration testing">
    Test connections between components.

    **What to test:**

    * Events feed correctly into models (datapoint slugs match)
    * Model outputs produce the expected batch results
    * Batch partitioning creates the right number of batches
    * Emission allocation distributes correctly across batches

    **How:** Create a small set of test events, run <a href="/production-accounting/generate-batches" target="_blank" rel="noopener noreferrer">Generate Batches</a>

    , and verify the results.
  </Tab>

  <Tab title="End-to-end testing">
    Test the complete pipeline with realistic data.

    **What to test:**

    * A full month's data produces expected batch outputs
    * All ledgers balance (inputs = outputs + losses)
    * Net carbon figures match manual calculations
    * Edge cases are handled correctly

    **How:** Load a comprehensive test dataset (Module 5 Exercise) and validate every output against expected values.
  </Tab>
</Tabs>

## Key verification points

At each layer of the pipeline, there are specific things to verify:

| Layer       | What to Check                                 | Common Failure Mode                                |
| ----------- | --------------------------------------------- | -------------------------------------------------- |
| **Events**  | All required datapoints present, valid values | Missing datapoints, wrong units                    |
| **Models**  | Intermediate values match expectations        | Wrong slug reference, missing division by 100      |
| **Batches** | Correct number generated, outputs match       | Wrong partition cadence, mismatched output slugs   |
| **Ledgers** | Balance reconciles (in = out + change)        | Missing allocation rules, wrong batch type linkage |
| **Reports** | Aggregated totals are correct                 | Incomplete batch coverage, wrong period selection  |

<Tip>
  Start testing from the bottom up: verify events first, then model calculations, then batches, then ledgers. This way you build confidence at each layer before adding complexity.
</Tip>

***

### Check your understanding

<Accordion icon="circle-question" title="What are the 5 configuration layers in the complete data flow?">
  **Events** (data entry) → **Models** (calculations) → **Batches** (partitioned outputs) → **Ledgers** (mass balance tracking) → **Reports** (aggregated for verification). Each layer depends on the previous one being correctly configured.
</Accordion>

<Accordion icon="circle-question" title="What is the difference between unit testing and integration testing in this context?">
  **Unit testing** verifies individual components in isolation — a single model node, a single event type, a single emission factor. **Integration testing** verifies the connections between components — that events feed correctly into models, models produce correct batch outputs, and allocation distributes properly. Unit tests catch formula errors; integration tests catch configuration mismatches.
</Accordion>

***

Next, learn specific testing patterns and techniques in [Lesson 5.2: Testing Patterns](/accounting-academy/module-5/5-2-testing-patterns).
