ggen 1.2.0

ggen is a deterministic, language-agnostic code generation framework that treats software artifacts as projections of knowledge graphs.
Documentation

Table of Contents

ggen - Graph-Aware Code Generation Framework

GitHub Pages Rust License Crates.io Build Status Test Coverage Security Audit Docs Status

ggen is a production-ready, language-agnostic code generation framework that treats software artifacts as projections of RDF knowledge graphs. Generate reproducible, multi-language code from semantic ontologies using template-based generation with SPARQL queries and AI-powered enhancements.

Why ggen?

Generate code faster, smarter, and more consistently:

  • ๐Ÿค– AI-Powered Generation - GPT-4o, Claude 3.5, and local Ollama models
  • ๐ŸŒ Language-Agnostic - Generate Rust, TypeScript, Python, Go from one source
  • ๐Ÿ”— Knowledge Graph-Driven - Embed semantic metadata with SPARQL queries
  • ๐ŸŽฏ Deterministic Output - Byte-identical, reproducible builds every time
  • โšก Production-Ready - 88/100 readiness score, comprehensive testing
  • ๐Ÿงช Hermetic Testing - Cleanroom framework for isolated, deterministic tests
  • ๐Ÿ” Post-Quantum Security - ML-DSA (Dilithium3) cryptographic signatures

โšก Quick Start (2 Minutes)

Installation

# Install via Homebrew (macOS/Linux)
brew tap seanchatmangpt/tap
brew install ggen

# Or install from source
git clone https://github.com/seanchatmangpt/ggen
cd ggen
cargo install --path cli

Your First Generation

# 1. Check your environment
ggen doctor

# 2. Generate a template-based project
ggen gen templates/rust-module.tmpl --vars name=my_module

# 3. Or use AI to generate an entire project
ggen ai project "REST API with authentication" --name my-api --rust

# 4. Search marketplace for packages
ggen search "rust web"

๐ŸŽ‰ That's it! You've generated your first ggen project.


๐ŸŽฏ Core Workflow

ggen follows a simple, powerful workflow for all projects:

# 1. Search & Discover - Find existing packages
ggen search "rust web service"
ggen categories

# 2. Install & Setup - Add packages to your project
ggen add io.ggen.rust.cli-subcommand
ggen add io.ggen.postgres.schema

# 3. Generate - Create code from templates
ggen gen rust-service.tmpl --vars name=auth_service
ggen ai project "User management API" --rust

# 4. Test & Validate - Ensure quality
cargo test
ggen doctor

# 5. Deploy - Ship to production
ggen github pages-status
cargo build --release

Key Commands:

Command Purpose Example
ggen search <query> Find packages ggen search "rust web"
ggen add <package> Install package ggen add io.ggen.rust.cli
ggen gen <template> Generate code ggen gen service.tmpl --vars name=api
ggen ai project <desc> AI scaffolding ggen ai project "REST API" --rust
ggen doctor Health check ggen doctor
ggen list Show templates ggen list

๐Ÿ“š See: Complete Workflow Guide | CLI Reference


โœจ Key Features

๐Ÿค– AI-Powered Generation

Generate templates, projects, and ontologies using advanced LLMs:

# Generate complete projects
ggen ai project "E-commerce API with Stripe" --name shop-api --rust

# Generate templates from descriptions
ggen ai generate -d "Database repository pattern" -o repo.tmpl

# Generate RDF ontologies
ggen ai graph -d "User management ontology" -o users.ttl

# Generate SPARQL queries
ggen ai sparql -d "Find all active users" -g schema.ttl

Supported Providers: OpenAI (GPT-4o), Anthropic (Claude 3.5), Ollama (local)

๐ŸŽฏ Deterministic & Reproducible

Generate byte-identical output every time:

---
determinism: 42  # Fixed RNG seed
---
pub fn random() -> u32 {
    {{ rand_int(0, 100) }}  # Always generates same value
}

๐Ÿ”— Knowledge Graph-Driven

Embed RDF and query with SPARQL:

---
rdf_inline:
  - "@prefix foaf: <http://xmlns.com/foaf/0.1/> ."
  - ":person foaf:name '{{name}}' ."
sparql:
  get_name: "SELECT ?name WHERE { :person foaf:name ?name }"
---
Hello, {{ sparql(query="get_name") }}!

๐Ÿ“ฆ Marketplace Integration

Reusable template packages (gpacks):

ggen search "rust web"      # Find packages
ggen add io.ggen.rust.axum  # Install package
ggen list                   # Show templates
ggen update                 # Update packages

๐Ÿงช Production-Ready Testing

Hermetic, deterministic test environments:

  • Cleanroom Framework - Isolated containers for testing
  • 23+ Integration Tests - Comprehensive CLI coverage
  • 90%+ Test Coverage - Critical paths validated
  • Zero .expect() - Production-grade error handling

๐Ÿ“š See: Production Readiness Report | Testing Guide

๐Ÿ“Š Comparison

