Download the PHP package rnr1721/codecraft without Composer
On this page you can find all versions of the php package rnr1721/codecraft. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rnr1721/codecraft
More information about rnr1721/codecraft
Files in rnr1721/codecraft
Package codecraft
Short Description Universal code generation and manipulation library for PHP, JavaScript, CSS, JSON and more. Framework-agnostic with Laravel integration.
License MIT
Homepage https://github.com/rnr1721/codecraft
Informations about the package codecraft
CodeCraft
Universal code generation and manipulation library for modern development
CodeCraft is an experimental, AI-friendly library that provides a unified API for creating, editing, and analyzing code across multiple programming languages. Think of it as the "Swiss Army knife" for code generation - one simple interface for all your code generation needs.
I wouldn't write this library if I didn't want to test these features in my cyclic AI agent that can execute code - https://github.com/rnr1721/depthnet . But I haven't found anything similar that fits. I don't plan to actively develop this library (at the moment), so if someone likes the idea, I'll be happy if this project is continued or a new one is created, I'll gladly use it :)
Features
- Simple Path-Based API - Work with real file paths, not abstract types
- AI-Friendly - Built for AI agents and automated code generation
- AST-Powered - Uses Abstract Syntax Trees for precise PHP code manipulation
- 6 Languages Supported - PHP, JavaScript, TypeScript, Python, CSS, JSON
- Extensible - Easy to add new language adapters
- Validation - Built-in syntax validation for all languages
Supported Languages & Features
| Language | Classes | Functions | Components | Models | Tests | Config | AST | Validation |
|---|---|---|---|---|---|---|---|---|
| PHP | ✓ Classes, Interfaces, Traits | ✓ Methods, Functions | ✘ | ✘ | ✘ | ✓ | ✓ | ✓ php -l |
| JavaScript | ✓ ES6 Classes | ✓ Functions, Arrow Functions | ✓ React Components | ✘ | ✘ | ✘ | ✘ | ✓ Syntax |
| TypeScript | ✓ Classes, Generics | ✓ Functions, Async | ✓ React, Hooks | ✓ Api, Clients | ✘ | ✓ tsconfig | ✘ | ✓ Syntax |
| Python | ✓ Classes, DataClasses | ✓ Functions, Async | ✘ | ✓ Django, FastAPI | ✓ Pytest | ✘ | ✘ | ✓ Syntax |
| CSS | ✘ | ✘ | ✓ BEM Components | ✘ | ✘ | ✘ | ✘ | ✓ Syntax |
| JSON | ✘ | ✘ | ✘ | ✘ | ✘ | ✓ Configs, Package.json | ✘ | ✓ JSON |
Quick Start
Installation
Basic Usage
Factory Pattern Usage
Language-Specific Examples
PHP - Laravel Model (AST-Powered)
Python - FastAPI Application
JavaScript - React Component
CSS - BEM Component
JSON - Package Configuration
Core API Methods
Creating Files
Editing Files
Analysis and Validation
Utility Methods
Advanced Usage
Batch Modifications
JSON Manipulation
AI Integration
CodeCraft is designed to be AI-friendly with simple, predictable behavior:
Creating Custom Adapters
Use Cases
AI Code Generation
- AI agents and assistants
- Automated code generation
- Template-based development
- Code completion tools
Development Tools
- Laravel Artisan commands
- Custom scaffolding tools
- Project generators
- Migration utilities
Migration & Transformation
- Converting between frameworks
- API code generation from specs
- Database model generation
- Legacy code modernization
Framework Integration
Laravel Integration
Dependency Injection
Testing
Development
Setup
Adding a New Language Adapter
- Implement
FileAdapterInterface - Add comprehensive help system with examples
- Write tests covering all functionality
- Update documentation and README
- Submit a pull request
Code Quality
Requirements
- PHP 8.2+
- Composer
- Extensions:
ext-json,ext-mbstring
Dependencies
- nikic/php-parser - For PHP AST manipulation
- PHPUnit - Testing framework
Optional Dependencies
- Xdebug - For code coverage reports
- symfony/console - For CLI integration
- laravel/framework - For Laravel integration
FAQ
Q: How is CodeCraft different from existing code generators?
A: CodeCraft provides a simple, path-based API that's intuitive for both humans and AI. It focuses on real file operations rather than abstract concepts.
Q: Why path-based instead of type-based?
A: Paths are more intuitive and provide context. app/Models/User.php immediately tells you what type of file it is and where it belongs.
Q: How reliable is the AST-based PHP adapter?
A: Very reliable! It uses nikic/php-parser (the same library used by PHPStan, Psalm, and PHP-CS-Fixer) for accurate PHP code generation and manipulation.
Q: How do I add support for a new language?
A: Implement the FileAdapterInterface and register your adapter. See the "Creating Custom Adapters" section for a complete example.
Q: Is CodeCraft suitable for AI agents?
A: Yes! CodeCraft was designed with AI in mind. The simple, path-based API is easy for AI models to understand and use correctly.
License
CodeCraft is open-sourced software licensed under the MIT license.