ggen 1.2.0

ggen is a deterministic, language-agnostic code generation framework that treats software artifacts as projections of knowledge graphs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [ggen - Graph-Aware Code Generation Framework]#ggen---graph-aware-code-generation-framework
  - [Why ggen?]#why-ggen
  - [Quick Start (2 Minutes)]#quick-start-2-minutes
  - [Core Workflow]#core-workflow
  - [Key Features]#key-features
  - [Architecture]#architecture
  - [Examples]#examples
  - [Documentation]#documentation
  - [Contributing]#contributing
  - [License]#license

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# ggen - Graph-Aware Code Generation Framework

[![GitHub Pages](https://img.shields.io/badge/docs-live-success)](https://seanchatmangpt.github.io/ggen/)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Crates.io](https://img.shields.io/crates/v/ggen)](https://crates.io/crates/ggen)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](#)
[![Test Coverage](https://img.shields.io/badge/coverage-90%25-brightgreen.svg)](#performance-slos)
[![Security Audit](https://img.shields.io/badge/security-post--quantum-blue.svg)](#features)
[![Docs Status](https://img.shields.io/badge/docs-comprehensive-success.svg)](https://seanchatmangpt.github.io/ggen/)

**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

```bash
# 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

```bash
# 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:

```bash
# 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]https://seanchatmangpt.github.io/ggen/workflow | [CLI Reference]https://seanchatmangpt.github.io/ggen/cli

---

## โœจ Key Features

### ๐Ÿค– AI-Powered Generation
Generate templates, projects, and ontologies using advanced LLMs:

```bash
# 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:

```yaml
---
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:

```yaml
---
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):

```bash
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]docs/v1-production-readiness.md | [Testing Guide]docs/testing/README.md

## ๐Ÿ“Š 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

```yaml
---
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:**
```bash
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](https://seanchatmangpt.github.io/ggen/architecture)

## ๐Ÿ“š Examples

**Production-Ready Projects:**

- **[Microservices Architecture]examples/microservices-architecture/** - Full stack with auth, users, payments
- **[AI Code Generation]examples/ai-code-generation/** - Showcase of all AI features
- **[Advanced Rust Project]examples/advanced-rust-project/** - Production Rust service with RDF
- **[Full Stack App]examples/full-stack-app/** - Complete web application

**Quick Demos:**

```bash
# Browse all examples
ls examples/

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

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

**๐Ÿ“š See:** [Examples Directory]examples/ | [Project Gallery]https://seanchatmangpt.github.io/ggen/examples

## ๐Ÿ› ๏ธ Development

**Always use `cargo make` commands:**

```bash
# 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]CONTRIBUTING.md | [Makefile Reference]MAKEFILE.md

## ๐Ÿ“– Documentation

**Essential Guides:**
- ๐Ÿ“š **[Full Documentation]https://seanchatmangpt.github.io/ggen/** - Complete guides and API reference
- ๐Ÿค– **[AI Guide]docs/ai-guide.md** - AI-powered generation
- ๐Ÿ” **[CLI Reference]https://seanchatmangpt.github.io/ggen/cli** - All commands explained
- ๐Ÿ—๏ธ **[Template Creation]https://seanchatmangpt.github.io/ggen/templates/creating** - Build custom templates
- ๐Ÿ”— **[RDF & SPARQL]https://seanchatmangpt.github.io/ggen/rdf** - Knowledge graph integration

**Production:**
- โœ… **[Production Readiness]docs/v1-production-readiness.md** - Validation report (88/100)
- ๐Ÿงช **[Testing Guide]docs/testing/README.md** - Cleanroom testing framework
- ๐Ÿš€ **[Deployment]docs/DEPLOYMENT.md** - GitHub Pages setup

**Development:**
- ๐Ÿค **[Contributing]CONTRIBUTING.md** - How to contribute
- ๐Ÿ› ๏ธ **[Makefile Reference]MAKEFILE.md** - All cargo-make tasks
- ๐Ÿ“ **[CLAUDE.md]CLAUDE.md** - AI development guidelines

## โšก 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](https://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](https://seanchatmangpt.github.io/ggen/templates/creating).

**Q: Where do I get help?**
A: Run `ggen doctor` for diagnostics, `ggen help-me` for tips, or see [Troubleshooting Guide](https://seanchatmangpt.github.io/ggen/troubleshooting).

**More questions?** Check [GitHub Discussions](https://github.com/seanchatmangpt/ggen/discussions) or open an [issue](https://github.com/seanchatmangpt/ggen/issues).

---

## ๐Ÿค 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]CONTRIBUTING.md | [Good First Issues]https://github.com/seanchatmangpt/ggen/labels/good%20first%20issue | [Development Guide]CLAUDE.md

---

## ๐Ÿ“„ License

MIT License - see [LICENSE](LICENSE) for details.

---

## ๐Ÿ”— Links

- **GitHub:** https://github.com/seanchatmangpt/ggen
- **Documentation:** https://seanchatmangpt.github.io/ggen/
- **Crates.io:** https://crates.io/crates/ggen
- **Homebrew:** `brew tap seanchatmangpt/tap && brew install ggen`

---

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