Teach LLMs structural context before code generation
Instead of prompting LLMs to generate APIs from scratch, define an archetype—a declarative contract describing directory layout, component boundaries, and validation gates—so the agent understands structural constraints before writing code.
Score breakdown
Developers using LLM code generation can reduce architectural violations and layer leakage by defining structural constraints upfront, enabling agents to self-validate output against your system's actual shape rather than generating code blind.
- 01Archetypes are declarative contracts specifying directory layout, component boundaries, inter-component contracts, and validation gates before code generation
- 02The agent reads the archetype, generates code, then re-reads and scores its own output against the archetype constraints to catch violations
- 03The approach works best for greenfield projects; existing codebases and frequently-changing contracts require treating the archetype as a starting point rather than a fixed spec
One-shot LLM code generation fails because models have no structural context about your codebase architecture. Rlabs proposes using archetypes—declarative contracts that describe the shape of your system before generation begins. An archetype specifies: top-level directory layout, component boundaries and what crosses them, contracts between components, and validation gates that must pass post-generation. The agent reads the archetype, generates code (e.g., using Claude Code with an MCP server), then re-reads the archetype and scores its own output against it. If the self-challenge detects a violation (e.g., layer leakage, mocked tests where they shouldn't be), the agent corrects it and re-validates.
The approach has practical limits: it works best for greenfield projects rather than existing codebases, and the archetype must match your stack's actual shape, not just the language.
The approach has practical limits: it works best for greenfield projects rather than existing codebases, and the archetype must match your stack's actual shape, not just the language. Archetypes should be treated as a "starting chassis" rather than a spec of record, especially if contracts change frequently. Rlabs maintains a marketplace of 61 archetypes with documented schema at `/docs/archetype-schema`. A launch-week promotion (code SURPRISE_DEVTO) returns approximately 50% of the price as wallet credit, funded from the author's royalty, valid for 250 uses through June 18.
Key facts
- 01Archetypes are declarative contracts specifying directory layout, component boundaries, inter-component contracts, and validation gates before code generation
- 02The agent reads the archetype, generates code, then re-reads and scores its own output against the archetype constraints to catch violations
- 03The approach works best for greenfield projects; existing codebases and frequently-changing contracts require treating the archetype as a starting point rather than a fixed spec
- 04A marketplace of 61 archetypes is available with schema documented at `/docs/archetype-schema`
- 05Launch-week promotion SURPRISE_DEVTO returns ~50% of the price as wallet credit (funded from author royalty, 250 uses, expires June 18)