|
| 1 | +# Architecture |
| 2 | + |
| 3 | +The PHP SDK is a single Composer package, `arcp/arcp`, with namespaces |
| 4 | +that map to the same layers as the TypeScript SDK packages. |
| 5 | + |
| 6 | +## Layering |
| 7 | + |
| 8 | +| Layer | PHP namespace | |
| 9 | +| --- | --- | |
| 10 | +| Wire/core | `Arcp\Envelope`, `Arcp\Messages`, `Arcp\Errors`, `Arcp\Ids` | |
| 11 | +| Client | `Arcp\Client` | |
| 12 | +| Runtime | `Arcp\Runtime`, `Arcp\Internal\Runtime` | |
| 13 | +| Transports | `Arcp\Transport` | |
| 14 | +| Persistence | `Arcp\Store` | |
| 15 | +| Extensions | `Arcp\Extensions` | |
| 16 | + |
| 17 | +The public surface is intentionally small: `ARCPClient`, `ARCPRuntime`, |
| 18 | +the message DTOs, transports, typed errors, and IDs. Internal dispatch |
| 19 | +collaborators live under `Arcp\Internal`. |
| 20 | + |
| 21 | +## Core |
| 22 | + |
| 23 | +`Arcp\Envelope\Envelope` is the top-level wire object. Payload |
| 24 | +polymorphism is handled by `MessageTypeRegistry`; the default registry is |
| 25 | +created by `MessageCatalog::create()`. |
| 26 | + |
| 27 | +Serialization is handled by `Arcp\Json\EnvelopeSerializer`, which turns |
| 28 | +envelopes into protocol JSON and back without reflection. |
| 29 | + |
| 30 | +## Client |
| 31 | + |
| 32 | +`Arcp\Client\ARCPClient` owns: |
| 33 | + |
| 34 | +- session handshake, |
| 35 | +- the background read loop, |
| 36 | +- correlated response routing, |
| 37 | +- subscription callbacks, |
| 38 | +- helper APIs such as `invokeTool()`, `listJobs()`, `subscribe()`, |
| 39 | + `cancelJob()`, `putArtifact()`, and `fetchArtifact()`. |
| 40 | + |
| 41 | +## Runtime |
| 42 | + |
| 43 | +`Arcp\Runtime\ARCPRuntime` owns: |
| 44 | + |
| 45 | +- registered tools and versioned tool resolution, |
| 46 | +- session negotiation, |
| 47 | +- job lifecycle, |
| 48 | +- permissions and leases, |
| 49 | +- artifacts, |
| 50 | +- subscriptions, |
| 51 | +- event logging. |
| 52 | + |
| 53 | +Tool handlers implement `Arcp\Runtime\ToolHandler` and receive a |
| 54 | +`JobContext` for progress, streams, metrics, permissions, artifacts, and |
| 55 | +result chunks. |
| 56 | + |
| 57 | +## CLI |
| 58 | + |
| 59 | +The aggregate package exposes `bin/arcp`, implemented with Symfony |
| 60 | +Console under `Arcp\Cli`. |
| 61 | + |
| 62 | +## Middleware |
| 63 | + |
| 64 | +There are no separate PHP middleware packages. PHP hosts should adapt |
| 65 | +`Arcp\Transport\Transport` to their framework or process model. |
| 66 | + |
| 67 | +## Wire format |
| 68 | + |
| 69 | +All messages are PHP value objects extending `MessageType`. Unknown core |
| 70 | +types are rejected as `UNIMPLEMENTED`; extension handling is delegated to |
| 71 | +`ExtensionRegistry`. |
| 72 | + |
| 73 | +## Where to read the code |
| 74 | + |
| 75 | +- `src/Client/ARCPClient.php` |
| 76 | +- `src/Runtime/ARCPRuntime.php` |
| 77 | +- `src/Envelope/MessageCatalog.php` |
| 78 | +- `src/Internal/Runtime/Dispatcher.php` |
| 79 | +- `src/Internal/Runtime/ToolInvocationHandler.php` |
0 commit comments