How meilisearch/meilisearch-php works
Project type and purpose
• This is an open-source PHP SDK (API client) for Meilisearch, a standalone search engine.
• Its sole responsibility is to provide developers with a typed, PSR-compliant, high-level PHP interface to communicate with a Meilisearch server over HTTP.
File structure
• Top-level:
– src/Client.php – the façade entry point
– src/Contracts/… – interfaces defining queries, results, endpoints, etc.
– src/Endpoints/… – concrete implementations of each Meilisearch endpoint (Indexes, Documents, Tasks, Stats, etc.)
– src/Http/… – HTTP client implementation wrapper + serializer (PSR-18 + PSR-17 + JSON)
– src/Exceptions/… – typed exceptions for API, network, JSON, timeouts
– src/Meilisearch.php – convenience alias
• Tests and scripts are kept separate and not part of runtime; they validate each component.
• Configuration: composer.json, Dockerfile, CI workflows—support packaging, testing, and release.
Extract architecture notes from the README
• The SDK requires a PSR-18 HTTP client + PSR-17 HTTP factory.
• It exposes a single Client class: developers call $client = new Client(url, key, optionalHttpClient)
• All calls (indexing, searching, settings, tasks) funnel through endpoint classes which orchestrate query construction, HTTP invocation, and response deserialization.
a. Main components
• Application code (your PHP project using the SDK)
• Meilisearch PHP SDK
– Client façade
– Endpoint modules
– Contracts (interfaces)
– HTTP layer (PSR-18 client + serializer)
– Exception handlers
• PSR-18 HTTP Client (e.g., Guzzle, Symfony) & PSR-17 factory
• JSON Serializer (implements SerializerInterface)
• External Meilisearch server (hosted or self-hosted)
b. Relationships & interactions
1. App → Client: developer instantiates Client and calls methods (e.g., index->addDocuments(), index->search()).
2. Client → Endpoint: delegates call to the correct Endpoint class (Indexes, Documents, Tasks, etc.).
3. Endpoint → Contracts: assembles a Query DTO (implements appropriate Query interface).
4. Endpoint → HTTP layer:
– Uses PSR-18 client + PSR-17 factory to build an HTTP Request.
– Passes serialized JSON payload via Serializer.
5. HTTP layer ↔ Meilisearch server: actual network call over HTTP.
6. Response → HTTP layer: receives HTTP response, JSON → parse into Results DTO (implements Results interface).
7. Endpoint returns typed Results (or throws Exception).
8. Client returns to Application.
c. Architectural patterns & design principles
• Layered: Presentation (app) → SDK API → Domain (Endpoints) → Infrastructure (HTTP) → External service
• Dependency Injection: HTTP client and serializer are injected into Client.
• Delegation & Traits: common behaviors (e.g., batching, documents) are shared across endpoints via traits.
• Robust error handling: specialized exceptions for API errors, communication failures, JSON issues.
d. Key technologies & libraries
• PSR-18 (HTTP Client), PSR-17 (HTTP Message Factory)
• JSON Serializer (implements SerializerInterface)
• Composer for dependency management
• PHPUnit for tests
• Docker & CI workflows for packaging and releasing