opencrates 0.1.0

AI-powered Rust crate generator with enterprise-grade observability and comprehensive testing automation
Documentation

OpenCrates

Build Status Crates.io Documentation License: MIT OR Apache-2.0

OpenCrates is a powerful AI-driven Rust crate generator that leverages OpenAI's latest models to create production-ready Rust projects with comprehensive testing, documentation, and enterprise-grade observability features.

Features

Core Capabilities

  • AI-Powered Generation: Uses GPT-4, GPT-4 Turbo, and other OpenAI models
  • Web Search Integration: Enhanced context through real-time web search
  • Interactive Wizard: Step-by-step crate creation process
  • Comprehensive Testing: Automated unit, integration, and benchmark tests
  • Documentation: Auto-generated docs with examples and API references
  • Containerization: Docker and Docker Compose support
  • Template System: Extensible template engine for different project types

Enterprise Features

  • Observability: Prometheus metrics, distributed tracing, health checks
  • Security: Built-in security scanning and vulnerability detection
  • Performance: Benchmarking and performance regression detection
  • Web API: FastAPI integration for web-based interactions
  • Caching: Multi-layer caching with Redis support
  • CI/CD: GitHub Actions workflows and automated deployment

Supported Project Types

  • CLI Tools and Applications
  • Libraries and APIs
  • Web Services (Axum, Warp, Actix)
  • Async Libraries
  • Data Processing Pipelines
  • Game Development
  • Embedded Systems
  • Custom Templates

Quick Start

Prerequisites

  • Rust 1.70.0 or later
  • OpenAI API Key (required for AI features)
  • Docker (optional, for containerization)
  • Redis (optional, for caching)

Installation

From Crates.io

cargo install opencrates

From Source

git clone https://github.com/nikjois/opencrates.git
cd opencrates
cargo install --path .

Using Docker

docker pull nikjois/opencrates:latest
docker run -it --rm nikjois/opencrates:latest --help

Configuration

  1. Set up your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"
  1. Configure OpenCrates (optional):
opencrates config
  1. Verify installation:
opencrates --help

Usage

Interactive Mode

opencrates

This launches the interactive wizard that guides you through creating a new crate.

Command Line Mode

# Create a CLI tool
opencrates create "A command-line tool for managing Docker containers"

# Create with specific options
opencrates create "Web API for user management" \
  --template web-api \
  --features "postgres,redis,metrics" \
  --model gpt-4 \
  --search-web

# Create interactively
opencrates create --interactive

Web Search Integration

# Search for Rust patterns and examples
opencrates search "async Rust patterns with tokio"

# Search with custom limit
opencrates search "Rust web frameworks comparison" --limit 20

Testing and Quality Assurance

# Run the built-in test suite
opencrates test

# Run specific test scenarios
opencrates test --scenario basic
opencrates test --all

# List available templates
opencrates templates

Architecture

OpenCrates is built with a modular architecture:

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   CLI Interface │    │   Web Interface │    │   API Interface │
└─────────┬───────┘    └─────────┬───────┘    └─────────┬───────┘
          │                      │                      │
          └──────────────────────┼──────────────────────┘
                                 │
                    ┌─────────────▼─────────────┐
                    │      Core Engine          │
                    │  ┌─────────────────────┐  │
                    │  │  Stage Orchestrator │  │
                    │  └─────────────────────┘  │
                    └─────────────┬─────────────┘
                                  │
        ┌─────────────────────────┼─────────────────────────┐
        │                         │                         │
┌───────▼────────┐    ┌───────────▼──────────┐    ┌────────▼────────┐
│   Providers    │    │      Utilities       │    │    Templates    │
│                │    │                      │    │                 │
│ • OpenAI       │    │ • Config Management  │    │ • CLI Templates │
│ • Web Search   │    │ • Caching           │    │ • Web Templates │
│ • Templates    │    │ • Metrics           │    │ • Lib Templates │
│                │    │ • Health Checks     │    │ • Custom Types  │
└────────────────┘    │ • Error Handling    │    └─────────────────┘
                      │ • FastAPI Integration│
                      └─────────────────────┘

Core Components

  1. Stage Orchestrator: Manages the crate generation pipeline
  2. Providers: External service integrations (OpenAI, web search)
  3. Templates: Extensible template system for different project types
  4. Utilities: Cross-cutting concerns (config, caching, metrics)

Configuration

OpenCrates can be configured through:

  1. Environment Variables:
export OPENAI_API_KEY="your-key"
export OPENCRATES_MODEL="gpt-4"
export OPENCRATES_CACHE_TTL="3600"
export REDIS_URL="redis://localhost:6379"
  1. Configuration File (~/.config/opencrates/config.toml):
[openai]
api_key = "your-key"
default_model = "gpt-4"
max_tokens = 4000
temperature = 0.7

[cache]
enabled = true
ttl = 3600
redis_url = "redis://localhost:6379"

