Skip to main content

From CRUD to CQRS: The Story of Castlecraft Architect

Every developer's journey is shaped by the tools they use and the problems they solve. This document outlines the journey and core philosophy that led to the creation of Castlecraft Engineer and Castlecraft Architect, moving from the world of rapid CRUD to the structured elegance of Domain-Driven Design (DDD).

The Power and the Paradox of Rapid Scaffolding

Our first major "aha!" moment came with the Frappe Framework. For a solo developer or a small team, Frappe is a powerhouse. The ability to define a DocType and watch the framework magically scaffold a database table, a Python controller, frontend code, and API schemas—all from a UI—is nothing short of brilliant. Frappe has its own powerful ubiquitous language, and its ecosystem is a testament to the power of metadata-driven development.

However, as we helped implement Frappe in a team of over 200 developers, a new challenge emerged. The very magic that made it fast for individuals became a bottleneck at scale. You can't have hundreds of people performing direct CRUD-like operations on DocType definitions simultaneously without chaos. It became clear that large-scale collaboration requires a more structured, workflow-driven process for managing architectural changes. This experience planted the seed for what would later become the "Revisions" system in Architect.

The Allure of Clean Architecture

Our journey then led us to NestJS. We were immediately struck by the beauty of its organization and the clarity of its structure. While it didn't have Frappe's all-in-one UI, its command-line scaffolding tools felt like a perfect fit for a developer-centric workflow.

Crucially, it was the official NestJS documentation on CQRS (Command Query Responsibility Segregation) that formally introduced us to the world of Domain-Driven Design. This was the missing piece. DDD provided the language and patterns to tackle software complexity at its core, moving beyond simple data structures to model rich domain behavior.

The "What If?" Moment: Bridging Two Worlds

With these two powerful but different inspirations, a question began to form:

What if we could combine the UI-driven scaffolding power of Frappe with the universal, framework-agnostic language of Domain-Driven Design that NestJS embraces?

Instead of inventing a new, framework-specific paradigm like DocType, we could use the established, industry-understood terms of DDD—Aggregates, Repositories, Domain Events, Commands, Queries—as the foundation for scaffolding.

The idea moved from concept to reality when we began turning it into a real project. It quickly became a collaborative effort: Prafful kicked things off by sharing the initial ast-based "CodeEngine," the very heart of our generation logic. Aditya built upon this foundation, adding the first set of component engines. Meanwhile, Ansh brought the vision to life with the React UI, skillfully tweaking the backend as needed to connect the two worlds. The core Architect backend was developed in parallel, tying all these pieces together into a cohesive system.

Building the Foundation: Castlecraft Engineer

Before we could scaffold anything, we needed a solid, DDD-native foundation in Python. Building another large, opinionated framework risked repeating the very patterns we wanted to move away from.

This led to the creation of Castlecraft Engineer. Inspired by the clean contracts of NestJS CQRS, Engineer is a minimal, contract-based Python library. It doesn't impose a database or a web framework on you. Instead, it provides the foundational building blocks—clear interfaces for Aggregates, Repositories, Commands, and Event Sourcing—that empower you to build a DDD-aligned system while maintaining full control over your infrastructure. It respects the Dependency Inversion Principle, making your core domain logic pure and testable. We also baked in core concerns like OIDC for authentication and a flexible AuthorizationService contract, allowing for simple or sophisticated permission models.

Realizing the Vision: Castlecraft Architect

With Engineer providing the DDD foundation, we could finally build the tool we had envisioned. Castlecraft Architect is the answer to that "what if" question. It is the intelligent scaffolding and development acceleration tool built on top of Engineer.

Architect transforms the development experience by:

  1. Facilitating Domain Exploration: It generates context suitable for Large Language Models (LLMs), enabling richer, AI-assisted discussions with domain experts to collaboratively define system components.
  2. Intelligent Scaffolding: It generates DDD-aligned boilerplate, creating a well-structured foundation that embodies best practices from the outset.
  3. AI-Powered Guidance: With an understanding of your project's structure, Architect, in conjunction with LLMs, can suggest contextually relevant code additions while respecting architectural integrity.
  4. Managed Revisions: Inspired by the challenges of large-scale collaboration, its "Revisions" system provides a controlled workflow for managing architectural changes, making it suitable for both solo developers and large, distributed teams.
  5. Deep Extensibility: The same DDD and layered principles used for generated apps were applied to Architect itself. This clean internal design enabled a powerful plugin system, allowing developers to add custom authorization adapters or even define new component types. In theory, a sophisticated plugin could adapt Architect to scaffold a project for an entirely different ecosystem, like NestJS.

The AI Catalyst

We have to give credit where it's due: AI was an indispensable partner in this journey. The ability to rapidly prototype, explore ideas, and generate code with Gemini Code Assist was what allowed us to bring this vision to a tangible state by June 30th. It proved the core concept: when you provide a well-structured context (like DDD), AI can become an incredibly powerful accelerator.

Our Goal

The synergy between Castlecraft Engineer's robust DDD foundation and Castlecraft Architect's AI-driven acceleration is our attempt to bridge the gap between sophisticated software design and pragmatic development. Our goal is to empower teams of all sizes to build complex, maintainable, and scalable systems more efficiently, moving beyond the limitations of traditional approaches to truly harness the power of Domain-Driven Design.

This philosophy drives the design of both Castlecraft Engineer and Architect. To see how these concepts are put into practice, we recommend exploring the Generated Project Architecture or diving into the Getting Started Guide.