|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +## Repository Structure |
| 4 | + |
| 5 | +This repository contains two distinct packages with clear separation of concerns: |
| 6 | + |
| 7 | +### 1. Core Library (`/`) |
| 8 | + |
| 9 | +The main library providing tools and runtime support for Twenty CRM integration: |
| 10 | + |
| 11 | +- **Location:** Root directory |
| 12 | +- **Package:** `factorial-io/twenty-crm-php-client` |
| 13 | +- **Purpose:** Generic, schema-agnostic tools |
| 14 | +- **Contains:** |
| 15 | + - DynamicEntity system |
| 16 | + - Code generation CLI (`bin/twenty-generate`) |
| 17 | + - Metadata discovery |
| 18 | + - Entity relations |
| 19 | + - HTTP client infrastructure |
| 20 | +- **Tests:** Unit tests only (`tests/Unit/`) |
| 21 | + |
| 22 | +### 2. Usage Example (`/usage-example/`) |
| 23 | + |
| 24 | +Example implementation with generated entities demonstrating the library: |
| 25 | + |
| 26 | +- **Location:** `usage-example/` subdirectory |
| 27 | +- **Package:** `factorial-io/twenty-crm-entities` (example, not published) |
| 28 | +- **Purpose:** Usage examples, schema-specific entities, and integration tests |
| 29 | +- **Contains:** |
| 30 | + - Generated Person, Company, Campaign entities |
| 31 | + - Integration tests demonstrating library features |
| 32 | + - Test helpers and factories |
| 33 | + - Example usage patterns |
| 34 | +- **Tests:** Integration tests (`usage-example/tests/Integration/`) |
| 35 | + |
| 36 | +## Separation of Concerns |
| 37 | + |
| 38 | +| Concern | Core Library | Usage Example | |
| 39 | +|---------|--------------|---------------| |
| 40 | +| Generic tools | ✅ | ❌ | |
| 41 | +| DynamicEntity | ✅ | Uses | |
| 42 | +| Code generator | ✅ | Uses | |
| 43 | +| Generated entities | ❌ | ✅ | |
| 44 | +| Integration tests | ❌ | ✅ | |
| 45 | +| Schema-specific code | ❌ | ✅ | |
| 46 | +| Unit tests | ✅ | ❌ | |
| 47 | + |
| 48 | +## Running Tests |
| 49 | + |
| 50 | +### Core Library (Unit Tests) |
| 51 | + |
| 52 | +```bash |
| 53 | +# Run all unit tests |
| 54 | +vendor/bin/phpunit |
| 55 | + |
| 56 | +# Run with coverage |
| 57 | +vendor/bin/phpunit --coverage-html coverage/ |
| 58 | +``` |
| 59 | + |
| 60 | +### Usage Example (Integration Tests) |
| 61 | + |
| 62 | +```bash |
| 63 | +# Setup |
| 64 | +cd usage-example |
| 65 | +cp .env.example .env |
| 66 | +# Edit .env with your credentials |
| 67 | + |
| 68 | +# Run integration tests |
| 69 | +cd usage-example |
| 70 | +../vendor/bin/phpunit |
| 71 | +``` |
| 72 | + |
| 73 | +## Development Workflow |
| 74 | + |
| 75 | +### Working on Core Library |
| 76 | + |
| 77 | +1. Make changes in `src/` |
| 78 | +2. Add unit tests in `tests/Unit/` |
| 79 | +3. Run `vendor/bin/phpunit` |
| 80 | +4. Ensure no entity-specific code |
| 81 | + |
| 82 | +### Working on Usage Example |
| 83 | + |
| 84 | +1. Generate entities: `vendor/bin/twenty-generate --config=usage-example/.twenty-codegen.yml` |
| 85 | +2. Add integration tests in `usage-example/tests/Integration/` |
| 86 | +3. Run `cd usage-example && ../vendor/bin/phpunit` |
| 87 | +4. Commit generated code |
| 88 | + |
| 89 | +## Usage Example as Template |
| 90 | + |
| 91 | +The `usage-example/` directory serves multiple purposes: |
| 92 | + |
| 93 | +1. **Documentation:** Shows how to use the library with real code |
| 94 | +2. **Testing:** Integration tests validate library features against a live Twenty CRM instance |
| 95 | +3. **Code Generation Example:** Demonstrates the code generation workflow |
| 96 | +4. **Template:** Can be copied/adapted for your own Twenty CRM instance |
| 97 | + |
| 98 | +## Why This Structure? |
| 99 | + |
| 100 | +1. **Flexibility:** Users can use core library with any Twenty instance |
| 101 | +2. **Type Safety:** Generated typed entities with IDE support |
| 102 | +3. **Clean Separation:** No instance-specific code in core library |
| 103 | +4. **Living Documentation:** Real, tested examples of library usage |
| 104 | +5. **Example Code:** Shows how to generate and use entities |
| 105 | + |
| 106 | +## Code Generation |
| 107 | + |
| 108 | +Generate entities using the example configuration: |
| 109 | + |
| 110 | +```bash |
| 111 | +# Using config file |
| 112 | +vendor/bin/twenty-generate --config=usage-example/.twenty-codegen.yml |
| 113 | + |
| 114 | +# Or with CLI args |
| 115 | +vendor/bin/twenty-generate \ |
| 116 | + --api-url=https://your-instance.twenty.com/rest/ \ |
| 117 | + --api-token=$TWENTY_TOKEN \ |
| 118 | + --namespace="Factorial\\TwentyCrm\\Entities" \ |
| 119 | + --output=usage-example/src \ |
| 120 | + --entities=person,company,campaign |
| 121 | +``` |
| 122 | + |
| 123 | +## Quality Checks |
| 124 | + |
| 125 | +```bash |
| 126 | +# PHP CodeSniffer |
| 127 | +vendor/bin/phpcs |
| 128 | + |
| 129 | +# PHP CS Fixer |
| 130 | +vendor/bin/php-cs-fixer fix --dry-run --diff |
| 131 | + |
| 132 | +# PHPStan |
| 133 | +vendor/bin/phpstan analyse src |
| 134 | +``` |
0 commit comments