GrowGood's Greenprint - Our Technical Journey with ValueFlows and REA Accounting

GrowGood's Greenprint - Our Technical Journey with ValueFlows and REA Accounting

G’day! Ever wonder what it takes to build software that truly understands a farm? Not just the profits and losses, but the health of the soil, the value of shared work, and the intricate dance of a regenerative ecosystem?

That’s the challenge we’re tackling at GrowGood. Our journey to build a transparent, open-source AgTech platform has led us down a fascinating technical path, guided by the robust principles of ValueFlows and Resource-Event-Agent (REA) accounting.

So grab a cuppa, because we’re about to delve into the weeds – the delightful technical weeds, that is – of our architecture, the challenges we’ve faced, and the reasons you might just want to join us in the paddock.

Why ValueFlows and REA? The Foundation of Truth

Traditional farm management software often focuses on isolated metrics: yield per acre, cost per unit, profit margins. While useful, this approach falls short when attempting to capture the holistic, interconnected nature of regenerative practices. How do you account for increased soil organic carbon, enhanced biodiversity, or the value of shared community labour?

This is precisely the problem ValueFlows solves. It’s a formal ontology (a fancy word for a shared vocabulary) for describing economic networks. At its core is REA accounting, which views all economic activity as changes in Resources caused by Events involving Agents.

For us, this means:

  • Holistic Accounting: Every input (seeds, water, effort), every output (carrots, milk, improved soil health), and every transformation (planting, harvesting, composting) is an Economic Event in our system. This isn’t just financial; it encompasses ecological and social value.
  • True Traceability: Because every event links back to the resources, agents, and processes involved, we build an immutable, verifiable audit trail. This is crucial for proving sustainability claims – no greenwashing here!
  • Interoperability: ValueFlows is a widely recognized standard. By aligning with it, GrowGood can seamlessly connect with other VF-compliant systems, enabling distributed economic networks (think local food economies, supply chain transparency, and even carbon markets).

This isn’t just about better data; it’s about making data meaningful and actionable in a way that truly reflects the values of regenerative agriculture.

The Architecture: A Pythonic Backbone with a Fluttering Heart

Our backend is a lean, mean, FastAPI machine, powered by Python’s asynchronous capabilities. We’ve paired it with a robust PostgreSQL database, supercharged by PostGIS for all our spatial data needs – because on a farm, where something happens is often as important as what happens.

Architecturally, we’re firmly rooted in Domain-Driven Design (DDD) and Command Query Responsibility Segregation (CQRS). This might sound intimidating, but it essentially means we separate how we change data (Commands) from how we read it (Queries), optimizing for both performance and conceptual clarity. Our Economic Events are the single source of truth; all other application state is derived as projections from this immutable event stream.

On the frontend, after some thoughtful deliberation (and a few ADRs!), we’ve embraced Flutter. This was a pivotal decision, enabling us to build a single, beautiful codebase that runs natively across mobile (crucial for in-field operations), desktop (perfect for the Admin UI), and even the web.

The Journey: From Text to Interactive Canvas

Our path to a visual, ValueFlows-driven Admin UI has involved several prototyping detours, each teaching us invaluable lessons.

Phase 1: The DSL – Sketching Economic Flows in Text

Our first step was to define a ValueFlows Domain Specific Language (vf-dsl). Inspired by tools like Mermaid.js, this is a human-readable, text-based syntax for sketching out recipes (our VF process templates).

# Example vf-dsl snippet
process "Planting Tomatoes" {
    input "Tomato Seeds" (quantity: 10g)
    output "Tomato Seedlings" (quantity: 50 plants)
    agent "Farmer Jane"
}

This DSL proved incredibly powerful for rapid prototyping and version control. Developers could quickly define complex workflows in plain text, making it easy to review and discuss changes.

Phase 2: Jupyter – The Developer’s Playground

Our Jupyter prototype (dsl_tester_demo.ipynb) was a sandbox for our DSL parser and validator. Here, we could:

  • Parse DSL: Convert vf-dsl into a structured Python dictionary representing nodes and edges.
  • Validate Constraints: Implement core ValueFlows rules, like checking for circular dependencies or ensuring all quantities have units.
  • Static Visualization: Generate simple, non-interactive graphs to visually confirm the parsed structure.

This environment was invaluable for rapidly iterating on the DSL specification and the underlying parsing logic.

Phase 3: NiceGUI – Bringing the DSL to the Web (for Feedback)

