Skip to content

Commit 41f132a

Browse files
committed
Enhance claude.md with comprehensive practical guidance
Significantly improved claude.md to provide better context for AI-assisted development: ## New Sections Added - Quick Start for Common Tasks (TL;DR for immediate orientation) - Common Workflows (step-by-step guides for add rule, fix bug, update docs) - PHP Version Compatibility section (critical PHP 7.4 vs 8.0+ differences) - Quick Reference table (code ↔ documentation links) - Pre-Commit Checklist - Quick Troubleshooting guide ## Enhanced Sections - Project Structure: Detailed mapping of all src/ directories - Documentation Files: Added README, CONTRIBUTING, CONTRIBUTORS references - Critical Areas: Expanded with specific locations, purposes, and documentation links - Key Files: Categorized by purpose with descriptions ## Key Improvements - Clear connections between code locations and documentation - PHP 7.4 compatibility warnings with examples (trailing commas, union types, etc.) - Practical workflows instead of abstract guidelines - Quick reference for common issues and where to find solutions File size: 136 → 402 lines (3x more actionable content) This enhancement addresses real development scenarios and reduces time spent exploring the codebase for common tasks.
1 parent 019571f commit 41f132a

File tree

1 file changed

+284
-17
lines changed

1 file changed

+284
-17
lines changed

claude.md

Lines changed: 284 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PHPArchitect is an open-source static analysis tool for enforcing architectural
44

55
## Project Overview
66

7-
- **Language:** PHP (7.4+, 8.0+)
7+
- **Language:** PHP (7.4+, 8.0+) - **IMPORTANT: Must maintain PHP 7.4 compatibility!**
88
- **Type Checking:** Psalm
99
- **Testing:** PHPUnit
1010
- **Code Style:** PHP-CS-Fixer
@@ -15,6 +15,23 @@ PHPArchitect is an open-source static analysis tool for enforcing architectural
1515
- `symfony/event-dispatcher` - Event system
1616
- `symfony/finder` - File discovery
1717

18+
## Quick Start for Common Tasks
19+
20+
**Adding a new rule?**
21+
`src/Expression/ForClasses/` + tests + update `README.md`
22+
23+
**Fixing a bug?**
24+
→ Find relevant code, write failing test, fix, verify with `make test`
25+
26+
**Changed user-facing behavior?**
27+
→ Update `README.md` (installation/usage/rules sections)
28+
29+
**Ready to commit?**
30+
`make test && make csfix && make psalm` (all must pass)
31+
32+
**Need examples?**
33+
→ Look at existing code in `src/Expression/ForClasses/` and tests in `tests/`
34+
1835
## Development Workflow
1936

2037
1. **Branching:** Create feature branches for new work
@@ -23,6 +40,72 @@ PHPArchitect is an open-source static analysis tool for enforcing architectural
2340
4. **Type Safety:** Ensure no Psalm errors with `make psalm`
2441
5. **Pull Requests:** Submit PR for review before merging to main
2542

