Skip to content

Reading

Appearance

Text size

Bookmarks

    No bookmarks yet. Use “Bookmark chapter” or “Bookmark this section” while reading.

    Your data

    Saved only in this browser on this device. It is not synced to other devices or sent anywhere.

    Chapter 9 of 22 · about 2 min

    9. Step 1: constitution

    What it is

    The constitution holds your project's non-negotiable, long-term rules. Think of it as the "house rules" the AI must obey in every spec, plan, task and line of code.

    What belongs in it

    • Language and framework versions (e.g. Java 21, Spring Boot 3.x, Maven)
    • Architecture (layered: controller → service → repository; no business logic in controllers)
    • Coding standards and naming conventions
    • Testing rules (test-first; unit tests with JUnit 5; integration tests with Testcontainers; minimum coverage X%)
    • Security rules (never log passwords; validate all input; secrets come from environment variables)
    • API design conventions, error-handling style, logging and observability
    • Documentation standards
    • How the constitution itself gets amended (versioning, who approves)

    What does NOT belong in it

    Anything about a specific feature. "Users register with email" is a spec, not a constitution rule.

    Optional exerciseConstitution or feature spec?
    “Testing rules: test-first; unit tests with JUnit 5”
    “Users register with email”
    “Security rules: never log passwords; validate all input”
    “A password of at least 8 characters”
    “How the constitution itself gets amended (versioning, who approves)”
    “Registration is rejected with "Email address is already in use."”
    The rules are quoted from "What belongs in it"; the feature items come from chapter 10's user-registration example. Each answer cites its source.

    Tip from the course (a very good habit)

    Before running the command, use a chat AI to draft it with you, and ask the AI to interview you first:

    "Help me write a Spec Kit constitution prompt for a Spring Boot / Java 21 web app. First read the latest Spec Kit docs on the constitution command. Then ask me questions about build tool, architecture, testing, persistence, security, UI, and conventions. Only after I answer, write the prompt. Include only long-term rules, nothing feature-specific."

    Asking questions first stops the AI from inventing your standards.

    How to run it

    In your agent's chat:

    /speckit-constitution This is a Spring Boot 3 web application on Java 21, built with Maven.
    Architecture: layered (web → service → repository). Controllers contain no business logic.
    Testing: test-first. Every feature needs unit tests (JUnit 5, Mockito) and at least one
    integration test. Tests must fail before implementation is written.
    Persistence: Spring Data JPA, schema changes only through Flyway migrations.
    Security: never store or log plain-text passwords; validate all user input on the server.
    UI: server-side rendered Thymeleaf templates.
    Keep it simple: no extra abstraction layers or libraries without a documented reason.

    What happens

    The AI fills in the template placeholders in .specify/memory/constitution.md, adds a version number and dates, and keeps the dependent templates in sync with your rules.

    Your job afterwards

    Read it carefully. Every later step follows it, so a wrong rule here spreads into everything that comes after.

    Learning aidThe foundation under every step
    Every later step follows the constitution, so a wrong rule here spreads into everything that comes after.

    Background: the "Nine Articles"

    Spec Kit's methodology document (spec-driven.md) gives an example constitution with "articles" such as Library-First, CLI Interface, Test-First (non-negotiable), Simplicity (no more than 3 projects at first), Anti-Abstraction (use the framework directly instead of wrapping it), and Integration-First Testing (prefer real databases to mocks). The plan step then runs "gates" that check the design against these articles. You don't have to copy them, but they show the kind of thing a constitution should say.