Feature ggen Cookiecutter Yeoman Copier
RDF/SPARQL โœ… โŒ โŒ โŒ
AI Generation โœ… โŒ โŒ โŒ
Multi-Language โœ… โŒ โŒ โŒ
Deterministic โœ… โš ๏ธ โŒ โš ๏ธ
Language Rust Python JavaScript Python
Performance <3s Slower Slower Slower
Marketplace โœ… โœ… โœ… โŒ
Testing Framework โœ… โŒ โŒ โŒ

๐Ÿ“ Template Example

---
to: "src/{{name}}.rs"
vars:
  name: "example"
rdf_inline:
  - "@prefix ex: <http://example.org/> ."
  - "ex:{{name}} a ex:Module ."
sparql:
  get_type: "SELECT ?type WHERE { ex:{{name}} a ?type }"
determinism: 42
---
//! {{name}} module - Generated by ggen
//! Type from RDF: {{ sparql(query="get_type") }}

pub struct {{name | capitalize}} {
    name: String,
}

impl {{name | capitalize}} {
    pub fn new(name: impl Into<String>) -> Self {
        Self { name: name.into() }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_new() {
        let module = {{name | capitalize}}::new("test");
        assert_eq!(module.name, "test");
    }
}

Generate it:

ggen gen example.tmpl --vars name=my_module

๐Ÿ—๏ธ Architecture

High-Level:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ggen CLI   โ”‚โ”€โ”€โ”€โ”€โ”€โ–บโ”‚  ggen-core   โ”‚โ”€โ”€โ”€โ”€โ”€โ–บโ”‚   Output    โ”‚
โ”‚  (Commands) โ”‚      โ”‚ (Generation) โ”‚      โ”‚  (Code)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚   ggen-ai    โ”‚
                     โ”‚ (LLM Client) โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚ RDF + SPARQL โ”‚
                     โ”‚  (Knowledge) โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Modules:

  • cli/ - Command-line interface (Clap-based)
  • ggen-core/ - Template engine, RDF/SPARQL, marketplace
  • ggen-ai/ - AI providers (OpenAI, Anthropic, Ollama)
  • ggen-marketplace/ - Package management
  • utils/ - Shared utilities, configuration, logging

๐Ÿ“š See: Architecture Deep Dive

๐Ÿ“š Examples

Production-Ready Projects:

Quick Demos:

# Browse all examples
ls examples/

# Run screencast demo
./examples/screencast-demo.sh

# Test an example
cd examples/microservices-architecture && cargo build

๐Ÿ“š See: Examples Directory | Project Gallery

๐Ÿ› ๏ธ Development

Always use cargo make commands:

# Quick workflow
cargo make quick              # Format + test
cargo make dev                # Format + lint + test
cargo make ci                 # Full CI pipeline

# Testing
cargo make test               # All tests
cargo make test-coverage      # Coverage report
cargo make deterministic      # Reproducible tests

# Quality
cargo make fmt                # Format code
cargo make lint               # Clippy checks
cargo make audit              # Security scan

# AI features
cargo make ai-dev             # AI development
cargo make ai-demo            # Run AI demo

๐Ÿ“š See: CONTRIBUTING.md | Makefile Reference

๐Ÿ“– Documentation

Essential Guides:

Production:

Development:

โšก Performance

Build Times:

  • First build: ~3s (target โ‰ค15s) โœ…
  • Incremental: 2-3s (target โ‰ค2s) โœ…
  • RDF processing: <5s for 1k+ triples โœ…

Generation:

  • CLI scaffolding: <3s end-to-end โœ…
  • Memory usage: <100MB โœ…
  • Reproducible: 100% byte-identical โœ…

Testing:

  • Full suite: <60s โœ…
  • Test coverage: 90%+ โœ…
  • Deterministic: 100% reproducible โœ…

๐Ÿ’ฌ FAQ

Q: Do I need Rust installed? A: Yes. Install with brew install rust or see rustup.rs.

Q: Which AI providers are supported? A: OpenAI (GPT-4o), Anthropic (Claude 3.5), Ollama (local). Configure with ~/.config/ggen/ai-config.toml.

Q: Do I need to know RDF/SPARQL? A: No - basic generation works without RDF. Use RDF for advanced semantic features.

Q: How do I create custom templates? A: Templates use YAML frontmatter + Tera syntax. Run ggen ai generate -d "your idea" or see Template Creation Guide.

Q: Where do I get help? A: Run ggen doctor for diagnostics, ggen help-me for tips, or see Troubleshooting Guide.

More questions? Check GitHub Discussions or open an issue.


๐Ÿค Contributing

Contributions are welcome! Quick start:

  1. Fork and clone: git clone https://github.com/YOUR_USERNAME/ggen
  2. Verify setup: cargo make quick
  3. Make changes and test: cargo make ci
  4. Submit pull request

๐Ÿ“š See: CONTRIBUTING.md | Good First Issues | Development Guide


๐Ÿ“„ License

MIT License - see LICENSE for details.


๐Ÿ”— Links


Built with โค๏ธ using Rust, RDF, and SPARQL