Multi-language backend code generator from YAML specifications
Project description
SpecQL - Multi-Language Backend Code Generator
๐ง 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.
See It In Action
Installation
Quick Start
Multi-Language Generation
Reverse Engineering
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
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
Documentation
- ๐ Getting Started - 5-minute quick start
- ๐ Tutorials - Step-by-step guides
- ๐ Guides - Complete feature documentation
- ๐ง Reference - YAML syntax reference
- ๐๏ธ Architecture - How SpecQL works
- ๐ฎ Vision - Future roadmap
Real Examples
All from examples/ and entities/examples/:
- Contact Manager - Simple CRM
- E-Commerce - Orders, payments, inventory
- Java/Spring Boot - JPA entities with Lombok support
- TypeScript/Prisma - Prisma schemas with TypeScript interfaces
- SaaS Multi-Tenant - Enterprise patterns
- Simple Blog - CRUD basics
Community & Support
Alpha Release: SpecQL is in early alpha. We're building in public!
- ๐ Documentation - Complete guides and references
- ๐ Report Bugs - Help us improve
- ๐ก Feature Requests - Share your ideas
- ๐ฆ Examples - Working code examples
- ๐ Changelog - See what's new
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aacf479dd1d478d6df4de0d4285d1488e91a6f285729197251836e2f2b8194da
|
|
| MD5 |
4638bd3eee0cf1c3e1a9b999f6e54327
|
|
| BLAKE2b-256 |
7d5fd0306c74e88a322b78a59a281036ff149c9d9e1bbf043f5d91e314e8991f
|
File details
Details for the file specql_generator-0.5.0b0-py3-none-any.whl.
File metadata
- Download URL: specql_generator-0.5.0b0-py3-none-any.whl
- Upload date:
- Size: 784.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07e9b8438eb84f0932b4bd2a2942a2a291d08dbaae1f95eb3c69af470c449c40
|
|
| MD5 |
bff74e063ec2aedd7fd3fa6d3bcdaec2
|
|
| BLAKE2b-256 |
238987ac5fb120161be9083a0bbdfb518e91ff5a8f721b34cc8c2a222a815c09
|