43+
## Common Workflows
44+
45+
### Adding a New Rule/Constraint
46+
47+
1. **Create the constraint class** in `src/Expression/ForClasses/`
48+
- Extend appropriate base class or implement interface
49+
- Implement the constraint logic
50+
- Add proper type hints (PHP 7.4+ compatible)
51+
52+
2. **Write unit tests** in `tests/Unit/Expression/ForClasses/`
53+
- Test success cases
54+
- Test failure cases with proper violation messages
55+
- Test edge cases
56+
57+
3. **Update README.md**
58+
- Add rule to "Available rules" section
59+
- Provide clear usage example
60+
- Explain the rule's purpose and use cases
61+
62+
4. **Run validation**
63+
```bash
64+
make test # Ensure tests pass
65+
make csfix # Fix code style
66+
make psalm # Check types
67+
```
68+
69+
### Fixing a Bug/Issue
70+
71+
1. **Understand the issue**
72+
- Read the issue description carefully
73+
- Check existing tests in `tests/` for related functionality
74+
- Use Grep/Read to find relevant code
75+
76+
2. **Write a failing test** (TDD approach)
77+
- Create or update test in appropriate location
78+
- Verify the test fails (reproduces the bug)
79+
80+
3. **Fix the code**
81+
- Make minimal changes to fix the issue
82+
- Avoid refactoring unrelated code
83+
- Keep PHP 7.4 compatibility in mind
84+
85+
4. **Verify the fix**
86+
```bash
87+
make test # All tests should pass
88+
make csfix # Fix any style issues
89+
make psalm # Ensure no type errors
90+
```
91+
92+
5. **Update documentation if needed**
93+
- Update README.md if behavior changed
94+
- Add comments only if logic is non-obvious
95+
96+
### Updating Documentation
97+
98+
**When to update:**
99+
- Adding/modifying rules → Update `README.md` "Available rules" section
100+
- Changing public API → Update `README.md` usage examples
101+
- Fixing bugs that affect user behavior → Update relevant docs
102+
103+
**Where to find what:**
104+
- **User documentation:** `README.md` (installation, usage, rules)
105+
- **Contributor guide:** `CONTRIBUTING.md`
106+
- **Code examples:** Look at existing rules in `src/Expression/ForClasses/`
107+
- **Test examples:** Check `tests/` for patterns and conventions
108+
26109
## Common Commands
27110

