How adaline/gateway works
Project Type and Purpose
• This is an open‑source, production‑grade SDK (“Adaline Gateway”) for unifying access to 200+ LLMs completely locally.
• It’s a monorepo (pnpm + Turbo) containing a core gateway engine, many provider adapters, shared types, and helper packages.
High‑Level File Structure & Architectural Patterns
• Top‑level “core” houses:
• core/gateway – the Gateway engine (handlers, plugin interfaces, queue, cache, telemetry, etc.)
• core/providers/* – individual provider adapters (Anthropic, OpenAI, Azure, Bedrock, etc.) each following an adapter/strategy pattern
• “packages” contains:
• packages/types – shared TypeScript types & schemas (MessageType, Config, errors)
• packages/provider – v1 provider SDK interfaces, schemas, error definitions (legacy compatibility)
• Tools & config at root (husky, lint, turborepo, tsconfig) orchestrate builds and CI.
• Architectural patterns:
• Plugin architecture in the gateway (cache, logger, HTTP, queue, telemetry are pluggable)
• Adapter/Strategy for providers (each provider implements a uniform interface)
• Monorepo + Turborepo for code sharing and parallel builds
Core Components to Capture
a. Client Code
• “Your App” or “User Code” that imports Gateway, Config, and Provider(s)
b. Gateway Engine
• Gateway object instance
• Internals:
• Queue Manager
• Cache Manager
• Retry / Backoff logic
• HTTP Client Plugin
• Logger Plugin
• Telemetry (OpenTelemetry) Plugin
• Handlers for streamChat, completeChat, getEmbeddings
c. Provider Adapters
• e.g., @adaline/openai, @adaline/anthropic, @adaline/azure…
• Each adapter defines: Configs → Model objects → Provider vX interface → transforms calls → underlying HTTP calls
d. Shared Types & Config
• packages/types exports the super-types (MessageType, Config schemas) used by both gateway and providers
e. External LLM Endpoints
• OpenAI API, Anthropic API, Azure OpenAI endpoint, AWS Bedrock, etc.
Relationships & Data Flow
1) Client invokes Gateway.streamChat or Gateway.completeChat with:
• Model (from a provider adapter)
• Config (from shared types)
• Messages (MessageType[])
2) Gateway routes the request through its pipeline:
• (optional) Cache lookup → hit/miss
• Enqueue request in custom queue → batching
• Retry policy wraps HTTP client plugin call
• Logger & Telemetry wrap every stage
3) Gateway calls the provider adapter’s transformModelRequest → builds provider‑specific payload
4) HTTP Client plugin makes the actual network call to the external LLM endpoint
5) Response flows back through retry logic, handlers parse streams or completions, callbacks invoked, then returned to client
Key Architectural Patterns / Design Principles
• Separation of Concerns: Gateway core is independent of any particular LLM vendor
• Inversion of Control: Plugins and providers are injected into the Gateway object
• Single Responsibility: Each provider module only cares about model definitions & payload transformation
• Reusability via Monorepo: Shared types and error handling live in central packages