Skip to main content

Multi-language backend code generator from YAML specifications

Project description

SpecQL - Multi-Language Backend Code Generator

PyPI version PyPI - Python Version PyPI - Downloads License: MIT

๐Ÿšง v0.4.0-alpha: Production-ready for backend generation. APIs stable. Report issues.

One YAML spec โ†’ PostgreSQL + Java + Rust + TypeScript (100x code leverage)

SpecQL generates production-ready backends from business-domain YAML. Write your data model once, deploy across 4 languages.

Quick Example

15 lines of YAML:

entity: Contact
schema: crm

fields:
  email: text
  first_name: text
  last_name: text
  company: ref(Company)
  status: enum(lead, qualified, customer)

actions:
  - name: qualify_lead
    requires: caller.can_edit_contact
    steps:
      - validate: status = 'lead'
      - update: Contact SET status = 'qualified'
      - notify: owner

Auto-generates 2000+ lines across 4 languages:

  • โœ… PostgreSQL: Tables, indexes, constraints, audit fields, PL/pgSQL functions
  • โœ… Java/Spring Boot: JPA entities, repositories, services, controllers
  • โœ… Rust/Diesel: Models, schemas, queries, Actix-web handlers
  • โœ… TypeScript/Prisma: Schema, interfaces, type-safe client

Plus: FraiseQL GraphQL metadata, tests, CI/CD workflows.

Try it now | Read the guide

See It In Action

Installation

Installation Demo

Quick Start

Quick Start Demo

Multi-Language Generation

Multi-Language Demo

Reverse Engineering

Reverse Engineering Demo

What is SpecQL?

SpecQL transforms business-domain YAML into production-ready multi-language backend code:

# contact.yaml (15 lines - from actual example)
entity: Contact
schema: crm

fields:
  email: text
  first_name: text
  last_name: text
  company: ref(Company)
  status: enum(lead, qualified, customer)

actions:
  - name: qualify_lead
    requires: caller.can_edit_contact
    steps:
      - validate: status = 'lead'
        error: "not_a_lead"
      - update: Contact SET status = 'qualified'
      - notify: owner(email, "Contact qualified")

Auto-generates (from this single YAML):

PostgreSQL:

  • โœ… Tables with Trinity pattern (pk_*, id, identifier)
  • โœ… Foreign keys, indexes, constraints, audit fields
  • โœ… PL/pgSQL functions with full business logic

Java/Spring Boot:

  • โœ… JPA entities with Lombok annotations
  • โœ… Repository interfaces (JpaRepository)
  • โœ… Service classes with business logic
  • โœ… REST controllers with validation

Rust/Diesel:

  • โœ… Model structs with Diesel derives
  • โœ… Schema definitions (schema.rs)
  • โœ… Query builders and repositories
  • โœ… Actix-web HTTP handlers

TypeScript/Prisma:

  • โœ… Prisma schema with relations
  • โœ… TypeScript interfaces and types
  • โœ… Type-safe client generation

Plus:

  • โœ… FraiseQL metadata for GraphQL auto-discovery
  • โœ… 70+ automated tests (pgTAP SQL + pytest integration)
  • โœ… CI/CD workflows (GitHub Actions, GitLab CI)

Result: 2000+ lines across 4 languages + 70+ tests from 15 lines YAML (140x leverage)

Automated Testing

SpecQL automatically generates comprehensive test suites for your entities:

Generate Tests

# Generate both pgTAP and pytest tests
specql generate-tests entities/contact.yaml

