code-forge

$npx mdskill add techygarg/lattice/code-forge

Generates implementation code from design blueprints or verbal requirements.

  • Solves moving from approved design to working code with quality.
  • Depends on context anchoring, architecture, and test quality frameworks.
  • Decides based on domain-driven design and secure coding when applicable.
  • Delivers code with clean structure, tests, and security considerations.

SKILL.md

.github/skills/code-forgeView on GitHub ↗
---
name: code-forge
description: "Generate implementation code from an approved design blueprint or verbal requirements. Composes context anchoring, architecture, clean code, DDD, security, and test quality into an inside-out implementation workflow. Use when moving from design to code, implementing approved contracts, or when the user says 'implement', 'code this', 'build it', 'forge the code', or 'generate the code'."
---

# Code Forge

## Required Skills

Read, apply:

1. `framework:knowledge-priming` -- Load proj context (stack, arch, conventions) so impl matches real proj (always)
2. `framework:context-anchoring` -- Load/find context anchor doc; enrich as impl decisions made (always)
3. `framework:learning-harvest` -- Load prior operational learnings inform impl; harvest new patterns at session end (always)
4. `framework:collaborative-judgment` -- Surface real judgment calls w/ structured opts vs silent assume (always)
5. `framework:architecture` -- Layer place, dep direction, struct valid (always)
6. `framework:clean-code` -- Craft rails: SRP, naming, complexity, err handle (always)
7. `framework:domain-driven-design` -- Aggregates, entities, VOs, domain svcs (conditional: only when touch domain folder)
8. `framework:secure-coding` -- Trust bounds, injection prevent, secrets mgmt (conditional: only boundary-cross code)
9. `framework:test-quality` -- AAA struct, isolation, assert quality, naming (always when write tests)

## Workflow

### Step 1: Establish Implementation Context

Use `framework:learning-harvest` Load behavior. Focus hint: "implementation session — focus: implementation craft, quality signals, reliability".

Use `framework:context-anchoring` Doc Discovery check existing context anchor doc for feature impl.

- **If found** → Load (context-anchor Load behavior). Present struct ack -- feature name, **status**, decision count, open Qs, constraints. Honor all logged decisions/constraints as active commits.
- **If not found** → Nudge user: "Have design doc/blueprint for feature? Or work from discussed?" Accept either graceful.
  - User provides doc → load, follow.
  - Proceed without → all atom rails still apply; just no approved design doc to reference. Work from verbal reqs in convo.

**Design completeness check** — STOP gates before Step 2:

**Check 1 — status:** Read frontmatter `status`.
- `approved` → pass.
- Anything else → STOP: "Context doc not approved (`status: [value]`). Run design-blueprint first. Proceed anyway?" Confirm → log in Decisions Log, continue as "Without approved design."

**Check 2 — levels present:** Scan body for `## Design: Level 3` and `## Design: Level 4`.
- Both present → pass.
- Either missing → STOP: "Missing [Level 3 / Level 4 / both]. Proceed anyway?" Confirm → log absent levels in Decisions Log, treat as gaps to fill during implementation.

Both pass → proceed as **"With approved design"**.

### Step 2: Plan Implementation Order

**With approved design**: Extract component list, layer assigns from context anchor doc. Use L2 (Components) decisions for layer place, L3 (Interactions) for dep flow.

**Without approved design**: Classify req components→arch layers using layer defs from `framework:architecture`. Each component, determine:

- Primary responsibility? (biz rules, data access, coord, external I/O)
- Which layer in loaded arch doc matches responsibility?
- Dep constraints for that layer?

If `framework:architecture` no loaded layer defs (neither defaults nor custom doc resolved), warn: "No arch rules avail. Run `/architecture-refiner` define arch standards. Proceed w/o arch guidance." Continue w/ only remaining atom rails.

Present proposed layer assigns→user for approval before proceed.

Both cases, plan **inside-out impl order** following dep direction from loaded arch doc — start innermost layer (no outward deps), work outward. Each layer's deps should exist when built.

Classify each op per flow patterns in loaded arch doc (e.g., cmd vs query flows, or equiv distinction your arch style).

Present impl plan -- ordered component list, layer assigns, flow classifs -- confirm w/ user before write code.

After plan approved, ask user choose **review mode**:

> "How review impl?"
> 1. **Layer-by-layer** (rec) -- Impl each layer fully, pause for review before next. One review pt/layer.
> 2. **Full autonomy** -- Impl everything end-to-end, present complete result. One review pt at end. (If blueprint exists, still pause any deviation from approved design.)
> 3. **Component-by-component** -- Pause after each individual component for feedback. Max review pts.

