# Spec-Driven Development on an Existing Codebase: BA-Kit + OpenSpec + ChatQA

Most SDD tutorials start with an empty folder. My real projects never do.

I work on logistics systems that already have years of code, a Vietnam-based dev team, and requirements scattered across chats, Jira tickets and people's heads. "Write the spec first" sounds great until you realize there is nothing to write it *on top of*.

This post is how I'm closing that gap with three pieces:

- **BA-Kit** to produce the business-side documents (URD, SRS, user stories, acceptance criteria)
- **OpenSpec** to turn each change into a small, reviewable plan before any code
- **ChatQA** to verify the result on real devices after coding

## The mental model: three layers, three questions

| Layer | Tool | Question it answers |
| --- | --- | --- |
| Business | BA-Kit | What does the business need, and what are the acceptance criteria? |
| Change | OpenSpec | What exactly changes in *this* system, and what are the tasks? |
| Proof | ChatQA | Does the built thing actually work on a real phone or browser? |

Each layer feeds the next. If one is missing, the AI fills the gap with guesses.

## Why OpenSpec fits existing projects

OpenSpec's own philosophy says "built for brownfield not just greenfield". In practice that means one important thing: **you do not have to document the whole system first.**

After `openspec init`, `openspec/specs/` is empty. Your specs grow one change at a time: each finished change is archived, and archiving merges its requirements into the main specs. Six months later, the areas you actually touched are documented. The areas you never touched stay out of the way.

Compare that with "write a full spec of the legacy system", which nobody finishes.

## Setup on an existing repo (10 minutes)

```bash
# install (macOS/Linux)
curl -fsSL https://openspec.dev/cli/install.sh | sh

cd your-existing-project
openspec init
```

Two details that matter for existing repos:

1. **Skills install globally by default** (`~/.agents/skills/`), so nothing is dropped into your repo besides the `openspec/` folder. If your team wants skills committed, use `openspec init --scope project`.
2. **BA-Kit also uses** `.claude/skills/`**.** BA-Kit's own instructions say: if `.claude/` already exists, merge, don't overwrite. OpenSpec skills are named `openspec-*`, so the two sets sit side by side.

Then edit `openspec/config.yaml`. This is where an existing project differs from a new one, because the AI cannot see your conventions by reading code alone:

```yaml
schema: spec-driven

context: |
  Logistics platform. Backend: Quarkus + Kafka on Kubernetes.
  Mobile apps are tested on real iOS and Android devices.
  Write all artifacts in English.
  Source business docs live in docs/ (generated by BA-Kit).

rules:
  proposal:
    - Link the BA-Kit SRS section this change implements
  tasks:
    - The last task is always: run the affected flows in ChatQA and attach the report

operations:
  apply:
    guidance:
      - Run the linter before marking a task complete
```

Keep it short. OpenSpec warns that everything here lands in the agent's context, and verbose rules make output worse.

> Replace the `context` above with your real stack. The point is the pattern: stack, constraints, where business docs live.

## The loop on a real change

OpenSpec's loop has five steps: **explore → propose → review → apply → archive.**

### 1\. Business input from BA-Kit

A customer asks for a change. Instead of pasting the email into the AI, I run BA-Kit first:

- `/brainstorm` to pin down scope and ambiguous points
- `/srs` or `/userstory` + `/ac` to get requirements and acceptance criteria as files in `docs/`
- On legacy features with no docs, `/code-to-srs` reconstructs an SRS from the source code, with a confidence level per section

When requirements change mid-flight, `/cr` checks which documents are affected before anything is edited.

This step answers "what does the business want". It does not touch code.

### 2\. Explore, then propose (OpenSpec)

```plaintext
/openspec-explore
> Read docs/orders/srs/spec.md. How should we add partial cancellation to the order flow?
```

Explore is a thinking mode: it reads your codebase, compares options, and writes no code. This is the step that matters most on legacy code, because the AI discovers constraints you forgot to mention.

When the shape is right:

```plaintext
/openspec-propose add-partial-cancellation
```

You get a change folder:

```plaintext
openspec/changes/add-partial-cancellation/
├── proposal.md   why, and what changes
├── specs/        requirements and scenarios (delta specs)
├── design.md     technical approach (only when needed)
└── tasks.md      implementation checklist
```

