# jjjjstiyyyy/my-llm architecture

> Architecture diagram of the GitHub repository jjjjstiyyyy/my-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jjjjstiyyyy/my-llm
- Repository: https://github.com/jjjjstiyyyy/my-llm

## Overview

my-llm-py is an async LLM protocol adapter: an application supplies messages in a selected input/output format, configures an upstream provider and model, and receives translated messages or stream events. The principal path runs through profile resolution, request validation and conversion, a protocol-specific transport, then decoding and stream assembly. The graph also preserves offline conversion, semantic-loss handling, middleware I/O, caching, and protocol-specific implementations. Edges follow README statements or SOURCE INDEX references; unsampled subsystem links are omitted where their caller is not evidenced.

Main entry points: [`src/my_llm/codec/converter.py`](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/converter.py) (Format converter), [`src/my_llm/my_llm.py`](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/my_llm.py) (MyLLM), [`src/my_llm/codec/base/decoder.py`](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/decoder.py) (Native decoder), [`src/my_llm/codec/base/codec.py`](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/codec.py) (Codec registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entry"]
  node_myllm["MyLLM<br/>[my_llm.py]"]
end

subgraph group_config["Profiles and middleware"]
  node_profiles["Profile resolution<br/>[resolution.py]"]
  node_profile_config["Profile declarations<br/>[configuration.py]"]
  node_middleware_models["Middleware models<br/>[models.py]"]
  node_middleware_validation["Middleware validation<br/>[validation.py]"]
  node_middleware_stream["Middleware stream<br/>[stream.py]"]
end

subgraph group_conversion["Conversion core"]
  node_converter["Format converter<br/>[converter.py]"]
  node_base_codec["Codec registry<br/>[codec.py]"]
  node_base_encoder["Native encoder<br/>[encoder.py]"]
  node_base_decoder["Native decoder<br/>[decoder.py]"]
  node_shared_conversion["Shared conversion<br/>[conversion.py]"]
  node_shared_input["Input helpers<br/>[input.py]"]
  node_capabilities["Capability rules<br/>[capabilities.py]"]
  node_stream_helpers["Stream operations<br/>[stream.py]"]
  node_data["Data views<br/>[data.py]"]
  node_semantic_loss["Semantic-loss policy<br/>[semantic_loss.py]"]
  node_compiled_cache["Compiled cache<br/>[compiled_cache.py]"]
end

subgraph group_protocols["Protocol adapters"]
  node_openai_chat["OpenAI Chat"]
  node_openai_responses["OpenAI Responses"]
  node_anthropic["Anthropic Messages"]
end

subgraph group_runtime["Runtime and state"]
  node_runtime_state["Generation state<br/>[state.py]"]
  node_message_stream["Message stream<br/>[message_stream.py]"]
  node_message_cache[("Message cache<br/>[message_cache.py]")]
end

node_application(("Application"))
node_provider_services["Provider APIs"]

node_application -->|"calls generate"| node_myllm
node_myllm -->|"resolves settings"| node_profiles
node_profiles -->|"uses declarations"| node_profile_config
node_myllm -->|"converts requests"| node_converter
node_myllm -->|"uses middleware"| node_middleware_models
node_myllm -->|"uses stream types"| node_middleware_stream
node_converter -->|"uses codecs"| node_base_codec
node_converter -->|"uses encoders"| node_base_encoder
node_converter -->|"uses decoders"| node_base_decoder
node_converter -->|"converts middleware"| node_middleware_models
node_converter -->|"validates values"| node_middleware_validation
node_base_decoder -->|"uses schemas"| node_compiled_cache
node_base_decoder -->|"filters capabilities"| node_capabilities
node_base_decoder -->|"uses input helpers"| node_shared_input
node_base_decoder -->|"reports losses"| node_semantic_loss
node_openai_chat -->|"implements codec"| node_base_codec
node_openai_responses -->|"implements codec"| node_base_codec
node_anthropic -->|"implements codec"| node_base_codec
node_converter -.->|"selects protocol"| node_openai_chat
node_converter -.->|"selects protocol"| node_openai_responses
node_converter -.->|"selects protocol"| node_anthropic
node_openai_chat -.->|"sends requests"| node_provider_services
node_openai_responses -.->|"sends requests"| node_provider_services
node_anthropic -.->|"sends requests"| node_provider_services
node_myllm -->|"manages generation"| node_runtime_state
node_myllm -->|"returns stream"| node_message_stream
node_myllm -.->|"uses cache"| node_message_cache
node_application -->|"converts offline"| node_converter
node_application -->|"uses middleware I/O"| node_middleware_models
node_converter -->|"uses shared helpers"| node_shared_conversion
node_converter -->|"converts stream events"| node_stream_helpers

click node_myllm "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/my_llm.py"
click node_profiles "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/profile/resolution.py"
click node_profile_config "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/profile/configuration.py"
click node_middleware_models "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/middleware/models.py"
click node_middleware_validation "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/middleware/validation.py"
click node_middleware_stream "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/middleware/stream.py"
click node_converter "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/converter.py"
click node_base_codec "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/codec.py"
click node_base_encoder "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/encoder.py"
click node_base_decoder "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/decoder.py"
click node_shared_conversion "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/conversion.py"
click node_shared_input "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/input.py"
click node_capabilities "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/capabilities.py"
click node_stream_helpers "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/stream.py"
click node_data "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/basic/data.py"
click node_semantic_loss "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/basic/semantic_loss.py"
click node_compiled_cache "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/cache/compiled_cache.py"
click node_openai_chat "https://github.com/jjjjstiyyyy/my-llm/tree/main/src/my_llm/codec/openai/chat"
click node_openai_responses "https://github.com/jjjjstiyyyy/my-llm/tree/main/src/my_llm/codec/openai/responses"
click node_anthropic "https://github.com/jjjjstiyyyy/my-llm/tree/main/src/my_llm/codec/anthropic"
click node_runtime_state "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/runtime/state.py"
click node_message_stream "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/runtime/message_stream.py"
click node_message_cache "https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/cache/message_cache.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_myllm toneBlue
class node_profiles,node_profile_config,node_middleware_models,node_middleware_validation,node_middleware_stream toneAmber
class node_converter,node_base_codec,node_base_encoder,node_base_decoder,node_shared_conversion,node_shared_input,node_capabilities,node_stream_helpers,node_data,node_semantic_loss,node_compiled_cache,node_provider_services toneMint
class node_openai_chat,node_openai_responses,node_anthropic toneRose
class node_runtime_state,node_message_stream,node_message_cache,node_application toneIndigo
```

## Components

### Application entry

- [MyLLM](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/my_llm.py): `src/my_llm/my_llm.py`

### Profiles and middleware

- [Profile resolution](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/profile/resolution.py): `src/my_llm/profile/resolution.py`
- [Profile declarations](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/profile/configuration.py): `src/my_llm/profile/configuration.py`
- [Middleware models](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/middleware/models.py): `src/my_llm/middleware/models.py`
- [Middleware validation](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/middleware/validation.py): `src/my_llm/middleware/validation.py`
- [Middleware stream](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/middleware/stream.py): `src/my_llm/middleware/stream.py`

### Conversion core

- [Format converter](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/converter.py): `src/my_llm/codec/converter.py`
- [Codec registry](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/codec.py): `src/my_llm/codec/base/codec.py`
- [Native encoder](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/encoder.py): `src/my_llm/codec/base/encoder.py`
- [Native decoder](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/base/decoder.py): `src/my_llm/codec/base/decoder.py`
- [Shared conversion](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/conversion.py): `src/my_llm/codec/shared/conversion.py`
- [Input helpers](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/input.py): `src/my_llm/codec/shared/input.py`
- [Capability rules](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/capabilities.py): `src/my_llm/codec/shared/capabilities.py`
- [Stream operations](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/codec/shared/stream.py): `src/my_llm/codec/shared/stream.py`
- [Data views](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/basic/data.py): `src/my_llm/basic/data.py`
- [Semantic-loss policy](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/basic/semantic_loss.py): `src/my_llm/basic/semantic_loss.py`
- [Compiled cache](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/cache/compiled_cache.py): `src/my_llm/cache/compiled_cache.py`

### Protocol adapters

- [OpenAI Chat](https://github.com/jjjjstiyyyy/my-llm/tree/main/src/my_llm/codec/openai/chat): `src/my_llm/codec/openai/chat`
- [OpenAI Responses](https://github.com/jjjjstiyyyy/my-llm/tree/main/src/my_llm/codec/openai/responses): `src/my_llm/codec/openai/responses`
- [Anthropic Messages](https://github.com/jjjjstiyyyy/my-llm/tree/main/src/my_llm/codec/anthropic): `src/my_llm/codec/anthropic`

### Runtime and state

- [Generation state](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/runtime/state.py): `src/my_llm/runtime/state.py`
- [Message stream](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/runtime/message_stream.py): `src/my_llm/runtime/message_stream.py`
- [Message cache](https://github.com/jjjjstiyyyy/my-llm/blob/main/src/my_llm/cache/message_cache.py): `src/my_llm/cache/message_cache.py`

### Other components

- **Application**
- **Provider APIs**

## Connections

- Application → MyLLM: calls generate (evidence: `README.md`)
- MyLLM → Profile resolution: resolves settings (evidence: `src/my_llm/my_llm.py`)
- Profile resolution → Profile declarations: uses declarations (evidence: `src/my_llm/profile/resolution.py`)
- MyLLM → Format converter: converts requests (evidence: `src/my_llm/my_llm.py`)
- MyLLM → Middleware models: uses middleware (evidence: `src/my_llm/my_llm.py`)
- MyLLM → Middleware stream: uses stream types (evidence: `src/my_llm/my_llm.py`)
- Format converter → Codec registry: uses codecs (evidence: `src/my_llm/codec/converter.py`)
- Format converter → Native encoder: uses encoders (evidence: `src/my_llm/codec/converter.py`)
- Format converter → Native decoder: uses decoders (evidence: `src/my_llm/codec/converter.py`)
- Format converter → Middleware models: converts middleware (evidence: `src/my_llm/codec/converter.py`)
- Format converter → Middleware validation: validates values (evidence: `src/my_llm/codec/converter.py`)
- Native decoder → Compiled cache: uses schemas (evidence: `src/my_llm/codec/base/decoder.py`)
- Native decoder → Capability rules: filters capabilities (evidence: `src/my_llm/codec/base/decoder.py`)
- Native decoder → Input helpers: uses input helpers (evidence: `src/my_llm/codec/base/decoder.py`)
- Native decoder → Semantic-loss policy: reports losses (evidence: `src/my_llm/codec/base/decoder.py`)
- OpenAI Chat → Codec registry: implements codec (evidence: `src/my_llm/codec/openai/chat/codec.py`)
- OpenAI Responses → Codec registry: implements codec (evidence: `src/my_llm/codec/openai/responses/codec.py`)
- Anthropic Messages → Codec registry: implements codec (evidence: `src/my_llm/codec/anthropic/codec.py`)
- Format converter → OpenAI Chat: selects protocol
- Format converter → OpenAI Responses: selects protocol
- Format converter → Anthropic Messages: selects protocol
- OpenAI Chat → Provider APIs: sends requests
- OpenAI Responses → Provider APIs: sends requests
- Anthropic Messages → Provider APIs: sends requests
- MyLLM → Generation state: manages generation (evidence: `src/my_llm/my_llm.py`)
- MyLLM → Message stream: returns stream (evidence: `src/my_llm/my_llm.py`)
- MyLLM → Message cache: uses cache
- Application → Format converter: converts offline (evidence: `README.md`)
- Application → Middleware models: uses middleware I/O (evidence: `README.md`)
- Format converter → Shared conversion: uses shared helpers (evidence: `src/my_llm/codec/converter.py`)
- Format converter → Stream operations: converts stream events (evidence: `src/my_llm/codec/converter.py`)
