1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! Infrastructure Layer
//!
//! This module contains all adapter implementations and external system integrations
//! following the **Hexagonal Architecture** (Ports and Adapters) pattern.
//!
//! # Architecture
//!
//! The infrastructure layer is the outermost layer:
//! - **Depends on**: Application ports and core domain
//! - **Implements**: Application port traits (interfaces)
//! - **Integrates**: External systems (LLMs, databases, file storage, queues)
//!
//! # Dependency Flow
//!
//! ```text
//! External Systems
//! │
//! │ HTTP/TCP/Protocol
//! ▼
//! Infrastructure (Adapters) ──implements──> Application (Ports) ──uses──> Core
//! ```
//!
//! # Modules
//!
//! ## [adapters]
//!
//! Concrete implementations of application ports for external systems:
//!
//! ### LLM Provider Adapters ([adapters::llm])
//!
//! - **OpenAiAdapter** - OpenAI GPT models (hidden from docs, use via [`LlmPort`](paladin_ports::output::llm_port::LlmPort))
//! - Models: gpt-4, gpt-3.5-turbo, etc.
//! - Features: Streaming, function calling, vision
//! - **DeepSeekAdapter** - DeepSeek models (hidden from docs, use via [`LlmPort`](paladin_ports::output::llm_port::LlmPort))
//! - Cost-effective alternative with competitive performance
//! - **AnthropicAdapter** - Claude models (hidden from docs, use via [`LlmPort`](paladin_ports::output::llm_port::LlmPort))
//! - Models: claude-3-opus, claude-3-sonnet
//!
//! ### Memory Storage Adapters ([adapters::garrison])
//!
//! - **InMemoryGarrison** - In-process memory storage (hidden from docs, use via [`GarrisonPort`](paladin_ports::output::garrison_port::GarrisonPort))
//! - Fast, ephemeral, suitable for development
//! - **SqliteGarrison** - SQLite-backed persistent memory (hidden from docs, use via [`GarrisonPort`](paladin_ports::output::garrison_port::GarrisonPort))
//! - Local file storage, full-text search support
//!
//! ### Tool System Adapters ([adapters::arsenal])
//!
//! - **McpStdioAdapter** - MCP (Model Context Protocol) STDIO tools (hidden from docs, use via [`ArsenalPort`](paladin_ports::output::arsenal_port::ArsenalPort))
//! - Command-line tool integration
//! - **McpSseAdapter** - MCP SSE (Server-Sent Events) tools (hidden from docs, use via [`ArsenalPort`](paladin_ports::output::arsenal_port::ArsenalPort))
//! - Web-based tool integration
//!
//! ### State Persistence Adapters ([adapters::citadel])
//!
//! - **FileCitadel** - File-based state persistence (hidden from docs, use via [`CitadelPort`](paladin_ports::output::citadel_port::CitadelPort))
//! - Local filesystem storage
//!
//! ### Queue Adapters ([adapters::queue])
//!
//! - **RedisQueueAdapter** - Redis-backed queue (hidden from docs, use via port trait)
//! - Distributed task queue
//! - Feature flag: `redis-queue`
//!
//! ### File Storage Adapters ([adapters::file_storage])
//!
//! - **MinioAdapter** - S3-compatible storage (hidden from docs, use via port trait)
//! - Object storage for large files
//! - Feature flag: `s3-storage`
//!
//! ## [repositories]
//!
//! Database repository implementations for data persistence:
//!
//! - **MySQL repositories** - Production database storage (hidden from docs, use via repository ports)
//! - **SQLite repositories** - Development and testing (hidden from docs, use via repository ports)
//!
//! ## [web]
//!
//! Web server and API implementations:
//!
//! - REST API endpoints
//! - WebSocket handlers
//! - Middleware and routing
//!
//! # Adapter Pattern
//!
//! Each adapter translates between the application's port interface and
//! an external system's API:
//!
//! ```text
//! Application Port (Interface) External System
//! │ │
//! │ trait LlmPort │
//! │ fn generate(...) │
//! │ │
//! ▼ │
//! ┌─────────────────┐ │
//! │ OpenAiAdapter │─────────────────────┤
//! └─────────────────┘ HTTPS/REST API │
//! │ │
//! │ implements LlmPort │
//! │ │
//! └─────► translate request │
//! call OpenAI API ───────────►
//! ◄──────── response
//! translate response
//! return Result<Response>
//! ```
//!
//! # Feature Flags
//!
//! Infrastructure adapters use Cargo feature flags for optional dependencies:
//!
//! - `redis-queue` - Enable Redis queue adapter
//! - `s3-storage` - Enable MinIO/S3 storage adapter
//! - `integration-tests` - Enable integration test infrastructure
//!
//! # Configuration
//!
//! Adapters are configured via:
//! - Environment variables (e.g., `OPENAI_API_KEY`)
//! - Configuration files (`config.yml`)
//! - Direct instantiation in code
//!
//! # Examples
//!
//! ## Creating and Using an LLM Adapter
//!
//! ```ignore
//! use paladin::infrastructure::adapters::llm::openai_adapter::OpenAiAdapter;
//! use paladin_ports::output::llm_port::LlmPort;
//!
//! let adapter = OpenAiAdapter::new(
//! std::env::var("OPENAI_API_KEY").unwrap(),
//! "https://api.openai.com/v1".to_string(),
//! );
//!
//! let response = adapter.generate(&messages, &config).await?;
//! ```
//!
//! ## Using Redis Queue
//!
//! ```ignore
//! #[cfg(feature = "redis-queue")]
//! use paladin::infrastructure::adapters::queue::redis_adapter::RedisQueueAdapter;
//!
//! #[cfg(feature = "redis-queue")]
//! let queue = RedisQueueAdapter::new("redis://localhost:6379").await?;
//! ```
//!
//! ## Testing with Mock Adapters
//!
//! ```ignore
//! use paladin_ports::output::llm_port::LlmPort;
//!
//! struct MockLlmAdapter;
//!
//! #[async_trait]
//! impl LlmPort for MockLlmAdapter {
//! async fn generate(&self, _messages: &[Message]) -> Result<Response> {
//! Ok(Response {
//! content: "Mock response".to_string(),
//! // ...
//! })
//! }
//! }
//! ```
// Internal modules (public for testing, not part of stable API)