Skip to content

Commit e00fbe8

Browse files
committed
chore: updates architecture doc to reflect changes
1 parent bf1cee6 commit e00fbe8

File tree

1 file changed

+157
-30
lines changed

1 file changed

+157
-30
lines changed

docs/ARCHITECTURE.md

Lines changed: 157 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,158 @@ direction LR
802802
Tool "1" o-- "0..1" WebSearch
803803
```
804804

805+
## HTTP Communication Layer
806+
807+
This section describes the HTTP communication architecture that differs from the original design. Instead of models directly using PSR-18 HTTP clients, we introduce a layer of abstraction that provides better separation of concerns and flexibility.
808+
809+
### Design Principles
810+
811+
1. **Custom Request/Response Objects**: Models create and receive custom Request and Response objects specific to this library
812+
2. **HttpTransporter**: A dedicated class that handles the translation between custom objects and PSR standards
813+
3. **PSR Compliance**: The transporter uses PSR-7 (HTTP messages), PSR-17 (HTTP factories), and PSR-18 (HTTP client) internally
814+
4. **No Direct Coupling**: The library remains decoupled from any specific HTTP client implementation
815+
816+
### HTTP Communication Flow
817+
818+
```mermaid
819+
sequenceDiagram
820+
participant Model
821+
participant HttpTransporter
822+
participant PSR17Factory
823+
participant PSR18Client
824+
825+
Model->>HttpTransporter: send(Request)
826+
HttpTransporter->>PSR17Factory: createRequest(Request)
827+
PSR17Factory-->>HttpTransporter: PSR-7 Request
828+
HttpTransporter->>PSR18Client: sendRequest(PSR-7 Request)
829+
PSR18Client-->>HttpTransporter: PSR-7 Response
830+
HttpTransporter->>PSR17Factory: parseResponse(PSR-7 Response)
831+
PSR17Factory-->>HttpTransporter: Response
832+
HttpTransporter-->>Model: Response
833+
```
834+
835+
### HTTP Components Class Diagram
836+
837+
```mermaid
838+
---
839+
config:
840+
class:
841+
hideEmptyMembersBox: true
842+
---
843+
classDiagram
844+
direction TB
845+
namespace AiClientNamespace.Http.DTO {
846+
class Request {
847+
+getMethod() string
848+
+getUri() string
849+
+getHeaders() array< string, string|string[] >
850+
+getBody() string|null
851+
+withHeader(string $name, string|string[] $value) self
852+
+withBody(string $body) self
853+
+getJsonSchema() array< string, mixed >$
854+
}
855+
856+
class Response {
857+
+getStatusCode() int
858+
+getHeaders() array< string, string|string[] >
859+
+getBody() string
860+
+getReasonPhrase() string
861+
+isSuccessful() bool
862+
+getJsonSchema() array< string, mixed >$
863+
}
864+
}
865+
866+
namespace AiClientNamespace.Http.Contracts {
867+
class HttpTransporterInterface {
868+
+send(Request $request) Response
869+
}
870+
}
871+
872+
namespace AiClientNamespace.Http {
873+
class HttpTransporter {
874+
-requestFactory Psr17RequestFactoryInterface
875+
-streamFactory Psr17StreamFactoryInterface
876+
-client Psr18ClientInterface
877+
+__construct(Psr17RequestFactoryInterface $requestFactory, Psr17StreamFactoryInterface $streamFactory, Psr18ClientInterface $client)
878+
+send(Request $request) Response
879+
-convertToPsr7Request(Request $request) Psr7RequestInterface
880+
-convertFromPsr7Response(Psr7ResponseInterface $response) Response
881+
}
882+
}
883+
884+
namespace PSR {
885+
class Psr17RequestFactoryInterface {
886+
<<interface>>
887+
+createRequest(string $method, UriInterface|string $uri) RequestInterface
888+
}
889+
890+
class Psr17StreamFactoryInterface {
891+
<<interface>>
892+
+createStream(string $content) StreamInterface
893+
}
894+
895+
class Psr18ClientInterface {
896+
<<interface>>
897+
+sendRequest(RequestInterface $request) ResponseInterface
898+
}
899+
900+
class Psr7RequestInterface {
901+
<<interface>>
902+
}
903+
904+
class Psr7ResponseInterface {
905+
<<interface>>
906+
}
907+
}
908+
909+
<<interface>> HttpTransporterInterface
910+
911+
HttpTransporter ..|> HttpTransporterInterface
912+
HttpTransporter --> Psr17RequestFactoryInterface : uses
913+
HttpTransporter --> Psr17StreamFactoryInterface : uses
914+
HttpTransporter --> Psr18ClientInterface : uses
915+
HttpTransporter ..> Request : receives
916+
HttpTransporter ..> Response : creates
917+
HttpTransporter ..> Psr7RequestInterface : creates
918+
HttpTransporter ..> Psr7ResponseInterface : receives
919+
```
920+
921+
### Integration with Models
922+
923+
Models that need HTTP communication will use the `HttpTransporterInterface`:
924+
925+
```mermaid
926+
---
927+
config:
928+
class:
929+
hideEmptyMembersBox: true
930+
---
931+
classDiagram
932+
namespace AiClientNamespace.Providers.Models.Contracts {
933+
class WithHttpTransporterInterface {
934+
+setHttpTransporter(HttpTransporterInterface $transporter) void
935+
+getHttpTransporter() HttpTransporterInterface
936+
}
937+
}
938+
939+
namespace AiClientNamespace.Providers.Models.TextGeneration {
940+
class SomeProviderTextGenerationModel {
941+
-transporter HttpTransporterInterface
942+
+generateTextResult(Message[] $prompt) GenerativeAiResult
943+
-createApiRequest(Message[] $prompt) Request
944+
-parseApiResponse(Response $response) GenerativeAiResult
945+
}
946+
}
947+
948+
<<interface>> WithHttpTransporterInterface
949+
950+
SomeProviderTextGenerationModel ..|> TextGenerationModelInterface
951+
SomeProviderTextGenerationModel ..|> WithHttpTransporterInterface
952+
SomeProviderTextGenerationModel --> HttpTransporterInterface : uses
953+
SomeProviderTextGenerationModel --> Request : creates
954+
SomeProviderTextGenerationModel --> Response : receives
955+
```
956+
805957
### Details: Class diagram for AI extenders
806958

807959
```mermaid
@@ -826,13 +978,9 @@ direction LR
826978
827979
namespace AiClientNamespace.Providers.Contracts {
828980
class AuthenticationInterface {
829-
+authenticate(RequestInterface $request) void
981+
+authenticate(Request $request) void
830982
+getJsonSchema() array< string, mixed >$
831983
}
832-
class HttpClientInterface {
833-
+send(RequestInterface $request, array< string, mixed > $options) ResponseInterface
834-
+request(string $method, string $uri, array< string, mixed > $options) ResponseInterface
835-
}
836984
class ModelMetadataDirectoryInterface {
837985
+listModelMetadata() ModelMetadata[]
838986
+hasModelMetadata(string $modelId) bool
@@ -885,15 +1033,9 @@ direction LR
8851033
+setAuthentication(AuthenticationInterface $authentication) void
8861034
+getAuthentication() AuthenticationInterface
8871035
}
888-
class WithEmbeddingOperationsInterface {
889-
+getOperation(string $operationId) EmbeddingOperation
890-
}
891-
class WithGenerativeAiOperationsInterface {
892-
+getOperation(string $operationId) GenerativeAiOperation
893-
}
894-
class WithHttpClientInterface {
895-
+setHttpClient(HttpClientInterface $client) void
896-
+getHttpClient() HttpClientInterface
1036+
class WithHttpTransporterInterface {
1037+
+setHttpTransporter(HttpTransporterInterface $transporter) void
1038+
+getHttpTransporter() HttpTransporterInterface
8971039
}
8981040
}
8991041
@@ -973,14 +1115,6 @@ direction LR
9731115
}
9741116
}
9751117
976-
namespace AiClientNamespace.Providers.Models.EmbeddingGeneration.Contracts {
977-
class EmbeddingGenerationModelInterface {
978-
+generateEmbeddingsResult(Message[] $input) EmbeddingResult
979-
}
980-
class EmbeddingGenerationOperationModelInterface {
981-
+generateEmbeddingsOperation(Message[] $input) EmbeddingOperation
982-
}
983-
}
9841118
9851119
namespace AiClientNamespace.Providers.Models.ImageGeneration.Contracts {
9861120
class ImageGenerationModelInterface {
@@ -1050,20 +1184,15 @@ direction LR
10501184
<<interface>> ModelInterface
10511185
<<interface>> ProviderAvailabilityInterface
10521186
<<interface>> ModelMetadataDirectoryInterface
1053-
<<interface>> WithGenerativeAiOperationsInterface
1054-
<<interface>> WithEmbeddingOperationsInterface
10551187
<<interface>> TextGenerationModelInterface
10561188
<<interface>> ImageGenerationModelInterface
10571189
<<interface>> TextToSpeechConversionModelInterface
10581190
<<interface>> SpeechGenerationModelInterface
1059-
<<interface>> EmbeddingGenerationModelInterface
10601191
<<interface>> TextGenerationOperationModelInterface
10611192
<<interface>> ImageGenerationOperationModelInterface
10621193
<<interface>> TextToSpeechConversionOperationModelInterface
10631194
<<interface>> SpeechGenerationOperationModelInterface
1064-
<<interface>> EmbeddingGenerationOperationModelInterface
1065-
<<interface>> WithHttpClientInterface
1066-
<<interface>> HttpClientInterface
1195+
<<interface>> WithHttpTransporterInterface
10671196
<<interface>> WithAuthenticationInterface
10681197
<<interface>> AuthenticationInterface
10691198
<<Enumeration>> CapabilityEnum
@@ -1095,10 +1224,8 @@ direction LR
10951224
ModelInterface <|-- ImageGenerationModelInterface
10961225
ModelInterface <|-- TextToSpeechConversionModelInterface
10971226
ModelInterface <|-- SpeechGenerationModelInterface
1098-
ModelInterface <|-- EmbeddingGenerationModelInterface
10991227
ModelInterface <|-- TextGenerationOperationModelInterface
11001228
ModelInterface <|-- ImageGenerationOperationModelInterface
11011229
ModelInterface <|-- TextToSpeechConversionOperationModelInterface
11021230
ModelInterface <|-- SpeechGenerationOperationModelInterface
1103-
ModelInterface <|-- EmbeddingGenerationOperationModelInterface
11041231
```

0 commit comments

Comments
 (0)