ggen 4.0.0

ggen is a deterministic, language-agnostic code generation framework that treats software artifacts as projections of knowledge graphs.
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# Ggen Examples

This directory contains working examples demonstrating ggen's capabilities.

**Status**: All examples compile and run successfully (verified 2025-10-11)

## ๐Ÿš€ Quick Start

**Brand new to ggen?** Start here to get oriented:

### ๐Ÿฅ Step 1: Check Your Environment
```bash
# First time? Check if your environment is ready
ggen doctor

# โœ… Rust toolchain (rustc 1.90.0)
# โœ… Cargo (cargo 1.90.0)
# โœ… Git (git 2.39.0)
# โœ… Environment variables configured
# โœ… Templates directory exists
```

### ๐Ÿ“š Step 2: Get Personalized Help
```bash
# Get help adapted to your experience level
ggen help-me

# ๐Ÿ“š Your level: newcomer
# ๐Ÿš€ Welcome to ggen!
# Here are the essential commands to get started:
#   ggen doctor - Check if your environment is ready
#   ggen template list - See available templates
#   ggen help-me --tips - Get personalized tips
```

### ๐ŸŽฏ Step 3: Try Your First Example
**New to ggen?** Start with these comprehensive tutorials:

1. **[basic-template-generation/]basic-template-generation/** - Learn template fundamentals (15-30 min)
2. **[ai-template-creation/]ai-template-creation/** - AI-powered template creation (30-45 min)
3. **[complete-project-generation/]complete-project-generation/** - Generate full projects (45-60 min)

**Want ultra-fast deployment?** Check out the **[cleanroom/examples/](../cleanroom/examples/)** directory for <60 second concept-to-deploy workflows.

## ๐ŸŽฏ User-Friendly Features (NEW!)

### ๐Ÿฅ Environment Health Check
Before diving into examples, ensure your environment is ready:

```bash
ggen doctor
```

**What it checks**:
- โœ… Rust toolchain and Cargo
- โœ… Git installation
- โœ… Environment variables
- โœ… Templates directory
- โœ… Configuration files

**If something is missing**, ggen doctor provides platform-specific fix instructions!

### ๐Ÿ“š Progressive Help System
Get help that adapts to your experience level:

```bash
# General help (adapts based on your usage)
ggen help-me

# Get personalized tips
ggen help-me --tips

# Command-specific help
ggen help-me template
```

**Your help evolves as you use ggen more:**
- **Newcomer** (0-5 commands): Essential commands and quickstart
- **Intermediate** (6-20 commands): Common workflows and best practices
- **Advanced** (21-50 commands): Advanced features and optimization
- **Expert** (50+ commands): Power user tips and customization

### ๐Ÿ”ง Enhanced Error Messages
When something goes wrong, ggen now provides actionable help:

```bash
$ ggen template generate rust-servce
โŒ Error: Template 'rust-servce' not found

๐Ÿ“ Context: The specified template does not exist in the registry

๐Ÿ’ก Did you mean:
   โ€ข rust-service
   โ€ข rust-server
   โ€ข rust-svc

๐Ÿ”ง How to fix:
   1. Run 'ggen template list' to see available templates
   2. Use 'ggen template search rust' to find Rust templates

๐Ÿ“š Documentation: https://seanchatmangpt.github.io/ggen/templates
```

**Error messages now include:**
- Context explaining what went wrong
- "Did you mean?" suggestions for typos
- Step-by-step fix instructions
- Platform-specific commands (macOS/Linux/Windows)
- Links to relevant documentation

---

## ๐Ÿ“š Available Examples

### ๐ŸŽ“ Comprehensive Tutorial Examples (NEW!)

#### 1. **basic-template-generation/**
Complete tutorial for learning ggen template fundamentals.

**What You'll Learn**:
- Template anatomy (YAML frontmatter + Tera templating)
- Variable substitution and filters
- Conditional rendering and loops
- Generating production-quality Rust code

**Quick Start**:
```bash
# First, check your environment
ggen doctor

# Then run the tutorial
cd basic-template-generation
./run-example.sh        # Interactive tutorial
./run-example.sh show   # View all templates

# Get help if you need it
ggen help-me template
```

**Time**: 15-30 minutes
**Prerequisites**: Just ggen

---

#### 2. **ai-template-creation/**
AI-powered template creation using ggen's AI commands.

**What You'll Learn**:
- `ggen ai generate` - Create templates from descriptions
- `ggen ai validate` - Template validation
- Iterative improvement workflow
- Mock mode for cost-free testing

**Quick Start**:
```bash
cd ai-template-creation
./run-ai-workflow.sh    # Complete AI workflow demo
cat prompts.txt         # Example prompts library
```

**Time**: 30-45 minutes
**Prerequisites**: ggen (mock mode) or Ollama for real AI

---

#### 3. **complete-project-generation/**
Generate complete, production-ready Rust web services.

**What You'll Learn**:
- Multi-file project generation
- REST API with 6 endpoints
- Integration tests
- Complete build-test-deploy workflow

**Quick Start**:
```bash
cd complete-project-generation
./generate-project.sh validate    # Validate templates
./generate-project.sh generate    # Generate project
cd output/my-web-service && cargo run
```

**Time**: 45-60 minutes
**Prerequisites**: ggen, Rust toolchain

---

#### 4. **source-code-analysis/**
Analyze existing code and extract reusable templates.

**What You'll Learn**:
- `ggen ai from-source` - Pattern extraction
- Analyzing code to create templates
- Reverse engineering workflows
- Code regeneration with customization

**Quick Start**:
```bash
cd source-code-analysis
./analyze-and-generate.sh    # Complete analysis workflow
```

**Time**: 30-45 minutes
**Prerequisites**: ggen (mock mode works)

---

#### 5. **mcp-integration/**
Integrate ggen with Claude Desktop and Cline via MCP.

**What You'll Learn**:
- Model Context Protocol (MCP) integration
- 25+ MCP tools for conversational code generation
- Real AI assistant workflows
- Production integration patterns

**Quick Start**:
```bash
cd mcp-integration
./install-ggen-mcp.sh     # Install MCP server
./test-mcp-tools.sh       # Test integration
```

**Time**: 45-60 minutes
**Prerequisites**: ggen-mcp, Claude Desktop or Cline

---

#### 6. **mcp-rig-integration/** (NEW!)
Generate MCP + Rig AI agent projects with dynamic tool selection.

**What You'll Learn**:
- MCP Rust SDK integration with Rig framework
- Multi-provider LLM support (DeepSeek, Cohere, OpenAI)
- Dynamic tool discovery using RAG and embeddings
- Streaming chat with real-time tool calls
- Multi-transport MCP servers (stdio, SSE, streamable)

**Quick Start**:
```bash
cd mcp-rig-integration
./generate-project.sh my-agent    # Generate project
cd my-agent
# Configure API keys in config.toml
cargo run                          # Run AI agent
```

**Time**: 60-90 minutes
**Prerequisites**: Rust, ggen, MCP servers

**Features**:
- Vector-based dynamic tool selection
- Concurrent multi-server startup
- Beautiful CLI with colored streaming output
- Template-driven customization
- Production-ready architecture

---

#### 7. **Ultra-Fast Deployment** (NEW!) โšก
Deploy production services in <60 seconds using ggen + cleanroom synergy.

**What You'll Learn**:
- <60s concept-to-deployment workflow
- ggen marketplace โ†’ cleanroom testing โ†’ lifecycle deployment
- Hermetic test environments with testcontainers
- Production-grade error handling patterns
- Deployment validation and verification

**Quick Start**:
```bash
cd ../cleanroom/examples
./full_demo.sh                    # Complete ultra-fast demo
./quick_demo.sh                   # Quick 30s demo
cat quick_reference.sh            # Command reference
```

**Time**: 5-10 minutes for demo, 30-60 minutes for deep dive
**Prerequisites**: ggen, cleanroom (built from ../cleanroom)

**Features**:
- โšก <60s total deployment time
- ๐Ÿงช 100% tested with cleanroom
- ๐Ÿ”’ Production-safe (zero `.expect()` calls)
- ๐ŸŽฏ Deterministic and reproducible
- ๐Ÿ“ฆ Includes templates, tests, Docker, CI/CD

**Documentation**:
- [User Guide]../docs/ULTRA_FAST_DEPLOY.md - Getting started, examples, workflows
- [Technical Reference]../docs/ULTRA_FAST_REFERENCE.md - Architecture, API, performance
- [Cleanroom Examples]../cleanroom/examples/README.md - Hermetic testing

---

### Frontmatter CLI Examples

### Frontmatter CLI Examples

#### 1. **frontmatter-cli.rs**
Full-featured frontmatter template processor with RDF/SPARQL support.

**Usage**:
```bash
cargo run --example frontmatter-cli
```

**Features**:
- RDF ontology parsing
- SPARQL query execution
- Template variable extraction
- YAML frontmatter parsing

#### 2. **simple-frontmatter-cli.rs**
Minimal frontmatter processor for quick template generation.

**Usage**:
```bash
cargo run --example simple-frontmatter-cli
```

**Features**:
- Basic YAML frontmatter parsing
- Template rendering
- Variable substitution

#### 3. **standalone-frontmatter-cli.rs**
Self-contained frontmatter processor with no external dependencies.

**Usage**:
```bash
cargo run --example standalone-frontmatter-cli
```

**Features**:
- Zero-dependency parsing
- Embedded templates
- Minimal footprint

### GenAI Examples

#### 4. **genai_ollama_loop.rs**
Interactive chat loop with Ollama's qwen3-coder:30b model.

**Prerequisites**:
```bash
# 1. Install Ollama: https://ollama.ai
# 2. Start Ollama server
ollama serve

# 3. Pull the model
ollama pull qwen3-coder:30b
```

**Usage**:
```bash
cargo run --example genai_ollama_loop
```

**Features**:
- Interactive coding assistant
- Conversation history
- Token usage tracking
- Commands: 'clear', 'quit', 'exit'

#### 5. **genai_multi_provider_compare.rs**
Compare responses from multiple LLM providers for the same coding question.

**Prerequisites**:
```bash
# Optional - set API keys for providers you want to test
export OPENAI_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"
export GEMINI_API_KEY="your-key"

# Ollama is used by default (no API key needed)
```

**Usage**:
```bash
cargo run --example genai_multi_provider_compare
```

**Features**:
- Multi-provider comparison
- Performance benchmarking
- Token usage comparison
- Works with: Ollama, OpenAI, Anthropic, Google Gemini

### Utility Examples

#### 6. **json-to-yaml-frontmatter.rs**
Convert JSON frontmatter to YAML format.

**Usage**:
```bash
cargo run --example json-to-yaml-frontmatter
```

**Features**:
- JSON to YAML conversion
- Frontmatter generation
- RDF/SPARQL support

## Workspace Examples

The following examples are full workspace members with their own Cargo.toml:

- **examples/frontmatter-cli/** - Production-ready frontmatter CLI
- **examples/natural-market-search/** - Natural language market search
- **examples/ai-template-project/** - AI-powered template generation

## Running Examples

```bash
# Run specific example
cargo run --example <example-name>

# Build all examples
cargo build --examples

# List available examples
cargo run --example
```

## Requirements

- Rust 1.70 or later
- For GenAI examples: genai = "0.4"
- For Ollama examples: Ollama server running locally

## Troubleshooting

### ๐Ÿฅ First Step: Run Doctor
**Always start troubleshooting with:**
```bash
ggen doctor
```

This checks your environment and provides platform-specific fix instructions for any issues.

### ๐Ÿ“š Get Contextual Help
```bash
# Get tips based on your usage patterns
ggen help-me --tips

# Get help for a specific command
ggen help-me <command>
```

### Enhanced Error Messages
Ggen now provides detailed error messages with:
- Context explaining what went wrong
- "Did you mean?" suggestions for typos
- Step-by-step fix instructions
- Platform-specific commands

**Example of a helpful error:**
```bash
$ ggen template generate non-existent
โŒ Error: Template 'non-existent' not found

๐Ÿ’ก Did you mean:
   โ€ข rust-cli-template
   โ€ข basic-template

๐Ÿ”ง How to fix:
   1. Run 'ggen template list' to see available templates
   2. Use 'ggen template search <query>' to find templates
```

### Ollama Examples

If genai examples fail:
1. **Run `ggen doctor`** to check prerequisites
2. Check Ollama is running: `curl http://localhost:11434/api/tags`
3. Verify model is installed: `ollama list`
4. Pull model if needed: `ollama pull qwen3-coder:30b`

### Frontmatter Examples

If frontmatter examples fail:
1. **Run `ggen doctor`** to verify environment
2. Check template file exists
3. Verify YAML syntax is valid
4. Ensure RDF/SPARQL syntax is correct

## Contributing

When adding new examples:
1. Add file to `examples/` directory
2. Test compilation: `cargo build --example <name>`
3. Add usage documentation to this README
4. Ensure example is self-contained and working

## ๐Ÿ“Š Example Comparison Matrix

| Example | Complexity | Time | Prerequisites | What You Learn |
|---------|-----------|------|---------------|----------------|
| **basic-template-generation** | โญ Beginner | 15-30m | ggen only | Template fundamentals |
| **ai-template-creation** | โญโญ Intermediate | 30-45m | ggen (mock) | AI-powered generation |
| **source-code-analysis** | โญโญ Intermediate | 30-45m | ggen (mock) | Pattern extraction |
| **complete-project-generation** | โญโญโญ Advanced | 45-60m | ggen + Rust | Full project generation |
| **mcp-integration** | โญโญโญ Advanced | 45-60m | ggen-mcp + AI | MCP protocol integration |
| **mcp-rig-integration** | โญโญโญโญ Expert | 60-90m | Rust + MCP + Rig | AI agents with dynamic tools |
| **ultra-fast-deployment** โšก | โญโญโญ Advanced | 5-60m | ggen + cleanroom | <60s production deployment |

## ๐ŸŽฏ Learning Paths

### Path 1: Template Author
1. basic-template-generation (fundamentals)
2. ai-template-creation (AI assistance)
3. source-code-analysis (pattern extraction)

### Path 2: Project Generator
1. basic-template-generation (fundamentals)
2. complete-project-generation (full projects)
3. ai-template-creation (automation)

### Path 3: Integration Developer
1. basic-template-generation (fundamentals)
2. mcp-integration (MCP protocol)
3. complete-project-generation (real workflows)

### Path 4: DevOps Engineer โšก (NEW!)
1. basic-template-generation (fundamentals)
2. complete-project-generation (full projects)
3. **ultra-fast-deployment** (<60s production deploys)

**Path 4 is ideal for:**
- Teams needing rapid deployment cycles
- Developers wanting production-ready templates
- Organizations requiring hermetic testing
- Projects needing <60s concept-to-deploy workflows

## ๐Ÿ“– Documentation

Each comprehensive example includes:
- โœ… Complete README with step-by-step instructions
- โœ… Runnable scripts for hands-on learning
- โœ… Expected outputs and success criteria
- โœ… Troubleshooting guides
- โœ… Best practices and tips

## Maintenance

Last audit: 2025-01-13
- Total examples: 6 standalone + 3 workspace + 7 comprehensive tutorials = 16 total
- Compilation status: 100% passing
- New comprehensive examples: 7 (60+ files, ~15,000 lines)
- Latest additions:
  - MCP + Rig integration example (expert level)
  - Ultra-fast deployment workflow (<60s concept-to-deploy)
- All scripts executable and tested
- Dependencies: All up-to-date
- New documentation:
  - [ULTRA_FAST_DEPLOY.md](../docs/ULTRA_FAST_DEPLOY.md) - User guide
  - [ULTRA_FAST_REFERENCE.md](../docs/ULTRA_FAST_REFERENCE.md) - Technical reference