DEV Community

Maksim Zaborovskiy
Maksim Zaborovskiy

Posted on

Main spex. AI-first spec-driven development framework

Hi! I want to introduce you to Main spex framework, spex for short. It is a spec-driven development framework, in the same family as OpenSpec or Spec Kit: you write down what you want as specifications, and the AI builds from them.

The goal is to produce slop-free, verifiable results fast, with minimal human intervention — unleashing AI's full speed. The AI writes everything, following the specs, skills, and rules. The human decides, reviews, and approves what matters. Verification layers of agent reviews, tests, and deterministic checks prove the result.

In this article I'll explain why we need something like this, how it works, and how you can try it yourself.

1. Why develop with AI at all

Let's start with the obvious part. Used right, AI writes code faster than a developer, and the quality can stay high.

It is also pretty cheap, and it keeps getting faster and better. Writing every line by hand cannot match the speed of handing that work to AI, whether you are a single developer or a whole company. The gap only grows from here.

So the question is not whether to let AI write the code. The question is how to make sure the result is what we wanted, and as good as we wanted.

2. Why do we need specifications?

Ask an AI for a snake game and you will get one. But it is the snake the model imagined, built the way it was trained to build things. Ask three models and you get three different games.

If instead you specify that you want a snake with big blue eyes that eats donuts you will get it. Example is simple, but you get the idea - every detail you leave out, the model fills in with its own guess.

That is what a specification is for. A spec is a short description of one thing the system must do, with a list of acceptance criteria. Here is one from the spex library, an email policy:

id: email-policy
title: Validate and normalize email addresses
description: Accepts any email address a user can type and stores it in one canonical form so the same mailbox is never registered twice, for every email address the system stores. Loosely follows RFC 5321, RFC 5322, RFC 6531 and the OWASP Input Validation Cheat Sheet.
acceptance_criteria:
  - id: trimmed
    must: "trim leading and trailing whitespace (the Unicode `White_Space` property) from `email` as the first step, before validating, storing or comparing it, because a stray space from typing or autocomplete is most likely a user mistake and, unlike in a password, trimming changes no secret"
  - id: normalized
    must: "normalize `email` to NFC and lowercase it after trimming, at creation, change and login, before validating, storing or comparing it, so the same address typed in different cases or on different devices is one address, because RFC 5321 allows a case-sensitive local part but virtually no provider treats it so"
  - id: international-addresses
    must: "accept non-ASCII characters in `email` (RFC 6531) and store its domain in ASCII (punycode) form, so internationalized addresses work and one domain has one stored form"
  - id: length-limits
    must: "reject an `email` longer than 254 bytes in UTF-8 or with a local part longer than 64 bytes in UTF-8, the RFC 5321 limits, when a user sets or changes it"
  - id: shape-only-validation
    must: "validate only the shape of `email` when a user sets or changes it: one `@` separating a non-empty local part from a domain with at least one dot, because the full RFC grammar is too complex for a regex and only a message sent to the address proves it works"
  - id: plain-addresses-only
    must: "reject an `email` containing whitespace or a control character (Unicode category `Cc`), a display name (`Name <a@b.c>`), a comment, a quoted local part or an IP address in place of a domain, because nobody types those forms and they are the usual way to inject mail headers or confuse parsers"
  - id: unique-per-account
    must: "allow an `email` to belong to one account only, compared after normalization, so a case or Unicode variant cannot register the same mailbox twice"
  - id: no-provider-rules
    must_not: "alter the local part of `email` by provider-specific rules, such as removing dots or `+tag` suffixes, because those rules hold for some providers only and would merge distinct mailboxes on the others"
  - id: no-domain-blocking
    should_not: "reject an `email` by its domain, such as free-mail or disposable-address providers, because such lists are never complete and block real users"
Enter fullscreen mode Exit fullscreen mode

Specifications are foundation of the whole framework.

3. A spec is not enough

A spec tells us what we want to build. By itself it does nothing to check that the AI built it, or built it the way we expected.

