WrenAI is a comprehensive AI-powered data modeling and query generation platform that transforms natural language questions into SQL queries. The system consists of multiple interconnected services that work together to provide intelligent data analysis capabilities.
graph TB
subgraph "User Interface Layer"
UI[Wren UI<br/>Next.js Frontend<br/>Port: 3000]
CLI[Wren Launcher<br/>CLI Tool<br/>Go Application]
end
subgraph "API Gateway Layer"
GQL[GraphQL API<br/>Apollo Server]
REST[REST API<br/>FastAPI]
end
subgraph "Core Services"
AI[Wren AI Service<br/>Python FastAPI<br/>Port: 5555]
ENGINE[Wren Engine<br/>Java/Rust<br/>Port: 8080]
IBIS[Ibis Server<br/>Python<br/>Port: 8000]
end
subgraph "Data Layer"
QDRANT[Qdrant Vector DB<br/>Port: 6333]
SQLITE[SQLite Database<br/>Metadata Storage]
CACHE[In-Memory Cache<br/>Query Results]
end
subgraph "External Services"
LLM[LLM Providers<br/>OpenAI, Custom]
DATASOURCES[Data Sources<br/>BigQuery, PostgreSQL<br/>MySQL, Snowflake, etc.]
end
CLI --> UI
UI --> GQL
GQL --> AI
GQL --> ENGINE
GQL --> IBIS
AI --> REST
AI --> QDRANT
AI --> LLM
ENGINE --> DATASOURCES
IBIS --> DATASOURCES
UI --> SQLITE
AI --> CACHE
style UI fill:#e3f2fd
style AI fill:#fff3e0
style ENGINE fill:#f3e5f5
style QDRANT fill:#e8f5e8
style LLM fill:#fce4ec
- Technology: Next.js 14, React, TypeScript, Ant Design
- Port: 3000
- Responsibilities:
- Data source connection and configuration
- Visual data modeling interface
- Natural language query input
- Result visualization and charts
- User authentication and settings
Key Components:
// Main App Structure
src/pages/_app.tsx // Application root
src/pages/home/index.tsx // Query interface
src/pages/setup/ // Data source setup
src/pages/modeling/ // Data modeling tools
src/components/diagram/ // Visual modeling components
- Technology: Go
- Purpose: System orchestration and setup
- Responsibilities:
- Interactive system setup
- Docker container management
- Configuration generation
- Service health monitoring
- Technology: Python, FastAPI, Hamilton pipelines
- Port: 5555
- Architecture Pattern: Pipeline-based processing
graph LR
subgraph "AI Service Internal Architecture"
ROUTER[FastAPI Router] --> PIPELINE[Pipeline Manager]
PIPELINE --> INDEXING[Indexing Pipelines]
PIPELINE --> RETRIEVAL[Retrieval Pipelines]
PIPELINE --> GENERATION[Generation Pipelines]
INDEXING --> DBSCHEMA[DB Schema Indexing]
INDEXING --> HISTORICAL[Historical Q&A]
RETRIEVAL --> DBRETRIEVAL[DB Schema Retrieval]
RETRIEVAL --> QARETRIEVAL[Q&A Retrieval]
GENERATION --> SQLGEN[SQL Generation]
GENERATION --> FOLLOWUP[Follow-up Generation]
GENERATION --> ADJUSTMENT[Chart Adjustment]
end
style DBSCHEMA fill:#e8f5e8
style SQLGEN fill:#fff3e0
style RETRIEVAL fill:#f3e5f5
Core Pipelines:
-
Indexing Pipelines (
src/pipelines/indexing/
):db_schema.py
- Database schema vectorizationhistorical_question.py
- Q&A pair indexing
-
Retrieval Pipelines (
src/pipelines/retrieval/
):db_schema_retrieval.py
- Schema context retrievalhistorical_question_retrieval.py
- Similar question retrieval
-
Generation Pipelines (
src/pipelines/generation/
):sql_generation.py
- SQL query generationfollowup_generation.py
- Follow-up question generationchart_generation.py
- Visualization generation
- Technology: Java (Traditional) / Rust (Experimental)
- Port: 8080
- Purpose: SQL execution and optimization
- Responsibilities:
- SQL query execution
- Query optimization
- Result caching
- Performance monitoring
- Technology: Python, Ibis framework
- Port: 8000
- Purpose: Data source abstraction
- Responsibilities:
- Multi-database connectivity
- Schema introspection
- Query translation
- Metadata extraction
sequenceDiagram
participant User as User
participant UI as Wren UI
participant AI as AI Service
participant Engine as Wren Engine
participant Vector as Qdrant
participant LLM as LLM Provider
participant DS as Data Source
User->>UI: Natural language query
UI->>AI: POST /v1/asks
Note over AI: Query Processing Pipeline
AI->>Vector: Retrieve schema context
Vector-->>AI: Relevant schema documents
AI->>Vector: Retrieve similar questions
Vector-->>AI: Historical Q&A pairs
AI->>LLM: Generate SQL with context
LLM-->>AI: SQL query + reasoning
AI->>Engine: Validate SQL
Engine-->>AI: Validation result
AI-->>UI: SQL + explanation
UI->>Engine: Execute SQL
Engine->>DS: Query execution
DS-->>Engine: Results
Engine-->>UI: Formatted results
UI-->>User: Visualization + data
sequenceDiagram
participant User as User
participant UI as Wren UI
participant Ibis as Ibis Server
participant AI as AI Service
participant Vector as Qdrant
participant DS as Data Source
User->>UI: Connect data source
UI->>Ibis: GET /v1/ibis/metadata
Ibis->>DS: Schema introspection
DS-->>Ibis: Schema metadata
Ibis-->>UI: Structured schema
UI->>UI: Visual modeling
User->>UI: Define relationships
UI->>AI: POST /v1/semantics-preparations
Note over AI: MDL Processing
AI->>AI: Parse MDL schema
AI->>AI: Generate documents
AI->>Vector: Store embeddings
Vector-->>AI: Indexing complete
AI-->>UI: Deployment success
- Purpose: Semantic search and embeddings storage
- Port: 6333
- Data Types:
- Schema embeddings
- Historical question embeddings
- Metadata for filtering
Document Types:
# Schema Documents
{
"type": "TABLE_SCHEMA",
"name": "table_name",
"content": "CREATE TABLE...",
"meta": {
"project_id": "uuid",
"type": "TABLE"
}
}
# Q&A Documents
{
"type": "QA_PAIR",
"question": "natural language",
"sql": "SELECT...",
"meta": {
"project_id": "uuid"
}
}
- Purpose: Application metadata and configuration
- Tables:
- Projects and data sources
- Models and relationships
- User queries and threads
- Dashboard configurations
- Technology: Redis-compatible caching
- Purpose: Query result caching and session management
graph TB
subgraph "Communication Patterns"
subgraph "Synchronous"
HTTP[HTTP/REST APIs]
GQL[GraphQL Queries]
GRPC[gRPC Calls]
end
subgraph "Asynchronous"
QUEUE[Task Queues]
EVENTS[Event Streaming]
WEBHOOK[Webhooks]
end
end
subgraph "Service Mesh"
UI_SVC[UI Service<br/>:3000]
AI_SVC[AI Service<br/>:5555]
ENGINE_SVC[Engine Service<br/>:8080]
IBIS_SVC[Ibis Service<br/>:8000]
VECTOR_SVC[Vector Service<br/>:6333]
end
UI_SVC -->|GraphQL| AI_SVC
UI_SVC -->|REST| ENGINE_SVC
UI_SVC -->|REST| IBIS_SVC
AI_SVC -->|HTTP| VECTOR_SVC
AI_SVC -->|REST| ENGINE_SVC
style UI_SVC fill:#e3f2fd
style AI_SVC fill:#fff3e0
style ENGINE_SVC fill:#f3e5f5
style VECTOR_SVC fill:#e8f5e8
Endpoint: /api/graphql
type Query {
# Data source management
dataSources: [DataSource!]!
# Model management
models: [Model!]!
relationships: [Relationship!]!
# Query interface
threads: [Thread!]!
askingTask(taskId: ID!): AskingTask
}
type Mutation {
# Data modeling
createModel(data: CreateModelInput!): Model!
updateModel(where: ModelWhereUniqueInput!, data: UpdateModelInput!): Model!
# Query execution
createThread(data: CreateThreadInput!): Thread!
createAsk(data: CreateAskInput!): AskingTask!
}
Base URL: http://localhost:5555/v1
# Key endpoints
POST /asks # Natural language queries
POST /semantics-preparations # Schema deployment
GET /asks/{id} # Query status
POST /sql-explanations # SQL explanations
graph TB
subgraph "Docker Compose Stack"
subgraph "Application Containers"
UI_CONTAINER[wren-ui<br/>Node.js Container]
AI_CONTAINER[wren-ai-service<br/>Python Container]
ENGINE_CONTAINER[wren-engine<br/>Java/Rust Container]
IBIS_CONTAINER[ibis-server<br/>Python Container]
end
subgraph "Data Containers"
QDRANT_CONTAINER[qdrant<br/>Vector DB Container]
BOOTSTRAP_CONTAINER[bootstrap<br/>Init Container]
end
subgraph "Volumes"
DATA_VOLUME[data<br/>Persistent Volume]
CONFIG_VOLUME[config<br/>Configuration Volume]
end
end
subgraph "External"
DATASOURCES_EXT[External Data Sources]
LLM_EXT[LLM Providers]
end
UI_CONTAINER --> AI_CONTAINER
AI_CONTAINER --> ENGINE_CONTAINER
AI_CONTAINER --> QDRANT_CONTAINER
ENGINE_CONTAINER --> DATASOURCES_EXT
AI_CONTAINER --> LLM_EXT
DATA_VOLUME --> QDRANT_CONTAINER
DATA_VOLUME --> UI_CONTAINER
CONFIG_VOLUME --> AI_CONTAINER
style UI_CONTAINER fill:#e3f2fd
style AI_CONTAINER fill:#fff3e0
style QDRANT_CONTAINER fill:#e8f5e8
# Core service ports
WREN_UI_PORT: 3000
WREN_AI_SERVICE_PORT: 5555
WREN_ENGINE_PORT: 8080
IBIS_SERVER_PORT: 8000
QDRANT_PORT: 6333
# Service endpoints
WREN_AI_ENDPOINT: http://wren-ai-service:5555
WREN_ENGINE_ENDPOINT: http://wren-engine:8080
IBIS_SERVER_ENDPOINT: http://ibis-server:8000
QDRANT_HOST: wren-qdrant
# AI Configuration
OPENAI_API_KEY: sk-...
GENERATION_MODEL: gpt-4o-mini
EMBEDDING_MODEL: text-embedding-3-small
# Database
DB_TYPE: sqlite
SQLITE_FILE: /app/data/db.sqlite3
docker/docker-compose.yaml
- Service orchestrationdocker/.env.example
- Environment templatewren-ai-service/config.yaml
- AI service configurationwren-ui/next.config.js
- UI build configuration
graph TB
subgraph "Security Layers"
subgraph "Network Security"
NETWORK[Internal Network<br/>Docker Bridge]
FIREWALL[Port Restrictions]
TLS[TLS/SSL Encryption]
end
subgraph "Authentication"
API_KEY[API Key Management]
SESSION[Session Management]
CORS[CORS Configuration]
end
subgraph "Data Security"
ENCRYPTION[Data Encryption]
SANITIZATION[Input Sanitization]
VALIDATION[Schema Validation]
end
end
subgraph "External Security"
LLM_AUTH[LLM Provider Auth]
DB_AUTH[Database Authentication]
SECRETS[Secret Management]
end
NETWORK --> API_KEY
API_KEY --> ENCRYPTION
ENCRYPTION --> LLM_AUTH
ENCRYPTION --> DB_AUTH
style NETWORK fill:#e3f2fd
style ENCRYPTION fill:#e8f5e8
style LLM_AUTH fill:#fce4ec
- Network Isolation: Services communicate through internal Docker network
- API Security: Request validation and rate limiting
- Data Protection: Sensitive data encryption at rest and in transit
- Secret Management: Environment-based secret configuration
- Input Validation: SQL injection prevention and input sanitization
graph LR
subgraph "Multi-Level Caching"
L1[L1: Browser Cache<br/>Static Assets]
L2[L2: Application Cache<br/>Query Results]
L3[L3: Database Cache<br/>Metadata]
L4[L4: Vector Cache<br/>Embeddings]
end
REQUEST[User Request] --> L1
L1 --> L2
L2 --> L3
L3 --> L4
L4 --> DATABASE[Database Query]
style L1 fill:#e3f2fd
style L2 fill:#fff3e0
style L3 fill:#f3e5f5
style L4 fill:#e8f5e8
- Horizontal Scaling: Stateless service design
- Load Balancing: Container orchestration support
- Resource Optimization: Efficient memory and CPU usage
- Query Optimization: Intelligent SQL optimization
- Vector Search: Optimized semantic search with Qdrant
graph TB
subgraph "Observability Stack"
METRICS[Metrics Collection<br/>Performance Data]
LOGS[Centralized Logging<br/>Application Logs]
TRACES[Distributed Tracing<br/>Request Flows]
HEALTH[Health Checks<br/>Service Status]
end
subgraph "Analytics"
POSTHOG[PostHog Analytics<br/>User Behavior]
LANGFUSE[Langfuse<br/>LLM Observability]
CUSTOM[Custom Metrics<br/>Business Logic]
end
METRICS --> POSTHOG
LOGS --> LANGFUSE
TRACES --> CUSTOM
style METRICS fill:#e3f2fd
style POSTHOG fill:#fff3e0
style LANGFUSE fill:#e8f5e8
- Supported Databases:
- Google BigQuery
- PostgreSQL / MySQL
- Snowflake
- ClickHouse
- SQL Server / Oracle
- Amazon Athena / Redshift
- DuckDB
- OpenAI: GPT-4, GPT-3.5, Embeddings
- Custom Providers: Configurable LLM endpoints
- Embedding Models: Text-embedding-3-small/large
- Vector Database: Qdrant for semantic search
- Analytics: PostHog for user behavior tracking
- Observability: Langfuse for LLM monitoring
graph LR
subgraph "Development Environment"
DEV_UI[UI Development<br/>yarn dev]
DEV_AI[AI Service<br/>python -m src.__main__]
DEV_ENGINE[Engine Service<br/>Docker]
DEV_VECTOR[Vector DB<br/>Docker]
end
subgraph "Testing"
UNIT[Unit Tests<br/>pytest, jest]
INTEGRATION[Integration Tests<br/>API Testing]
E2E[E2E Tests<br/>Playwright]
end
subgraph "Deployment"
BUILD[Container Build<br/>Docker Images]
DEPLOY[Deployment<br/>Docker Compose]
MONITOR[Monitoring<br/>Health Checks]
end
DEV_UI --> UNIT
DEV_AI --> INTEGRATION
UNIT --> E2E
E2E --> BUILD
BUILD --> DEPLOY
DEPLOY --> MONITOR
style DEV_UI fill:#e3f2fd
style BUILD fill:#e8f5e8
style DEPLOY fill:#fff3e0
Component | Technology | Purpose |
---|---|---|
Frontend | Next.js 14, React, TypeScript | User interface |
AI Service | Python, FastAPI, Hamilton | AI/ML processing |
Engine | Java/Rust | SQL execution |
Vector DB | Qdrant | Semantic search |
Database | SQLite/PostgreSQL | Metadata storage |
Orchestration | Docker Compose | Service management |
API | GraphQL, REST | Service communication |
Authentication | API Keys, Sessions | Security |
Monitoring | PostHog, Langfuse | Observability |
WrenAI's architecture is designed for:
- Scalability: Microservices architecture with container orchestration
- Extensibility: Plugin-based data source and LLM provider support
- Performance: Multi-level caching and optimized query processing
- Security: Network isolation and data protection
- Observability: Comprehensive monitoring and analytics
- Developer Experience: Clear separation of concerns and modern tooling
The architecture supports both development and production environments with flexible deployment options and comprehensive monitoring capabilities.