2026-01-11 22:35:49 +00:00
..
2026-01-11 22:35:49 +00:00

Mode A: Cargo.toml Introspection

This example shows automatic provisioning generation from a Cargo.toml file.

What Gets Detected

From the included Cargo.toml, the generator detects:

Project Type

  • WebService - detected from axum dependency

Domain Features

  • http_server - from axum dependency
    • Fields: bind_address, timeout_seconds
  • authentication - from jsonwebtoken dependency
    • Fields: jwt_secret (sensitive)
  • caching - from redis dependency
    • Fields: cache_enabled, cache_ttl_seconds

Infrastructure

  • Database: PostgreSQL (from sqlx with postgres feature)
    • Fields: host, port, username, password, database name
  • SSH: Not required (no openssh-keys or ssh2)
  • Monitoring: Prometheus detected (from prometheus dependency)
  • Cloud Providers: Default to LXD

Running the Example

Step 1: Analyze the Cargo.toml

typedialog-provisioning-gen cargo \
  --input examples/11-provisioning-generation/mode-a-cargo/Cargo.toml \
  --output /tmp/my-provisioning
```text

### Step 2: Inspect Generated Structure
```bash
tree /tmp/my-provisioning
```text

Expected output:
```text
/tmp/my-provisioning/
├── config.ncl                    # Master configuration
├── constraints.toml              # Validation bounds
├── schemas/                      # Domain types
│   ├── http_server.ncl
│   ├── authentication.ncl
│   ├── caching.ncl
│   ├── database.ncl
│   ├── environment.ncl
│   └── ...
├── validators/                   # Validation functions
│   ├── http_server.ncl
│   ├── authentication.ncl
│   ├── caching.ncl
│   ├── common.ncl
│   └── ...
├── defaults/                     # Default values
│   ├── http_server.ncl
│   ├── authentication.ncl
│   ├── caching.ncl
│   ├── database.ncl
│   └── ...
├── fragments/                    # TypeDialog forms
│   ├── http_server-section.toml
│   ├── authentication-section.toml
│   ├── caching-section.toml
│   ├── database-mysql-section.toml
│   └── ...
└── scripts/                      # Orchestration
    ├── config.sh
    ├── config.nu
    ├── json-to-nickel.sh
    ├── validate-nickel.sh
    └── ...
```text

### Step 3: Validate Generated Configuration
```bash
cd /tmp/my-provisioning
./scripts/validate-nickel.sh
```text

### Step 4: Use in TypeDialog Forms
```bash
# Display HTTP server configuration form
typedialog fragments/http_server-section.toml --backend cli

# Display database configuration form
typedialog fragments/database-mysql-section.toml --backend cli
```text

## Dependency → Feature Mapping

The generator uses these heuristics:

| Dependency | Feature | Fields |
|---|---|---|
| axum, actix-web, rocket | http_server | bind_address, timeout_seconds |
| jsonwebtoken, oauth2 | authentication | jwt_secret |
| redis, memcache | caching | cache_enabled, cache_ttl_seconds |
| sqlx, mysql, postgres | database | host, port, username, password |
| prometheus | monitoring | scrape_interval, retention_time |
| grafana | dashboard | admin_password |
| openssh-keys, ssh2 | ssh | private_key_path, username, port |

## Customization

To override the detection, use Mode B (config file) with custom features:

1. Generate initial config from Cargo.toml
2. Edit the config file to add/modify features
3. Re-generate with Mode B

See `../mode-b-config/` for the config file format.

## What This Demonstrates

✅ Automatic feature detection from dependencies
✅ Type inference (WebService detected from web frameworks)
✅ Infrastructure requirements (database, monitoring setup)
✅ Complete 7-layer validation stack generation
✅ Integration with TypeDialog forms
✅ Reusable template library (generic validators, schemas, etc.)

## Next Steps

1. **Modify Configuration**: Edit generated `config.ncl` to customize
2. **Add Custom Fields**: Create domain-specific fields in generated fragments
3. **Deploy**: Use `config.sh` or `config.nu` scripts for orchestration
4. **Integrate**: Import generated schemas in your application configuration