OpenCrates
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
From Source
Using Docker
Configuration
- Set up your OpenAI API key:
- Configure OpenCrates (optional):
- Verify installation:
Usage
Interactive Mode
This launches the interactive wizard that guides you through creating a new crate.
Command Line Mode
# Create a CLI tool
# Create with specific options
# Create interactively
Web Search Integration
# Search for Rust patterns and examples
# Search with custom limit
Testing and Quality Assurance
# Run the built-in test suite
# Run specific test scenarios
# List available 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
- Stage Orchestrator: Manages the crate generation pipeline
- Providers: External service integrations (OpenAI, web search)
- Templates: Extensible template system for different project types
- Utilities: Cross-cutting concerns (config, caching, metrics)
Configuration
OpenCrates can be configured through:
- Environment Variables:
- Configuration File (
~/.config/opencrates/config.toml):
[]
= "your-key"
= "gpt-4"
= 4000
= 0.7
[]
= true
= 3600
= "redis://localhost:6379"
[]
= true
= 10
[]
= "~/.config/opencrates/templates"
[]
= true
= 9090
- Interactive Configuration:
Docker Support
Using Pre-built Images
# Run with environment variables
# Run interactively
Building from Source
# Build the image
# Run with Docker Compose
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
# Run specific test suites
# Run benchmarks
# Run the comprehensive test suite
Test Coverage
# Install tarpaulin
# Generate coverage report
Performance Testing
# Run benchmarks
# Profile with flamegraph
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:
Distributed Tracing
OpenCrates supports distributed tracing with Jaeger:
# Start Jaeger
# Configure OpenCrates
API Integration
FastAPI Web Interface
OpenCrates includes a FastAPI web interface:
# Start the web server
# API endpoints
OpenAI Agents SDK Integration
use CrateAssistant;
async
Development
Building from Source
# Install dependencies
# Run in development mode
# Run with all features
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run the test suite:
./test_all.sh - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Development Tools
# Install development tools
# Watch for changes
# Security audit
# License and dependency checking
Examples
CLI Tool Example
Web API Example
Library Example
Troubleshooting
Common Issues
- OpenAI API Key Issues:
# Verify your API key
# Test API connectivity
- Build Issues:
# Clean and rebuild
# Update dependencies
- Docker Issues:
# Check Docker daemon
# Rebuild image
Debug Mode
# Enable debug logging
RUST_LOG=debug
# Enable trace logging
RUST_LOG=trace
Performance Issues
# Profile the application
# Check system resources
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Support
- Documentation: https://docs.rs/opencrates
- Issues: GitHub Issues
- Repository: GitHub Repository
Author
Nik Jois - nik@nikjois.com
For questions, suggestions, or contributions, please open an issue on GitHub or contact the author directly.