# Mode C: Interactive Wizard

This example demonstrates the interactive provisioning generator wizard with AI-powered suggestions.

## Overview

Mode C guides you through a conversational process to build your provisioning configuration:

1. **Project Details**: Name and type (WebService, CliTool, Microservice, Library)
2. **Infrastructure**: Database, SSH, monitoring, cloud providers
3. **Domain Features**: Application-specific capabilities
4. **Field Configuration**: Details for each feature
5. **Generation**: Creates complete provisioning structure

## Running the Wizard

```bash
# Interactive wizard with project name
typedialog-provisioning-gen wizard --project my-service

# Or use default name
typedialog-provisioning-gen wizard
```text

## Interactive Flow

### Step 1: Project Type Selection
```text
What type of project are you building?

1) WebService    - REST APIs, web servers
2) Microservice  - Distributed services with event streaming
3) CliTool       - Command-line utilities
4) Library       - Reusable Rust library
5) Other

Select (1-5):
```text

### Step 2: Infrastructure Requirements
```text
Infrastructure Configuration

Enable SSH access? (y/n): y
  → SSH access enabled for deployments

Which databases do you need?
1) PostgreSQL
2) MySQL
3) SQLite
4) None
5) Multiple databases

Select (1-5): 1
  → PostgreSQL selected

Enable monitoring? (y/n): y
  Which monitoring stack?
  1) Prometheus
  2) Grafana
  3) Both
  4) None

  Select (1-3): 3
  → Prometheus + Grafana enabled

Cloud deployment target?
1) LXD (local containers)
2) AWS
3) GCP
4) Multiple

Select (1-4): 2
  → AWS selected
```text

### Step 3: Domain Features
```text
Domain Features

The wizard suggests features based on your project type.

Suggested features:
✓ http_server (HTTP REST API)
✓ authentication (User authentication)
□ caching (Redis caching)
□ event_streaming (Message queue)
□ file_upload (File handling)

Select features to include:
[✓] http_server
[✓] authentication
[□] caching
[✓] event_streaming
[ ] file_upload

Confirm? (y/n): y
```text

### Step 4: Feature Configuration
```text
Configure http_server

1) Bind Address (default: 0.0.0.0:8080)
2) Request Timeout (default: 30 seconds)
3) Rate Limit (default: 100 req/sec)
4) Done

Select field to configure (1-4):
```text

The wizard guides you through each feature's fields with:
- Helpful descriptions
- Validation rules
- Default values
- Examples

### Step 5: Review and Generate
```text
Summary

Project:   my-service
Type:      WebService
Features:  http_server, authentication, caching
Database:  PostgreSQL
Monitoring: Prometheus, Grafana

Generate to: ./provisioning

Continue? (y/n): y

Generating...
✓ Constraints
✓ Schemas
✓ Validators
✓ Defaults
✓ Fragments
✓ Scripts

Done! Generated to ./provisioning
```text

## AI-Powered Suggestions

When Mode C integrates with typedialog-ai, it provides:

### 1. RAG-Based Feature Suggestions
The wizard retrieves similar project examples:

```text
Projects similar to "WebService" in your domain:

1. E-commerce platform
   - Features: product_catalog, shopping_cart, payment_gateway
   - Database: PostgreSQL
   - Monitoring: Prometheus + Grafana

2. Content delivery service
   - Features: media_upload, streaming, analytics
   - Database: PostgreSQL
   - Caching: Redis

Suggest these features? (y/n):
```text

### 2. Field Generation Assistance
LLM analyzes domain features and suggests fields:

```text
Configure http_server feature

Based on similar services, recommended fields:
- bind_address (Type: Text)
- max_connections (Type: Number)
- keepalive_timeout (Type: Number)
- compression_enabled (Type: Confirm)

Add recommended fields? (y/n):
```text

### 3. Constraint Learning
LLM suggests validation bounds from patterns:

```text
For max_connections field:

Learned constraints from similar services:
- Min: 1
- Max: 100000
- Typical: 1000

Apply? (y/n):
```text

## Typical Workflow Examples

### Example 1: Simple Web Service
```bash
typedialog-provisioning-gen wizard --project api-service

# Selections
# - WebService
# - PostgreSQL
# - Prometheus monitoring
# - Features: http_server, authentication
```text

Generated structure optimized for REST APIs with user management.

### Example 2: Microservice Platform
```bash
typedialog-provisioning-gen wizard --project order-service

# Selections
# - Microservice
# - PostgreSQL + Redis
# - Multiple cloud providers (AWS + GCP)
# - Features: http_server, authentication, event_streaming, caching
```text

Generated for distributed event-driven architecture.

### Example 3: CLI Tool
```bash
typedialog-provisioning-gen wizard --project deployment-tool

# Selections
# - CliTool
# - No database
# - SSH enabled
# - Features: configuration_management, deployment
```text

Generated for infrastructure automation.

## Customizing the Wizard

The wizard can be extended with:

1. **Custom feature library** (in typedialog-ai):
   - Add project types
   - Define feature templates
   - Set default constraints

2. **Custom LLM integration**:
   - Use your own LLM provider
   - Custom prompt engineering
   - Domain-specific knowledge base

## Fallback Mode

If typedialog-ai is not available, the wizard uses sensible defaults:

```rust
// Minimal wizard without AI
fn simple_wizard() {
    let name = prompt("Project name? ", "my-project");
    let project_type = select(
        "Project type?",
        vec!["WebService", "CliTool", "Microservice", "Library"]
    )?;

    let spec = ProjectSpec {
        name,
        project_type,
        infrastructure: InfrastructureSpec::default(),
        domain_features: vec![DomainFeature::new("basic_config")],
        constraints: vec![],
    };
    Ok(spec)
}
```text

This ensures the wizard works standalone without dependencies.

## Integration with typedialog-ai

For full AI capabilities:

1. Start typedialog-ai service:
   ```bash
   typedialog-ai serve --port 3000
   ```

2. Configure in .env:
   ```bash
   TYPEDIALOG_AI_URL=http://localhost:3000
   LLM_API_KEY=sk-...
   ```

3. Run wizard:
   ```bash
   typedialog-provisioning-gen wizard --project my-service
   ```

The wizard automatically uses AI for:
- Feature suggestions
- Constraint learning
- Field recommendations
- Example retrieval

## What This Demonstrates

✅ Conversational configuration
✅ AI-powered feature suggestions
✅ RAG-based example retrieval
✅ Interactive field configuration
✅ Sensible defaults
✅ Validation and constraints
✅ Graceful fallback without AI
✅ Complete 7-layer generation

## Troubleshooting

### "typedialog-ai not available"
The wizard falls back to basic mode. Features:
- Manual feature selection
- Default field configurations
- Standard constraints

To use full AI:
1. Install typedialog-ai: `cargo build -p typedialog-ai`
2. Start service: `typedialog-ai serve`
3. Run wizard: `typedialog-provisioning-gen wizard`

### "Generation failed"
Check:
1. Output directory is writable
2. Templates are installed correctly
3. Feature names don't contain special characters
4. Run with `--dry-run` first to validate

### "Fields missing after selection"
Some features are added/modified during wizard. Use Mode B to customize:
1. Run wizard: generates initial config
2. Export to TOML: inspect generated structure
3. Modify with Mode B: adjust features and fields
4. Regenerate: final structure

## Next Steps

1. **Run the Wizard**: `typedialog-provisioning-gen wizard --project my-service`
2. **Inspect Output**: Check generated provisioning/ structure
3. **Test Forms**: Run TypeDialog with fragments
4. **Deploy**: Use scripts for orchestration
5. **Iterate**: Modify and regenerate as needed

For detailed customization, see Mode B (Config File) examples.