28111
```bash
@@ -37,37 +120,85 @@ make phar # Build PHAR executable
37120

38121
## Project Structure
39122

123+
### Source Code (`src/`)
40124
```
41125
src/
42-
├── Contracts/ # Core interfaces and contracts
43-
├── Parser/ # AST parsing logic
44126
├── Analyzer/ # Constraint analysis engine
45-
├── Rules/ # Architectural rule definitions
46-
└── [other modules]
127+
├── CLI/ # Command-line interface
128+
│ ├── Command/ # CLI commands (check, etc.)
129+
│ ├── Printer/ # Output formatters
130+
│ └── Progress/ # Progress indicators
131+
├── Exceptions/ # Custom exceptions
132+
├── Expression/ # Rule expressions (constraints)
133+
│ └── ForClasses/ # Class-level constraints
134+
├── PHPUnit/ # PHPUnit integration
135+
├── RuleBuilders/ # Fluent rule builders
136+
│ └── Architecture/ # Architectural pattern builders
137+
└── Rules/ # Core rule engine
138+
└── DSL/ # Domain-specific language parsing
47139
tests/
48-
└── [test files matching src/ structure]
49-
bin/ # Executable files
140+
└── [mirrors src/ structure]
141+
bin/
142+
├── phparkitect # Main executable
143+
└── [other tools]
50144
```
51145

146+
### Documentation Files
147+
- **`README.md`** - User-facing documentation, installation, usage, available rules
148+
- **`CONTRIBUTING.md`** - How to contribute (code, tests, docs)
149+
- **`CONTRIBUTORS.md`** - List of project contributors
150+
- **`claude.md`** - This file (Claude AI context)
151+
152+
### Configuration Files
153+
- **`phparkitect.php`** - Example configuration file for users
154+
- **`phparkitect-stub.php`** - PHAR entry point
155+
- **`composer.json`** - Dependencies and project metadata
156+
- **`box.json`** - PHAR build configuration
157+
- **`Makefile`** - Development commands
158+
52159
## Critical Areas
53160

54161
### 1. Parser and AST
55162
- **Location:** `src/Parser/`
56163
- **Purpose:** Parses PHP source code into an Abstract Syntax Tree
164+
- **Dependencies:** Uses `nikic/php-parser` (~5) for parsing
57165
- **Caution:** Parser edge cases can cause failures on unusual syntax. Be careful with:
58166
- First-class callables (PHP 8.1+)
59167
- Union/intersection types
60168
- Readonly properties
61169
- Dynamic property/method access
170+
- **When working here:** Always test with various PHP versions (7.4, 8.0+)
62171

63-
### 2. Constraint Checking
64-
- **Location:** `src/Analyzer/`, `src/Rules/`
172+
### 2. Constraint Checking (Rules & Expressions)
173+
- **Locations:**
174+
- `src/Rules/` - Core rule engine and DSL
175+
- `src/Expression/ForClasses/` - Individual constraint implementations
176+
- `src/Analyzer/` - Analysis orchestration
65177
- **Purpose:** Validates code against defined architectural constraints
66178
- **Critical:** This is the core logic of the tool
179+
- **Documentation link:** Rules are documented in `README.md` "Available rules" section
180+
- **When adding a rule:**
181+
1. Add constraint class in `src/Expression/ForClasses/`
182+
2. Add tests in `tests/Unit/Expression/ForClasses/`
183+
3. Document in `README.md`
67184

68-
### 3. Performance
185+
### 3. Rule Builders (Fluent API)
186+
- **Location:** `src/RuleBuilders/`, `src/Rules/RuleBuilder.php`
187+
- **Purpose:** Provides fluent interface for users to define rules
188+
- **Example:** `Rule::allClasses()->that(...)->should(...)->because(...)`
189+
- **Documentation:** Examples in `README.md` Quick Start section
190+
- **When modifying:** Update README examples to reflect API changes
191+
192+
### 4. CLI Interface
193+
- **Location:** `src/CLI/`
194+
- **Purpose:** Command-line interface, output formatting, progress tracking
195+
- **Main command:** `src/CLI/Command/Check.php`
196+
- **User impact:** Changes here affect user experience directly
197+
198+
### 5. Performance
69199
- **Concern:** Must handle analysis of large codebases efficiently
70200
- **Watch:** Avoid O(n²) algorithms on file collections, cache parsing results where possible
201+
- **Test:** Use large codebases to verify performance doesn't degrade
71202

72203
## Code Style and Conventions
73204

@@ -77,6 +208,75 @@ bin/ # Executable files
77208
- **Type Hints:** Use proper type declarations (PHP 7.4+ compatible)
78209
- **Comments:** Only add when logic is non-obvious; avoid redundant docblocks
79210

211+
## PHP Version Compatibility (CRITICAL)
212+
213+
This project supports **PHP 7.4+**, which has specific limitations compared to PHP 8.0+:
214+
215+
### PHP 7.4 Limitations to Avoid
216+
217+
**NO trailing commas in function parameters/calls**
218+
```php
219+
// WRONG (PHP 8.0+ only)
220+
function foo(
221+
string $a,
222+
string $b, // ← This comma breaks PHP 7.4
223+
) {}
224+
225+
// CORRECT (PHP 7.4 compatible)
226+
function foo(
227+
string $a,
228+
string $b // ← No trailing comma
229+
) {}
230+
```
231+
232+
**NO constructor property promotion**
233+
```php
234+
// WRONG (PHP 8.0+ only)
235+
public function __construct(
236+
private string $name,
237+
private int $age
238+
) {}
239+
240+
// CORRECT (PHP 7.4 compatible)
241+
private string $name;
242+
private int $age;
243+
244+
public function __construct(string $name, int $age)
245+
{
246+
$this->name = $name;
247+
$this->age = $age;
248+
}
249+
```
250+
251+
**NO union types (PHP 8.0+)**
252+
```php
253+
// WRONG
254+
public function foo(string|int $value) {}
255+
256+
// CORRECT: Use PHPDoc
257+
/** @param string|int $value */
258+
public function foo($value) {}
259+
```
260+
261+
**NO named arguments** (PHP 8.0+)
262+
**NO match expressions** (PHP 8.0+)
263+
**NO nullsafe operator (`?->`)** (PHP 8.0+)
264+
**NO attributes/annotations** (PHP 8.0+)
265+
266+
### PHP 7.4 Features You CAN Use
267+
268+
✅ Typed properties (introduced in PHP 7.4)
269+
✅ Arrow functions: `fn($x) => $x * 2`
270+
✅ Null coalescing assignment: `$var ??= 'default'`
271+
✅ Array spread: `[...$array1, ...$array2]`
272+
273+
### Testing Compatibility
274+
275+
Always test changes with PHP 7.4 to catch compatibility issues:
276+
```bash
277+
make test # Runs tests on configured PHP version
278+
```
279+
80280
## What to Avoid
81281

82282
1. **Over-engineering:** Keep solutions simple and focused on the requirement
@@ -116,20 +316,87 @@ make phar # Creates phparkitect.phar
116316

117317
## Key Files to Understand
118318

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
319+
### Configuration & Build
320+
- **`composer.json`** - Dependencies, autoloading, PHP version requirements
321+
- **`Makefile`** - All development commands (test, csfix, psalm, build, phar)
322+
- **`box.json`** - PHAR build configuration
323+
- **`phparkitect-stub.php`** - PHAR entry point
324+
- **`.php-cs-fixer.php`** - Code style rules
325+
326+
### Documentation (IMPORTANT)
327+
- **`README.md`** - **PRIMARY USER DOCUMENTATION**
328+
- Installation instructions
329+
- Usage examples
330+
- **Available rules section** (must update when adding rules!)
331+
- Configuration examples
332+
- **`CONTRIBUTING.md`** - How to contribute, development setup
333+
- **`CONTRIBUTORS.md`** - Project contributors list
334+
335+
### Entry Points
336+
- **`bin/phparkitect`** - Main CLI executable
337+
- **`src/CLI/Command/Check.php`** - Main check command implementation
338+
339+
### Core Classes to Know
340+
- **`src/Rules/Rule.php`** - Base rule class
341+
- **`src/Rules/RuleBuilder.php`** - Fluent API entry point
342+
- **`src/Expression/ForClasses/`** - All constraint implementations
343+
- **`src/Analyzer/`** - Analysis engine
344+
345+
### Testing
346+
- **`bin/phpunit`** - Test runner
347+
- **`tests/`** - Test files (mirror `src/` structure)
348+
- **`phpunit.xml.dist`** - PHPUnit configuration
349+
350+
## Quick Reference: Code ↔ Documentation Links
351+
352+
| Task | Code Location | Documentation | Tests |
353+
|------|---------------|---------------|-------|
354+
| Add new rule/constraint | `src/Expression/ForClasses/` | `README.md` "Available rules" | `tests/Unit/Expression/ForClasses/` |
355+
| Modify rule builder API | `src/Rules/RuleBuilder.php` | `README.md` examples | `tests/Unit/Rules/` |
356+
| Change CLI behavior | `src/CLI/Command/` | `README.md` "Usage" | `tests/Unit/CLI/` |
357+
| Fix parser issues | `src/Parser/` | N/A | `tests/Unit/Parser/` |
358+
| Update analysis logic | `src/Analyzer/` | N/A | `tests/Unit/Analyzer/` |
359+
360+
## Pre-Commit Checklist
361+
362+
Before committing changes, ensure:
363+
364+
- [ ] **Tests pass:** `make test`
365+
- [ ] **Code style fixed:** `make csfix`
366+
- [ ] **No type errors:** `make psalm`
367+
- [ ] **PHP 7.4 compatible:** No trailing commas, union types, or PHP 8+ syntax
368+
- [ ] **Documentation updated:** If adding/changing rules, update `README.md`
369+
- [ ] **Tests added:** New functionality has corresponding tests
370+
371+
## Quick Troubleshooting
372+
373+
**Tests failing?**
374+
- Run `make test` to see failures
375+
- Check PHP version compatibility (PHP 7.4 vs 8.0+)
376+
- Ensure you didn't use PHP 8.0+ syntax
377+
378+
**Psalm errors?**
379+
- Run `make psalm` to see type issues
380+
- Check type hints and return types
381+
- Use PHPDoc for complex types
382+
383+
**Code style issues?**
384+
- Run `make csfix` to auto-fix
385+
- Check for trailing commas in function parameters (PHP 7.4 incompatible)
386+
387+
**Can't find where to add a rule?**
388+
- Look at existing rules in `src/Expression/ForClasses/`
389+
- Check tests in `tests/Unit/Expression/ForClasses/` for patterns
390+
- Follow the "Adding a New Rule" workflow above
125391

126392
## When to Ask for Help
127393

128394
- Architecture questions about parsing or analysis flow
129395
- Performance optimization strategies
130396
- Complex test scenarios
131397
- Integration with Symfony components
398+
- Uncertainty about where to implement a feature
132399

133400
---
134401

135-
*Last updated: 2025*
402+
*Last updated: February 2026*

0 commit comments

Comments
 (0)