LLM Platform Architecture Overview
System Overviewβ
The LLM Platform is a multi-tier enterprise AI system built on Drupal 11 with TypeScript/Node.js microservices. The architecture separates concerns between data processing, AI operations, and user interfaces while maintaining security and scalability.
Core Architecture Principlesβ
- Microservices Design: NPM packages provide specialized AI services
- Drupal Integration: Custom modules extend Drupal with AI capabilities
- Security First: All AI operations include security scanning and compliance
- Test-Driven Development: 95%+ test coverage requirement across components
- Multi-Provider Support: Abstract AI provider implementations for vendor flexibility
System Tiersβ
Tier 1: Foundation Services (NPM Packages)β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β apple-fm β β llm-gateway β β tddai β
β Apple Models β β API Gateway β β Test Framework β
β TypeScript SDK β β Multi-Provider β β AI Integration β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β
βββββββββββββββββββ΄ββββββββββββββββββ
β llm-gateway-sdk β
β OpenAPI Generated SDK β
β TypeScript Client Library β
βββββββββββββββββββββββββββββββββββββ
Production Ready:
- apple-fm: TypeScript SDK for Apple Foundation Models with real Ollama integration
- llm-gateway-sdk: OpenAPI-generated client with comprehensive API coverage
- tddai: Working test framework with AI integration and multiple presets
In Development:
- llm-gateway: API gateway core working, advanced features developing
- llm-ui: React components exist, build optimization needed
Tier 2: Drupal Integration Layerβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Drupal 11 Core β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β β llm β βai_provider_ β β api_normalization β β
β β Core Module β β apple β β Framework β β
β βProduction β β Complete β β Ready β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β βgov_complianceβ βmcp_client_ β β recipe_onboarding β β
β β Framework β β extras β β Framework β β
β β Stage β β Development β β Stage β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Production Ready:
- llm: Enterprise AI platform with circuit breaker patterns, intelligent caching
- ai_provider_apple: Complete Apple Silicon optimization with 85% test coverage
Framework Stage:
- api_normalization: 95/100 innovation score, Drupal.org ready
- gov_compliance: Compliance framework structure
- recipe_onboarding: Installation and setup automation
Tier 3: Deployment & Configurationβ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β llm_platform β β secure_drupal β βllm_platform_ β
β Recipe β β Recipe β β manager β
β Optimized β β Security β β Theme β
β Deployment β β Focused β β Enterprise β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Data Flow Architectureβ
AI Request Processing Flowβ
User Request β Drupal Module β NPM Service β AI Provider β Response Processing β User Interface
β β β β β β
Security β Validation β Rate Limiting β API Call β Content Safety β Caching
Checking & Auth & Queuing & Retry Filtering & Delivery
Key Componentsβ
- Request Validation: Input sanitization and security scanning
- Provider Abstraction: Unified interface for multiple AI providers
- Queue Management: Asynchronous processing for long-running operations
- Response Processing: Content safety filtering and format normalization
- Caching Strategy: Multi-layer caching for performance optimization
Security Architectureβ
Multi-Layer Security Modelβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββ
β Application Layer β
β β’ Input Validation β’ CSRF Protection β’ Rate Limiting β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Service Layer β
β β’ API Key Management β’ Circuit Breakers β’ Audit Logs β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Data Layer β
β β’ Field Encryption β’ Secure Storage β’ Access Controls β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Security Featuresβ
- Field-Level Encryption: Sensitive data encrypted at rest
- API Key Rotation: Automated key management and rotation
- Circuit Breaker Pattern: Prevents cascade failures
- Audit Logging: Comprehensive security event tracking
- Compliance Framework: GDPR, HIPAA, SOC2 compliance modules
Integration Patternsβ
NPM Package β Drupal Module Integrationβ
- Service Container: NPM packages registered as Drupal services
- Configuration Bridge: Drupal configuration mapped to NPM package settings
- Event System: Drupal hooks trigger NPM package operations
- Queue Integration: Long-running NPM operations processed via Drupal queues
Provider Abstraction Patternβ
interface AIProviderInterface {
public function generateText(string $prompt, array $options): AIResponse;
public function generateImage(string $prompt, array $options): AIResponse;
public function processAudio(string $audio, array $options): AIResponse;
}
Each provider (OpenAI, Anthropic, Apple, etc.) implements this interface, allowing seamless switching between providers.
Performance Architectureβ
Caching Strategyβ
- Response Caching: AI responses cached by content hash
- Vector Caching: Embeddings cached for similarity searches
- Configuration Caching: Provider settings cached for performance
- Edge Caching: CDN integration for static AI-generated content
Scaling Considerationsβ
- Horizontal Scaling: NPM services can be deployed across multiple containers
- Load Balancing: API gateway distributes requests across service instances
- Database Optimization: Specialized tables for AI operations and logging
- Queue Processing: Background workers handle resource-intensive operations
Development Environmentβ
Local Development Stackβ
Docker Compose Environment:
βββ Drupal 11 (Apache/PHP 8.3)
βββ MySQL 8.0
βββ Redis (Caching)
βββ Node.js 18+ (NPM Services)
βββ Testing Services (Jest, PHPUnit)
Required Dependenciesβ
PHP Dependencies:
- Drupal 11.x
- Key module (API key management)
- Redis module (performance caching)
Node.js Dependencies:
- TypeScript 5.x
- OpenAPI generators
- Jest testing framework
Deployment Architectureβ
Production Environmentβ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Load Balancer β β Web Servers β β DB Cluster β
β (HAProxy) ββ β (Drupal 11) ββ β (MySQL 8) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β CDN/Edge β β NPM Services β β Redis Cluster β
β (CloudFlare) β β (Node.js) β β (Caching) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Container Architectureβ
Each NPM package can be containerized and deployed independently:
# Example: apple-fm service container
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist/ ./dist/
EXPOSE 3000
CMD ["node", "dist/index.js"]
Monitoring & Observabilityβ
Health Monitoringβ
- Service Health Checks: Each NPM service exposes health endpoints
- Database Monitoring: Connection pooling and query performance
- AI Provider Monitoring: Response times and error rates per provider
- Queue Monitoring: Processing times and backlog tracking
Logging Strategyβ
Application Logs β Structured JSON β Centralized Logging β Alerting
β β β β
Drupal Logs β Log Aggregation β ElasticSearch β PagerDuty
NPM Logs β (Fluentd) β (ELK) β Email/Slack
Configuration Managementβ
Environment-Based Configurationβ
# Development
ai_providers:
openai:
endpoint: "https://api.openai.com/v1"
timeout: 30000
apple:
endpoint: "http://localhost:3001"
timeout: 5000
# Production
ai_providers:
openai:
endpoint: "https://api.openai.com/v1"
timeout: 10000
apple:
endpoint: "https://apple-fm.internal.cluster"
timeout: 2000
Feature Flagsβ
- Provider Switching: Enable/disable AI providers without deployment
- Feature Rollouts: Gradual feature enablement for user groups
- Emergency Shutoffs: Quick disable of problematic features
Testing Architectureβ
Multi-Level Testing Strategyβ
- Unit Tests: Individual function testing (Jest, PHPUnit)
- Integration Tests: Service-to-service communication testing
- End-to-End Tests: Full user workflow testing
- Performance Tests: Load testing and response time validation
- Security Tests: Vulnerability scanning and penetration testing
Test Coverage Requirementsβ
- NPM Packages: 95% code coverage minimum
- Drupal Modules: 85% code coverage minimum
- Integration Tests: All critical user paths covered
- Performance Tests: Response time benchmarks established
Known Limitations & Constraintsβ
Current Implementation Constraintsβ
- Apple Intelligence: Currently uses Ollama integration, native Apple Intelligence pending
- Provider Rate Limits: Each AI provider has different rate limiting strategies
- Response Size Limits: Large content generation may require chunking
- Cache Invalidation: Complex cache dependencies require careful management
Scalability Considerationsβ
- Database: AI operation logs can grow quickly, requires archiving strategy
- File Storage: Generated content files need distributed storage solution
- Memory Usage: Vector embeddings can consume significant memory
- API Costs: AI provider costs scale with usage, monitoring required
Future Architecture Evolutionβ
Planned Enhancementsβ
- Native Apple Intelligence: Direct integration when APIs become available
- Multi-Region Deployment: Geographic distribution for performance
- Advanced Caching: Predictive pre-caching based on usage patterns
- Enhanced Security: Zero-trust architecture implementation
This architecture document reflects the current implemented state of the LLM Platform, with clear distinctions between production-ready components and those in development. All architectural decisions are based on actual working code rather than aspirational features.