AI writes code fast, but fast is not the same as right. It can add changes nobody asked for. It can forget a requirement. It can solve the same problem differently every time. Or it can simply make things up.

Every decision nobody reviewed and every result nobody verified adds a bit of slop. Slop piles up. Slowly the code gets harder to maintain, we trust it less, and we stop really understanding it.

You can review everything by hand, but then you throw away the speed. Or you can accept everything, and then you ship the slop.

There is a third way. Instead of fighting the agent in a loop of prompts, explaining how we want it built, reminding it what it forgot, checking every line, we build automated layers of verification on top of the specs. Those layers give us the slop-free result we wanted.

This is what Main spex (spex for short) does.

4. The framework

Work flows in one direction:

PRD → spec → contract → implementation → test

Four pieces hold it together:

  • Spec says what to build.
  • Rule says how to build it.
  • Skill is the set of instructions the AI follows.
  • Traceability links all of it together.

It is quick to start. A project can set spex up in about five minutes. And it does not care what you use: any model, any coding agent, any terminal or IDE, any language. It adapts to your project, not the other way around.

5. Verification layers

The idea behind all the layers is the same. Deterministic checks prove what they can. AI handles what checks can't. Humans reviews what matters.

5.1 PRD, spec and contract

There are three layers of specification, from top to bottom. Each one is a different kind of document, not just a longer version of the one above.

  • PRD. One per project. A short overview of why we build this and what it does: the problem, the goal and the main capabilities. No details.
  • Spec. The detailed description of one capability, with acceptance criteria. Most specs break down one of the PRD's main capabilities.
  • Contract. Comes from a spec, where it applies. It adds the interface to build against: an OpenAPI schema for an API, a Figma design for a screen.

Specs and contracts are small, so they are quick to review. A human approves them before any code is written, and the agent builds against a fixed target.

They are also used to verify the result. The review agent reads the PRD to understand the goal behind a spec, then checks the implementation against the spec and the contract.

5.2 Traceability

@spec annotations are simple comments and they connect a spec to its contract, its code and its tests.

Every acceptance criterion must have an implementation and a test. The spex coverage command checks that, the same way every time, so nothing gets forgotten. And an agent can follow the trail from a spec to everything it produced, and back again.

5.3 Rules and checks

Rules describe how we want things done: style, structure, security. The spex check command proves that they were followed.

When we notice the same mistake again and again, we add a check for it. If needed, that is our own project-specific lint.

5.4 Review agents

A review agent looks at every change and compares it with our specs, rules and PRD.

Each pull request also gets a risk label: low, medium or high. A change that implements a spec that is already verified and approved, or a low-risk change to code or tests, may not need a human at all. Human review goes only to the important parts, so it never becomes the bottleneck.

6. Skills

Skills are not verification. They are instructions that make the AI do a job the exact same way every time.

Without them, every step is improvised in chat. What should it read? Which rules apply? What needs updating afterward? The answer depends on what somebody remembered that day. A skill writes the answer down once, as a procedure you can repeat.

  • There is one skill for each step of the work: spec, implement, review, test and orchestrators that combine them.
  • Every package gets its own skill, with its structure, its commands and its rules. You never explain the package again in a new session. The skill is created when you add the package, and the agent keeps it up to date as the package changes.
  • Every framework skill has two parts. The top is generic, and the framework keeps it up to date. Below it is a part that belongs to your project. You can adapt a skill a little by adding to your part, or fully by turning updates off for that skill and owning all of it.
  • Skills load on demand. Only the short description is always in the context, and the full text loads when it is needed. A smaller context gives better output.

7. Specs and rules library

The same tasks come back in every project, so we reuse and adapt instead of reinventing the wheel.

spex lib ships ready-made rules, such as naming, commit messages, OpenAPI, Postgres and secret handling. It also has template specs, such as password policy and email policy. The library will grow with community contributions, so building a project starts to feel like putting building blocks together.

Every project then adapts them to its own needs.

8. Final

Want to try it? Install it and set up a project:

cargo install main-spex
spex init
Enter fullscreen mode Exit fullscreen mode

Top comments (0)