|
| 1 | +# Claude Configuration for PHPArchitect |
| 2 | + |
| 3 | +PHPArchitect is an open-source static analysis tool for enforcing architectural constraints in PHP applications. It uses the `nikic/php-parser` library to parse PHP code and validate it against defined architectural rules. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +- **Language:** PHP (7.4+, 8.0+) |
| 8 | +- **Type Checking:** Psalm |
| 9 | +- **Testing:** PHPUnit |
| 10 | +- **Code Style:** PHP-CS-Fixer |
| 11 | +- **Key Dependencies:** |
| 12 | + - `nikic/php-parser` (~5) - PHP AST parsing |
| 13 | + - `symfony/console` - CLI interface |
| 14 | + - `phpstan/phpdoc-parser` - Doc parsing |
| 15 | + - `symfony/event-dispatcher` - Event system |
| 16 | + - `symfony/finder` - File discovery |
| 17 | + |
| 18 | +## Development Workflow |
| 19 | + |
| 20 | +1. **Branching:** Create feature branches for new work |
| 21 | +2. **Testing:** All changes require passing unit tests |
| 22 | +3. **Code Style:** Run `make csfix` to fix code style |
| 23 | +4. **Type Safety:** Ensure no Psalm errors with `make psalm` |
| 24 | +5. **Pull Requests:** Submit PR for review before merging to main |
| 25 | + |
| 26 | +## Common Commands |
| 27 | + |
| 28 | +```bash |
| 29 | +make test # Run all unit tests |
| 30 | +make test_<name> # Run specific test (e.g., make test_Parser) |
| 31 | +make build # Full build: install deps, fix code style, run psalm, run tests |
| 32 | +make csfix # Fix code style issues |
| 33 | +make psalm # Run type checking |
| 34 | +make coverage # Generate coverage report |
| 35 | +make phar # Build PHAR executable |
| 36 | +``` |
| 37 | + |
| 38 | +## Project Structure |
| 39 | + |
| 40 | +``` |
| 41 | +src/ |
| 42 | + ├── Contracts/ # Core interfaces and contracts |
| 43 | + ├── Parser/ # AST parsing logic |
| 44 | + ├── Analyzer/ # Constraint analysis engine |
| 45 | + ├── Rules/ # Architectural rule definitions |
| 46 | + └── [other modules] |
| 47 | +tests/ |
| 48 | + └── [test files matching src/ structure] |
| 49 | +bin/ # Executable files |
| 50 | +``` |
| 51 | + |
| 52 | +## Critical Areas |
| 53 | + |
| 54 | +### 1. Parser and AST |
| 55 | +- **Location:** `src/Parser/` |
| 56 | +- **Purpose:** Parses PHP source code into an Abstract Syntax Tree |
| 57 | +- **Caution:** Parser edge cases can cause failures on unusual syntax. Be careful with: |
| 58 | + - First-class callables (PHP 8.1+) |
| 59 | + - Union/intersection types |
| 60 | + - Readonly properties |
| 61 | + - Dynamic property/method access |
| 62 | + |
| 63 | +### 2. Constraint Checking |
| 64 | +- **Location:** `src/Analyzer/`, `src/Rules/` |
| 65 | +- **Purpose:** Validates code against defined architectural constraints |
| 66 | +- **Critical:** This is the core logic of the tool |
| 67 | + |
| 68 | +### 3. Performance |
| 69 | +- **Concern:** Must handle analysis of large codebases efficiently |
| 70 | +- **Watch:** Avoid O(n²) algorithms on file collections, cache parsing results where possible |
| 71 | + |
| 72 | +## Code Style and Conventions |
| 73 | + |
| 74 | +- **PSR-4 Autoloading:** Namespace `Arkitect\` maps to `src/` |
| 75 | +- **Test Namespace:** `Arkitect\Tests\` maps to `tests/` |
| 76 | +- **Naming:** Use descriptive names for classes and methods |
| 77 | +- **Type Hints:** Use proper type declarations (PHP 7.4+ compatible) |
| 78 | +- **Comments:** Only add when logic is non-obvious; avoid redundant docblocks |
| 79 | + |
| 80 | +## What to Avoid |
| 81 | + |
| 82 | +1. **Over-engineering:** Keep solutions simple and focused on the requirement |
| 83 | +2. **Unnecessary comments/docstrings:** Only document complex logic |
| 84 | +3. **Feature flags/backwards-compatibility shims:** Modify code directly when possible |
| 85 | +4. **Parsing edge cases:** When working with parser logic, test against: |
| 86 | + - PHP 7.4 syntax (older code) |
| 87 | + - PHP 8.0+ features (newer syntax) |
| 88 | + - Mixed scenarios that could break |
| 89 | +5. **Test coverage:** Always add unit tests for new functionality |
| 90 | + |
| 91 | +## Testing Guidelines |
| 92 | + |
| 93 | +- Unit tests go in `tests/` mirroring the `src/` structure |
| 94 | +- Use PHPUnit (7.5+, 9.0+, or 10.0+) |
| 95 | +- Use prophecy for mocking |
| 96 | +- Aim for good coverage of critical paths |
| 97 | +- Test both success and edge cases |
| 98 | + |
| 99 | +## Building and Deployment |
| 100 | + |
| 101 | +### Local Build |
| 102 | +```bash |
| 103 | +make build |
| 104 | +``` |
| 105 | + |
| 106 | +### Docker |
| 107 | +```bash |
| 108 | +make dbi # Build Docker image |
| 109 | +docker run --rm -it --entrypoint= -v $(PWD):/arkitect phparkitect bash |
| 110 | +``` |
| 111 | + |
| 112 | +### PHAR Distribution |
| 113 | +```bash |
| 114 | +make phar # Creates phparkitect.phar |
| 115 | +``` |
| 116 | + |
| 117 | +## Key Files to Understand |
| 118 | + |
| 119 | +- `composer.json` - Project metadata and dependencies |
| 120 | +- `Makefile` - Development commands |
| 121 | +- `bin/phpunit` - Test runner |
| 122 | +- `bin/php-cs-fixer` - Code style fixer |
| 123 | +- `box.json` - PHAR configuration |
| 124 | +- `phparkitect-stub.php` - PHAR entry point |
| 125 | + |
| 126 | +## When to Ask for Help |
| 127 | + |
| 128 | +- Architecture questions about parsing or analysis flow |
| 129 | +- Performance optimization strategies |
| 130 | +- Complex test scenarios |
| 131 | +- Integration with Symfony components |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +*Last updated: 2025* |
0 commit comments