# Generate only pgTAP (PostgreSQL unit tests)
specql generate-tests entities/*.yaml --type pgtap

# Generate only pytest (Python integration tests)
specql generate-tests entities/*.yaml --type pytest --output-dir tests/integration/

What Tests Are Generated?

From a single Contact entity (15 lines of YAML), SpecQL generates 70+ comprehensive tests:

pgTAP Tests (PostgreSQL unit tests):

  • โœ… Structure validation (10+ tests): Tables, columns, constraints, indexes
  • โœ… CRUD operations (15+ tests): Create, read, update, delete with happy/error paths
  • โœ… Constraint validation (8+ tests): NOT NULL, foreign keys, unique constraints
  • โœ… Business logic (12+ tests): Action execution, state transitions, validations

pytest Tests (Python integration tests):

  • โœ… Integration tests (10+ tests): End-to-end CRUD workflows
  • โœ… Action tests (8+ tests): Business action execution
  • โœ… Error handling (6+ tests): Duplicate detection, validation errors
  • โœ… Edge cases (5+ tests): Boundary conditions, state machine paths

Example: Contact Entity

# contact.yaml (15 lines)
entity: Contact
schema: crm

fields:
  email: email
  status: enum(lead, qualified, customer)

actions:
  - name: qualify_lead
    steps:
      - validate: status = 'lead'
      - update: Contact SET status = 'qualified'

Generates:

-- test_contact_structure.sql (50+ lines)
SELECT has_table('crm', 'tb_contact', 'Contact table exists');
SELECT has_column('crm', 'tb_contact', 'email', 'Has email column');
SELECT col_is_pk('crm', 'tb_contact', 'pk_contact', 'PK constraint');
-- ... 7 more structure tests

-- test_contact_crud.sql (100+ lines)
SELECT lives_ok(
  $$SELECT app.create_contact('test@example.com')$$,
  'Create contact succeeds'
);
-- ... 14 more CRUD tests

-- test_contact_actions.sql (80+ lines)
SELECT ok(
  (SELECT app.qualify_lead(contact_id)).status = 'success',
  'Qualify lead action succeeds'
);
-- ... 11 more action tests
# test_contact_integration.py (150+ lines)
class TestContactIntegration:
    def test_create_contact_happy_path(self, clean_db):
        result = execute("SELECT app.create_contact('test@example.com')")
        assert result['status'] == 'success'

    def test_qualify_lead_action(self, clean_db):
        # ... 9 more integration tests

Reverse Engineer Existing Tests

Import your existing pgTAP or pytest tests into universal TestSpec format:

# Parse pgTAP tests
specql reverse-tests tests/test_contact.sql

# Parse pytest tests with coverage analysis
specql reverse-tests tests/test_*.py --analyze-coverage

# Convert to universal YAML format
specql reverse-tests test.sql --entity=Contact --output-dir=specs/ --format=yaml

Use cases:

  • ๐Ÿ“Š Coverage analysis - Find missing test scenarios
  • ๐Ÿ”„ Framework migration - Convert between test frameworks
  • ๐Ÿ“š Documentation - Generate test documentation from code
  • ๐ŸŽฏ Gap detection - Identify untested business logic

Installation

From Source (Required for v0.4.0-alpha)

# Prerequisites: Python 3.11+, uv
# Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh

git clone https://github.com/fraiseql/specql.git
cd specql
uv sync
uv pip install -e .

Verify Installation

# Check CLI is available
specql --help

# Generate a test example
specql generate entities/examples/contact_lightweight.yaml --dry-run

# You should see generation output without errors

Coming soon: PyPI package (pip install specql-generator) in v0.5.0-beta

Prerequisites

  • Python: 3.11 or higher
  • uv: Installation guide
  • PostgreSQL (optional): For testing generated schemas
  • Java JDK 11+ (optional): For Java reverse engineering

Troubleshooting: See Installation Guide

CLI Commands

SpecQL provides a comprehensive CLI for all development workflows:

specql init - Project Scaffolding

Create new projects from templates:

specql init blog myblog        # Blog platform (Post, Author, Comment)
specql init minimal myproject  # Single entity example

specql generate - Code Generation

Generate multi-language code from YAML:

specql generate entities/*.yaml                    # All languages
specql generate contact.yaml --target postgresql  # PostgreSQL only
specql generate entities/ --dry-run               # Preview without writing

specql validate - Pre-flight Validation

Validate entities before generation:

specql validate entities/*.yaml           # Basic validation
specql validate entities/ --strict        # Fail on warnings
specql validate entities/ --format json   # JSON output for CI

specql examples - Built-in Examples

Learn from working examples:

specql examples --list                    # List all examples
specql examples with-actions             # Show specific example
specql examples blog-post > post.yaml    # Save to file

Complete Command Reference

See CLI Commands Reference for all options and examples.

Architecture

SpecQL Architecture

See detailed architecture documentation โ†’

Features

Multi-Language Code Generation โœ…

Generate production-ready code from single YAML specification:

PostgreSQL (Verified โœ…)

  • Database schema with Trinity pattern (pk_*, id, identifier)
  • Foreign keys, indexes, constraints, audit fields
  • PL/pgSQL functions with business logic
  • Test coverage: 96%+
  • Example: See PostgreSQL Generator

Java/Spring Boot (Verified โœ…)

  • JPA entities with Lombok annotations
  • Repository interfaces (JpaRepository)
  • Service classes with business logic
  • REST controllers with validation
  • Test coverage: 97%
  • Performance: 1,461 entities/sec
  • Example: See Java Generator

Rust/Diesel (Verified โœ…)

  • Model structs with Diesel derives
  • Schema definitions (schema.rs)
  • Query builders and repositories
  • Actix-web HTTP handlers
  • Test pass rate: 100%
  • Example: See Rust Generator

TypeScript/Prisma (Verified โœ…)

  • Prisma schema with relations
  • TypeScript interfaces and types
  • Type-safe client generation
  • Test coverage: 96%
  • Performance: 37,233 entities/sec
  • Example: See TypeScript Generator

Reverse Engineering (Partial ๐Ÿ”„)

Transform existing code back to SpecQL YAML:

  • PostgreSQL โ†’ SpecQL (schema introspection)
  • Python โ†’ SpecQL (dataclass and Pydantic parsing)
  • Java/Rust/TypeScript โ†’ SpecQL (in development)

Developer Tools (Partial ๐Ÿ”„)

  • Interactive CLI - Live preview with syntax highlighting
  • Pattern Library - Reusable patterns with semantic search
  • Visual Diagrams - Graphviz/Mermaid schema generation
  • CI/CD Generation - GitHub Actions, GitLab CI, CircleCI support
  • Infrastructure as Code - Terraform, Kubernetes, Docker Compose
  • Automated Test Generation - 70+ pgTAP SQL tests + pytest integration tests per entity

FraiseQL Integration (Partial ๐Ÿ”„)

  • Automatic GraphQL metadata generation
  • Vector search support via pgvector
  • Auto-discovery for instant GraphQL APIs
  • FraiseQL Integration Guide

Testing & Quality โœ…

  • Automated Test Generation - Generate 70+ comprehensive tests per entity (pgTAP + pytest)
  • 96%+ Coverage - Comprehensive test suite across 389 Python files (2937 tests)
  • Performance Benchmarks - 1,461 Java entities/sec, 37,233 TypeScript entities/sec
  • Security - SQL injection prevention, comprehensive security audit

Roadmap (Coming Soon)

  • ๐Ÿ”œ Go Backend - Go structs, GORM, HTTP handlers
  • ๐Ÿ”œ Frontend - React, Vue, Angular component generation
  • ๐Ÿ”œ Infrastructure as Code - Complete Terraform/Pulumi/CloudFormation
  • ๐Ÿ”œ Full-Stack Deployment - Single-command deployment to cloud
  • ๐Ÿ”œ PyPI Package - Install via pip install specql

See VISION.md and roadmap

Documentation

Real Examples

All from examples/ and entities/examples/:

Community & Support

Alpha Release: SpecQL is in early alpha. We're building in public!

Coming Soon: Discord community and GitHub Discussions

Contributing

See CONTRIBUTING.md for development setup and workflow.

License

MIT License - see LICENSE


Current Status

Release: ๐Ÿšง Alpha (v0.4.0-alpha) - Multi-language backend generation Languages: PostgreSQL + Java + Rust + TypeScript Test Coverage: 96%+ across 389 Python files (2937 tests) Stability: Pre-release - APIs subject to change

Supported Technologies

  • PostgreSQL: 14+ with Trinity pattern (pk_*, id, identifier)
  • Java: 17+ (Spring Boot 3.x, JPA/Hibernate, Lombok)
  • Rust: 1.70+ (Diesel 2.x, Actix-web)
  • TypeScript: 4.9+ (Prisma Client, type-safe interfaces)

Known Limitations

  • Frontend generation not yet implemented
  • Infrastructure as Code partial (Terraform/Pulumi in progress)
  • Not published to PyPI (install from source only)
  • Discord and GitHub Discussions not yet available

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

specql_generator-0.5.0b0.tar.gz (9.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

specql_generator-0.5.0b0-py3-none-any.whl (784.3 kB view details)

Uploaded Python 3

File details

Details for the file specql_generator-0.5.0b0.tar.gz.

File metadata

  • Download URL: specql_generator-0.5.0b0.tar.gz
  • Upload date:
  • Size: 9.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for specql_generator-0.5.0b0.tar.gz
Algorithm Hash digest
SHA256 aacf479dd1d478d6df4de0d4285d1488e91a6f285729197251836e2f2b8194da
MD5 4638bd3eee0cf1c3e1a9b999f6e54327
BLAKE2b-256 7d5fd0306c74e88a322b78a59a281036ff149c9d9e1bbf043f5d91e314e8991f

See more details on using hashes here.

File details

Details for the file specql_generator-0.5.0b0-py3-none-any.whl.

File metadata

File hashes

Hashes for specql_generator-0.5.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 07e9b8438eb84f0932b4bd2a2942a2a291d08dbaae1f95eb3c69af470c449c40
MD5 bff74e063ec2aedd7fd3fa6d3bcdaec2
BLAKE2b-256 238987ac5fb120161be9083a0bbdfb518e91ff5a8f721b34cc8c2a222a815c09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page