Skip to content

This project demonstrates contract-first development using a spec-kit approach where OpenAPI specifications evolve organically through feature development. Each feature analyzes existing contracts for reuse before extending the API, using Specmatic MCP as intelligent guardrails throughout the process.

Notifications You must be signed in to change notification settings

specmatic/specmatic-mcp-sample-with-spec-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Specmatic MCP Sample Project

This project demonstrates contract-first development using spec-kit where OpenAPI specifications evolve organically through feature development. Each feature analyzes existing contracts for reuse before extending the API, using Specmatic MCP as intelligent guardrails throughout the process.

πŸš€ Quick Start

# Configure MCP servers
claude mcp add specmatic npx "specmatic-mcp"
claude mcp add playwright npx "@playwright/mcp@latest"

# Open project
claude

Try the spec-kit workflow:

/specify product listing page
- each product has name, description, price and category, all of these properties are mandatory
- category can be only "food", "gadget", "book" or "other"
- default sort order is alphabetical by name
- users should be able to filter by category
- no pagination required, just show all available products as per category filter
/plan
/tasks
implement T001-T006

Execute tasks in small chunks or all at once. The gated tasks make it easy to pause/resume without losing context.

πŸ“¦ Specmatic MCP Resources

Note: This project uses Claude Code for demo purposes, however you can use any coding agent of your choice and make necessary changes accordingly.

🎯 What This Template Demonstrates

This template shows API Design First methodology in action. Starting from zero (no pre-existing contracts), observe how:

  • Contract-first development works using the spec-kit workflow: /specify β†’ /plan β†’ /tasks β†’ implement
  • OpenAPI specifications evolve organically through feature development
  • Existing API operations are analyzed for reuse before extending contracts
  • Teams can work independently after agreeing on the contract
  • Specmatic MCP provides intelligent guardrails throughout the process
  • Frontend and backend stay synchronized with the evolving API specification

βœ… Prerequisites

Install Claude Code (if not already installed): Follow installation instructions at https://docs.anthropic.com/claude/docs/claude-code

πŸ”„ Optional Reset

Reset the project to try again (optional - Claude Code command available):

/reset-sample-project

πŸ“ Project Structure

specmatic-mcp-sample-with-spec-kit/
β”œβ”€β”€ api_spec.yaml         # OpenAPI specification (evolves with each feature)
β”œβ”€β”€ specs/               # Feature specifications and plans
β”‚   β”œβ”€β”€ 001-product-listing/
β”‚   β”‚   β”œβ”€β”€ spec.md     # Feature specification  
β”‚   β”‚   β”œβ”€β”€ plan.md     # Implementation plan
β”‚   β”‚   └── tasks.md    # Generated tasks
β”‚   └── 002-next-feature/
β”œβ”€β”€ backend/             # Node.js/Express API implementation (generated)
β”œβ”€β”€ frontend/           # React frontend application (generated) 
β”œβ”€β”€ memory/             # Project constitution and guidelines
β”‚   └── constitution.md
β”œβ”€β”€ templates/          # Spec-kit templates for feature development
└── .claude/           # Spec-kit commands (specify, plan, tasks)

🎯 Key Benefits Demonstrated

Contract-First Development

  • OpenAPI specifications evolve organically through feature development
  • Each feature analyzes existing contracts for reuse before extending
  • Both frontend and backend are built to conform to the evolving contract
  • Smart contract analysis prevents API bloat and promotes reuse

True Test-Driven Development

  • Contract tests MUST fail before any backend implementation exists
  • Backend routes/endpoints implemented only to make failing tests pass
  • Resiliency tests MUST fail before input validation is added
  • Follows strict RED-GREEN-REFACTOR cycle throughout

Independent Development

  • Backend implemented first against failing contract tests
  • Frontend developed using Specmatic's mock server (port 9001) in parallel
  • No coordination needed - contract serves as the agreement between teams

Automatic Validation

  • Specmatic MCP automatically validates backend implementations
  • Contract tests ensure API compliance
  • Resiliency tests verify error handling and boundary conditions

Zero Dependencies

  • Specmatic runs as an MCP server through NPX
  • No need to add Specmatic dependencies to your project
  • Clean project structure with minimal tooling overhead