Default **layer-by-layer** if user no preference.

### Step 3: Implement Per Component

Each component in planned order, gen **code+tests together** -- tests not afterthought.

Every component:

- **Prefer the simpler path first.** Before writing custom code: does a stdlib function, platform built-in, or existing dependency already cover this? If yes — use it. Can it be expressed in shorter code? Use that. Write custom code only when simpler options genuinely fall short.
- **Place correct arch layer** per `framework:architecture`. Valid dep direction follows loaded arch rules.
- **Apply `framework:clean-code` self-valid** during gen. Run inline checks: SRP comply, meaningful naming, low cyclomatic complexity, proper err handle, no magic vals, clean func sigs, no dead code, appropriate abstract level, clear control flow, minimal comments (code self-doc).
- **Write tests** using `framework:test-quality` self-valid.

Conditional checks per component:

- **If domain layer** → Apply `framework:domain-driven-design` self-valid.
- **If trust boundary** (HTTP handler, external API call, user input process, file I/O) → Apply `framework:secure-coding` self-valid.
- **If blueprint exists AND Level 4 was confirmed present in Step 1** → Verify component fulfills L4 (Contracts) spec. Flag any deviation from agreed contract. If user proceeded without L4 (Step 1 Check 2 failed), skip this check — there are no contracts to verify against.

**Post-Gen Verification** (applies every component, all review modes):

After gen each component, before present→user:

1. Run **Self-Valid Checklist** from each applicable atom against every func/class this component. Atoms use imperative STOP-verify lang -- follow literally.
2. Run **Active Anti-Pattern Scan** from each applicable atom. Check every box scan list.
3. Violations found → fix before present. Don't present code you know violates atom checklist.
4. Judgment calls flagged (see each atom's Ambiguity Signals) → collect. Present using `framework:collaborative-judgment` protocol before show code. Don't silent resolve.
5. All checks pass, no flagged judgment calls → present w/ brief comply note (e.g., "All clean-code, DDD checks pass"). Keep one line when clean -- only verbose when report violations, fixes.

**Pacing -- follow user's chosen review mode**:

- **Layer-by-layer**: Impl all components within layer, present full layer (code+tests) for review before next layer.
- **Full autonomy**: Impl all layers continuous. Present complete impl (all code+tests) at end. Skip→Step 4 (Cross-Component Verif) after all components done.
- **Component-by-component**: Present each component w/ tests individually. Wait approval before next.
- **Exception (all modes)**: Component needs significant deviation from plan (new dep, changed contract, unexpected complexity), pause immediately, discuss before continue -- regardless chosen review mode.

### Step 4: Cross-Component Verification

Step checks **arch coherence** -- not code quality (verified per-component Step 3). After all components impl:

- **With blueprint**: Verify interaction flows match L3 (Interactions) design. Every designed interaction traceable in code.
- **Dep direction**: Apply `framework:architecture` verif across all components — verify inter-component dep direction follows loaded arch rules. No layer import from layer not permitted depend.
- **Zero Impl Rule**: Check no new components, interactions, contracts intro beyond planned Step 2. Something added, flag -- may be necessary, but should be conscious decision, not scope creep.
- **Final security scan**: Apply `framework:secure-coding` across component boundaries. Check data flowing between components crosses trust bounds safely.
- **Learnings check**: If operational learnings loaded Step 1, verify previously-flagged patterns not recur this impl.

### Step 5: Enrich Context

Throughout Steps 3-4, use `framework:context-anchoring` Enrich behavior keep living doc current:

- **Add key files** as created -- path, purpose, layer assign.
- **Capture impl decisions** -- lib choices, pattern selects, deviations from blueprint, tradeoffs made.
- **Resolve open Qs** -- Qs from design phase answered during impl, log resolution.
- **If no context doc exists**, significant impl decisions made → suggest create. Decisions worth preserve future sessions.

**Harvest learnings.** Use `framework:learning-harvest` Harvest behavior. Session context: "implementation session — code generation from design contracts". Synthesize and propose cross-cutting patterns from this session — implementation gotchas, design-to-reality gaps, library/framework lessons. User confirms what enters the document. **STOP: run this before closing the feature lifecycle below.**

**Close feature lifecycle**: Write `status: complete` to context doc frontmatter. **STOP: required.**

**STOP: do not write status to `requirement_doc`.** The feature file's status is owned by whoever manages the requirement — a human, or an external system it may live in. This molecule manages its own context doc only.

After enrich context doc, recommend review:

> "Impl complete. Recommend run `/review` on gen code before consider feature done -- provides independent quality assess against same atom standards, catches issues generator may blind to, captures learnings future sessions."

More from techygarg/lattice

SkillDescription
architecture-compassArchitectural thinking partner for an existing repository — scans the codebase, conducts a structured interview, agrees on current architectural state and recommended direction, and produces a shareable insights document. Scoped to one repository, module, or folder. Does not execute transformation — it orients. Use when the user says 'assess my codebase architecture', 'what direction should my codebase go', 'architecture compass', 'understand my architecture', 'audit architecture drift', 'architectural assessment', or 'help me understand what is wrong with my codebase'.
architecture-refinerFacilitate a structured conversation to define architecture principles for a repository. Supports multiple architecture styles: clean architecture (default), hexagonal / ports & adapters, modular monolith, or custom. Produces a formal architecture document that the corresponding atom will use. Use when setting up a new project, defining architecture standards, or when the user says 'setup architecture', 'define layers', 'architecture principles', 'help me define my architecture', 'hexagonal architecture', 'modular monolith', 'ports and adapters', or 'define my architecture style'.
bug-fixInvestigate, reproduce, and safely fix a bug with regression protection. Composes context, diagnosis, architecture, code quality, and testing guardrails into a reproduce-first repair workflow. Use when the user says 'fix this bug', 'debug this', 'investigate this failure', 'patch this regression', 'repair this issue', or 'why is this broken'.
clean-code-refinerFacilitate a structured conversation to define clean code principles for a repository. Produces a formal clean-code.md document that the clean-code atom will use as its override. Use when setting up coding standards, defining code quality rules, or when the user says 'setup clean code', 'define coding standards', 'code quality principles', 'coding guidelines', or 'help me define my code standards'.
collaborative-judgmentProtocol for handling ambiguous decisions and missing/conflicting knowledge during code generation, design, and review. Ensures AI surfaces genuine judgment calls with structured options and stops on hallucination risk instead of silently assuming. Use when a decision has multiple valid approaches, when facts are missing or contradictory, when the user asks 'what should we do here?', 'is this a judgment call?', 'should I ask about this?', 'am I guessing here?', 'what are the tradeoffs?', or when deciding between two reasonable architectural or design options. Also composed by molecules to define how judgment calls and clarification requests are surfaced and resolved.
context-anchoringManage per-feature living documents that capture decisions, constraints, and reasoning across AI sessions during active development. Scoped to feature-level work — design, implementation, bugfix, refactor — not for codebase-wide assessments or product-wide specifications (those define their own document lifecycles). Handles creating new context documents, loading existing ones, and enriching them with new decisions. Use when starting a new feature, resuming work, making technical decisions, resolving questions, or when context needs to persist across sessions. Use this skill whenever the user mentions 'load context', 'update context', 'context doc', 'decisions', 'continue where we left off', 'what did we decide', or 'capture this decision'.
ddd-refinerFacilitate a structured conversation to define DDD guardrails for domain design within a repository. Produces a formal ddd-principles.md document that the domain-driven-design atom will use as its override. Use when setting up domain design principles, defining aggregate rules, or when the user says 'setup DDD', 'define domain rules', 'DDD principles', or 'help me define my domain patterns'.
design-blueprintRun a complete design workflow -- from establishing context through 5 progressive design levels to an approved blueprint. Composes context anchoring, design-first methodology, architecture, and DDD into a unified process. Handles both new features (create context doc) and resuming existing work (load context doc). Use when starting a design, planning architecture, or when the user says 'design a feature', 'blueprint', 'start designing', 'plan the architecture', or 'let's design before coding'.
knowledge-primingLoad project-specific context -- tech stack, architecture overview, directory layout, trusted sources, and conventions -- so that all skills operate with awareness of what this project actually is. Use when a knowledge base document exists, or when the user asks about the project's tech stack, architecture, conventions, framework, directory layout, or says 'tell me about this project', 'what are we using?', 'what's our stack?', or 'what framework is this?'. Use the knowledge-priming-refiner to create a knowledge base document.
knowledge-priming-refinerFacilitate a structured conversation to create a project-specific knowledge base document. Produces a knowledge-base.md that primes AI with the project's tech stack, architecture, trusted sources, and project structure. Use when the user says 'set up knowledge base', 'prime the project', 'onboard AI', 'create knowledge base', 'set up project context', or 'configure AI context'.