Recognizing that raw DSL wasn’t ideal for end-users, we built a web-based prototype using NiceGUI (a Python UI framework). This allowed us to:

  • Visualise with VueFlow: Integrate a VueFlow component to render interactive, node-based graphs directly in the browser.
  • Gather Early Feedback: Provide a zero-installation, web-accessible tool for farm administrators to test the UI and provide feedback on the visual editor’s workflow.

The NiceGUI prototype served as a crucial bridge, demonstrating how the text-based DSL could underpin a rich graphical interface. It proved that a hybrid approach – using DSL for rapid scaffolding and versioning, and a visual editor for intuitive interaction – offered the best of both worlds.

Phase 4: Flutter – Unifying the Experience

Our most recent, and most strategic, decision was to unify both the Operational (mobile-first) and Administrator (desktop-first) UIs under a single Flutter codebase. This was captured in ADR-010: Use Flutter for Operational and Administrator UIs.

Why Flutter?

  • Native Performance: Crucial for a smooth, responsive experience on both mobile (often in low-connectivity environments) and desktop.
  • True Cross-Platform: One codebase, native apps for iOS, Android, Windows, macOS, Linux, and web. This drastically reduces our maintenance burden as an open-source project.
  • Offline-First Capabilities: Flutter’s ecosystem (e.g., drift for local databases) is perfectly suited for building robust offline-first applications, a non-negotiable for farmers in the field.
  • Rich UI Toolkit: Allows us to build the complex, interactive node-based editor for recipes that our Admin UI demands.

This shift presents a learning curve for our Python-focused team, but the long-term benefits in maintainability, consistency, and user experience are undeniable.

Challenges and Learnings

Our journey hasn’t been without its bumps and epiphanies:

  • DSL Design vs. VF Purity: Balancing the need for a concise, human-readable DSL with strict ValueFlows ontological purity was an ongoing negotiation. We opted for pragmatic shortcuts in the DSL that are then expanded into full VF JSON-LD during parsing.
  • Visualizing Complexity: Representing multi-layered ValueFlows concepts (Recipes, Plans, Processes, Events) in an intuitive visual graph requires careful design. We’re leaning towards distinct visual cues and interactive filtering to manage information overload.
  • Derived State in CQRS: Initially, we had a tendency to store derived state in our database models. Feedback from the ValueFlows community and our commitment to CQRS led us to a stricter event-sourcing model where all state is truly derived from the immutable event log. This improves data integrity but adds query complexity, necessitating sophisticated projection services.
  • Testing Strategy: With an event-sourced, cross-platform architecture, our testing matrix grew significantly. We’ve invested in comprehensive unit, integration, and end-to-end tests, alongside dedicated DSL testing in Jupyter, to ensure robustness.

The Road Ahead: Open Questions and Future Work

As we move towards a full Flutter implementation of the Admin UI, several exciting technical challenges and opportunities lie before us:

  • Advanced Graph Interactivity: Building a highly interactive, drag-and-drop node editor in Flutter. We’re exploring combining libraries like graphview with custom CustomPainter implementations to achieve the desired level of control and performance.
  • DSL Round-Tripping: Enabling seamless conversion between the visual graph and the text-based DSL, allowing power users to switch between modes.
  • Real-time Collaboration: How can multiple administrators collaborate on recipe design without conflicts? This opens doors to CRDTs or operational transformation algorithms.
  • Backend Scaling: As GrowGood grows, optimizing our PostgreSQL/PostGIS setup and potentially exploring microservices for specific domains will be critical.

Join the Paddock! A Call for Contributors

This is where you come in, dear reader. GrowGood is an ambitious open-source project, and we believe in the power of community.

If you’re a developer (or even a budding one!) with a passion for:

  • Flutter: Help us build a beautiful, performant, and intuitive cross-platform UI.
  • Python/FastAPI: Contribute to our robust backend, expand our ValueFlows integration, or optimize our PostGIS queries.
  • AgTech & Regenerative Agriculture: Bring your domain expertise to shape features that truly empower farmers.
  • Open Source: Join a friendly, growing community dedicated to building public goods for a better food system.

We’re looking for folks to help with:

  • Flutter UI Development: From implementing the node editor to building responsive layouts.
  • Backend Logic: Extending ValueFlows models, optimizing projection services, and integrating new data sources.
  • Testing: Ensuring our platform is bulletproof across all layers.
  • Documentation: Helping us make GrowGood accessible to a wider audience.

Head over to our GitLab repository, check out our issues, join our Discord, and let’s cultivate this green revolution together. The future of food is open, and it’s being built, one ValueFlow at a time.

Featured image by glassholic on Flickr.