[web_search]
enabled = true
max_results = 10

[templates]
custom_path = "~/.config/opencrates/templates"

[metrics]
enabled = true
prometheus_port = 9090
  1. Interactive Configuration:
opencrates config

Docker Support

Using Pre-built Images

# Run with environment variables
docker run -e OPENAI_API_KEY="your-key" nikjois/opencrates:latest create "my awesome crate"

# Run interactively
docker run -it -e OPENAI_API_KEY="your-key" nikjois/opencrates:latest

Building from Source

# Build the image
docker build -t opencrates:local .

# Run with Docker Compose
docker-compose up -d

Docker Compose Setup

version: '3.8'
services:
  opencrates:
    build: .
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - REDIS_URL=redis://redis:6379
    depends_on:
      - redis
    ports:
      - "8000:8000"
      - "9090:9090"
  
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
  
  prometheus:
    image: prom/prometheus:latest
    ports:
      - "9091:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml

Testing

Running Tests

# Run all tests
cargo test

# Run specific test suites
cargo test --lib                    # Unit tests
cargo test --test integration       # Integration tests
cargo test --doc                    # Documentation tests

# Run benchmarks
cargo bench

# Run the comprehensive test suite
./test_all.sh

Test Coverage

# Install tarpaulin
cargo install cargo-tarpaulin

# Generate coverage report
cargo tarpaulin --out Html

Performance Testing

# Run benchmarks
cargo bench

# Profile with flamegraph
cargo install flamegraph
cargo flamegraph --bin opencrates -- create "test crate"

Monitoring and Observability

Metrics

OpenCrates exposes Prometheus metrics on port 9090:

  • Request metrics: HTTP request duration, count, errors
  • Generation metrics: Crate generation time, success rate
  • Cache metrics: Hit rate, miss rate, eviction count
  • Health metrics: Component health status

Health Checks

Health check endpoint available at /health:

curl http://localhost:8000/health

Distributed Tracing

OpenCrates supports distributed tracing with Jaeger:

# Start Jaeger
docker run -d --name jaeger \
  -p 16686:16686 \
  -p 14268:14268 \
  jaegertracing/all-in-one:latest

# Configure OpenCrates
export JAEGER_ENDPOINT="http://localhost:14268/api/traces"

API Integration

FastAPI Web Interface

OpenCrates includes a FastAPI web interface:

# Start the web server
opencrates serve --port 8000

# API endpoints
curl -X POST http://localhost:8000/api/v1/generate \
  -H "Content-Type: application/json" \
  -d '{"description": "CLI tool for file management", "template": "cli"}'

OpenAI Agents SDK Integration

use opencrates::agents::CrateAssistant;

#[tokio::main]
async fn main() -> Result<()> {
    let assistant = CrateAssistant::new("your-api-key").await?;
    
    let result = assistant.generate_crate(
        "A web scraper for e-commerce sites",
        GenerationOptions::default()
    ).await?;
    
    println!("Generated crate: {}", result.name);
    Ok(())
}

Development

Building from Source

git clone https://github.com/nikjois/opencrates.git
cd opencrates

# Install dependencies
cargo build

# Run in development mode
cargo run -- --help

# Run with all features
cargo run --all-features -- create "test crate"

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run the test suite: ./test_all.sh
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Development Tools

# Install development tools
cargo install cargo-watch cargo-audit cargo-deny

# Watch for changes
cargo watch -x check -x test

# Security audit
cargo audit

# License and dependency checking
cargo deny check

Examples

CLI Tool Example

opencrates create "A CLI tool for managing Kubernetes deployments" \
  --template cli \
  --features "clap,serde,tokio" \
  --model gpt-4

Web API Example

opencrates create "REST API for a blog platform" \
  --template web-api \
  --features "axum,sqlx,redis" \
  --search-web

Library Example

opencrates create "A high-performance JSON parser" \
  --template library \
  --features "serde,benchmarks" \
  --no-docs false

Troubleshooting

Common Issues

  1. OpenAI API Key Issues:
# Verify your API key
echo $OPENAI_API_KEY

# Test API connectivity
curl -H "Authorization: Bearer $OPENAI_API_KEY" \
  https://api.openai.com/v1/models
  1. Build Issues:
# Clean and rebuild
cargo clean
cargo build

# Update dependencies
cargo update
  1. Docker Issues:
# Check Docker daemon
docker info

# Rebuild image
docker build --no-cache -t opencrates:local .

Debug Mode

# Enable debug logging
RUST_LOG=debug opencrates create "test crate"

# Enable trace logging
RUST_LOG=trace opencrates create "test crate"

Performance Issues

# Profile the application
cargo install flamegraph
cargo flamegraph --bin opencrates -- create "test crate"

# Check system resources
htop

License

This project is licensed under either of

at your option.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Support

Author

Nik Jois - nik@nikjois.com

For questions, suggestions, or contributions, please open an issue on GitHub or contact the author directly.