### 3\. Delta specs: the feature that makes brownfield work

On an existing system you rarely add whole new capabilities. You *modify* behavior. OpenSpec handles this with **delta specs**: instead of rewriting a spec, you describe only what changes.

```markdown
## MODIFIED Requirements

### Requirement: Order cancellation
The system SHALL allow cancelling individual items of an order before pickup.

#### Scenario: Cancel one item
- **WHEN** the customer cancels one item of a 3-item order before pickup
- **THEN** the order total is recalculated and the other 2 items stay active
```

The available operations are `ADDED`, `MODIFIED`, `REMOVED` (needs a reason and migration note) and `RENAMED`. Three rules from the docs that save time:

- Scenarios must use exactly four `####` hashtags, or they fail silently.
- Every requirement needs at least one scenario.
- Run `openspec validate --strict` to catch weak scenarios before the AI starts coding.

Pure refactors with no behavior change can skip specs with `skip_specs: true`.

### 4\. Review the plan, not the code

This is the step people skip, and it is where SDD pays off. Read in this order: `proposal.md` (right problem?), `specs/` (would I accept these as "done"?), `tasks.md` (does it cover the specs and nothing more?).

Fixing a wrong sentence in a spec costs seconds. Fixing wrong code costs a sprint.

### 5\. Apply and archive

Start a **fresh chat session** for apply. OpenSpec recommends a clean context window for implementation.

```plaintext
/openspec-apply-change
```

The agent works through `tasks.md` and ticks checkboxes. If the session dies, open a new one and apply again: it resumes at the first unchecked task. There is no hidden state, just the checkboxes.

When all tasks are done:

```plaintext
/openspec-archive-change
```

The delta merges into `openspec/specs/` and the change folder moves to `openspec/changes/archive/`. Your system documentation just grew by exactly the part you touched.

## After coding: where ChatQA comes in

Specs describe intended behavior. They do not prove it. OpenSpec ships an optional `openspec-verify-change` step (enable it via `openspec config profile`) that checks the implementation against the plan, but it does not run your app on a phone.

That is the gap [ChatQA](https://chatqasoft.zhst.app/) fills, and it connects to the spec in three ways:

1. **Scenarios become flows.** Each `WHEN/THEN` scenario maps naturally to a test flow. ChatQA uses plain files: Maestro YAML for mobile, Playwright Test for web.
2. **The AI can drive it.** ChatQA exposes 49 tools over MCP, so the same agent that implemented the change can ask: "Run the login and cancel-order flows on every free Android phone and report errors."
3. **It knows what to run.** ChatQA reads a git diff between two versions and tells you which flows are affected, so you don't re-test everything after every change.

Closing the loop is one line in `config.yaml` (shown above): make the final task of every `tasks.md` a ChatQA run. The change is only "done" when the evidence (screenshots, logs, HTML report) exists.

## The full pipeline

```plaintext
Customer request
   → BA-Kit      /brainstorm → /srs → /userstory + /ac
   → OpenSpec    explore → propose → review the plan
   → Coding      apply (fresh session)
   → ChatQA      run affected flows on real devices, keep the evidence
   → OpenSpec    archive (specs updated)
   → BA-Kit      /doc-drift to check docs still match
```

## What I'd tell someone starting tomorrow

- **Don't backfill.** Start with the next real change, not a documentation project.
- **Put your conventions in** `config.yaml`, not in your head.
- **Review specs like code.** It's the cheapest review you'll ever do.
- **Keep changes small.** One change folder, one capability, one reviewable plan.
- **Make "done" mean evidence**, not "the AI said it's finished".

## Conclusion

- OpenSpec works best with high-reasoning models, and the docs recommend clearing context before implementation.
- Writing specs adds up-front time. It pays back on changes that touch legacy behavior, and is overkill for a one-line fix.

---

*Links:* [*OpenSpec*](https://github.com/Fission-AI/openspec) *·* [*OpenSpec docs*](https://openspec.dev/docs) *·* [*ChatQA*](https://chatqasoft.zhst.app/)

#sdd #openspec #ai #testing #buildinpublic