πŸ”§ How It Works

  1. Spec-Kit Workflow: Features developed through specify β†’ plan β†’ tasks β†’ implement cycles

  2. Smart Contract Evolution:

    • First feature creates initial OpenAPI specification at repository root
    • Subsequent features analyze existing contracts for reuse opportunities
    • Only extends API when existing operations cannot support new features
    • Prevents API bloat through intelligent contract analysis
  3. Specmatic MCP Integration:

    • Provides contract testing capabilities for evolving specifications
    • Offers mock server functionality for isolated frontend development
    • Validates implementations against the current contract state
    • Runs resiliency tests for error scenarios
  4. Constitutional Governance:

    • All development follows constitutional principles in /memory/constitution.md
    • Ensures consistent, high-quality feature development
    • Maintains contract-first discipline throughout the process

πŸ—οΈ Architecture Diagrams

Production Setup

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚ ────── HTTP Requests ───────────► β”‚                 β”‚
β”‚    Frontend     β”‚                                   β”‚    Backend      β”‚
β”‚   (React App)   β”‚        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚ (Express API)   β”‚
β”‚                 β”‚        β”‚  api_spec.yaml   β”‚       β”‚                 β”‚
β”‚   Port: 4000    β”‚        β”‚ (Evolved OpenAPI)β”‚       β”‚   Port: 3000    β”‚
β”‚                 β”‚        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚                 β”‚
|                 |                                   |                 |
β”‚                 β”‚ ◄────── HTTP Responses ────────── β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Development Setup - Frontend

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚                     β”‚                 β”‚
β”‚    Frontend     β”‚     Mock Requests   β”‚ Specmatic Mock  β”‚
β”‚   (React App)   β”‚ ◄─────────────────► β”‚    Server       β”‚
β”‚                 β”‚                     β”‚                 β”‚
β”‚   Port: 4000    β”‚                     β”‚   Port: 9001    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                  β”‚
                                                  β”‚ Based on
                                                  β”‚
                                                  β–Ό
                                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                     β”‚                     β”‚
                                     β”‚   api_spec.yaml     β”‚
                                     β”‚  (Evolved OpenAPI)  β”‚
                                     β”‚                     β”‚
                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Development Setup - Backend

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚                       β”‚                 β”‚
β”‚ Specmatic MCP   β”‚ ───► Contract   ───►  β”‚    Backend      β”‚
β”‚    Tools        β”‚      Testing          β”‚ (Express API)   β”‚
β”‚                 β”‚                       β”‚                 β”‚
β”‚ (via NPX)       β”‚ ───► Resiliency ───►  β”‚   Port: 3000    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜      Testing          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β”‚ Validates against
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     β”‚
β”‚   api_spec.yaml     β”‚
β”‚  (Evolved OpenAPI)  β”‚
β”‚                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎨 Contract Evolution Example

As features are developed, the API evolves organically:

Feature 1 (001-product-listing):

  • Creates initial api_spec.yaml with GET /products endpoint
  • Includes product filtering by type (book, food, gadget, other)

Feature 2 (002-product-creation):

  • Analyzes existing contract β†’ No POST endpoint exists
  • Extends api_spec.yaml with POST /products and validation schemas

Feature 3 (003-product-search):

  • Analyzes existing contract β†’ GET /products with query params might suffice
  • Reuses existing endpoint instead of creating new ones

The complete API specification emerges through this thoughtful, feature-driven evolution.

πŸ—οΈ API Design First Workflow

  1. Feature Specification: Use /specify to create feature requirements and user stories
  2. Contract Analysis: Use /plan to analyze existing contracts and extend only if needed
  3. Task Generation: Use /tasks to break down implementation into concrete steps
  4. Backend-First Implementation (RED-GREEN-REFACTOR):
    • RED: Contract tests MUST FAIL (no routes/endpoints exist yet)
    • GREEN: Implement just enough backend code to make contract tests pass
    • RED: Resiliency tests MUST FAIL (no input validation exists yet)
    • GREEN: Add input validation to make resiliency tests pass
    • REFACTOR: Clean up implementation while keeping tests green
  5. Frontend Implementation: Develop UI against Specmatic mock servers (port 9001) in parallel
  6. Integration: Switch frontend to real backend (port 3000) and verify end-to-end
  7. Iteration: Repeat for next feature, building on the evolved contract base

πŸ“š Learn More


Ready to see spec-kit contract evolution in action? Just ask Claude to build your first feature!

About

This project demonstrates contract-first development using a spec-kit approach where OpenAPI specifications evolve organically through feature development. Each feature analyzes existing contracts for reuse before extending the API, using Specmatic MCP as intelligent guardrails throughout the process.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages