Skip to main content

Architecture Overview

Zygotrix is built on a modern, scalable architecture designed for high-performance genetics computations.

High-Level Architecture

┌─────────────────────────────────────────────────────────────────────────┐
│ CLIENTS │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Web App │ │ Mobile App │ │ API Users │ │
│ │ (React/TS) │ │ (Future) │ │ (curl/SDK) │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
└─────────┼─────────────────┼─────────────────┼───────────────────────────┘
│ │ │
└─────────────────┼─────────────────┘
│ HTTPS

┌─────────────────────────────────────────────────────────────────────────┐
│ BACKEND (FastAPI) │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ API Layer (Routes) │ │
│ │ /auth /traits /genetics /gwas /zygotrix-ai /admin │ │
│ └──────────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌──────────────────────────┼───────────────────────────────┐ │
│ │ Service Layer │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────────┐ │ │
│ │ │ Auth │ │ Traits │ │ GWAS │ │ Claude AI │ │ │
│ │ │ Service │ │ Service │ │ Service │ │ (MCP Tools) │ │ │
│ │ └─────────┘ └─────────┘ └────┬────┘ └─────────────────┘ │ │
│ └───────────────────────────────┼──────────────────────────┘ │
│ │ │
│ ┌───────────────────────────────┼──────────────────────────┐ │
│ │ C++ Engine Layer (subprocess) │ │
│ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │
│ │ │zyg_cross │ │zyg_gwas │ │zyg_protein│ │ │
│ │ │ _cli │ │ _cli │ │ _cli │ │ │
│ │ └───────────┘ └───────────┘ └───────────┘ │ │
│ └──────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ MongoDB │ │ Redis │ │ Cloud Storage│
│ (Primary) │ │ (Cache) │ │ (Files/GWAS) │
└──────────────┘ └──────────────┘ └──────────────┘

Component Overview

Frontend Layer

ComponentTechnologyPurpose
zygotrix_aiReact + TypeScript + ViteAI chatbot interface
zygotrix_universityReact + TypeScriptEducational courses
webReact + TypeScriptMain website

Backend Layer

ComponentTechnologyPurpose
FastAPIPython 3.11+REST API framework
PydanticPythonRequest/response validation
MotorPythonAsync MongoDB driver
aioredisPythonAsync Redis client

C++ Engine Layer

BinaryPurposePerformance
zyg_cross_cliMendelian genetics calculations10x faster than Python
zyg_gwas_cliGWAS statistical analysis50x faster than Python
zyg_protein_cliProtein translation5x faster than Python
zyg_parallel_dna_cliLarge DNA generationParallel processing

Data Layer

StorePurposeData Types
MongoDBPrimary databaseUsers, traits, courses, conversations
RedisCaching & sessionsAuth tokens, rate limits, query cache
DigitalOcean SpacesFile storageGWAS datasets, VCF files

Request Flow

Example: Punnett Square Calculation

sequenceDiagram
participant User
participant FastAPI
participant MendelianService
participant CppEngine
participant MongoDB

User->>FastAPI: POST /api/genetics/cross
FastAPI->>MendelianService: calculate_cross()
MendelianService->>CppEngine: subprocess.run(zyg_cross_cli)
CppEngine-->>MendelianService: JSON result
MendelianService->>MongoDB: Log calculation (optional)
MendelianService-->>FastAPI: CrossResult
FastAPI-->>User: JSON response

Example: AI Chatbot Query

sequenceDiagram
participant User
participant FastAPI
participant ChatService
participant Classifier
participant ClaudeAI
participant MCPTools

User->>FastAPI: POST /api/zygotrix-ai/chat
FastAPI->>ChatService: process_message()
ChatService->>Classifier: classify_query()
Classifier-->>ChatService: "genetics_tools"
ChatService->>ClaudeAI: send_message(with MCP tools)
ClaudeAI->>MCPTools: tool_call: calculate_punnett_square
MCPTools-->>ClaudeAI: tool_result
ClaudeAI-->>ChatService: Response with explanation
ChatService-->>FastAPI: ChatResponse
FastAPI-->>User: JSON response

Key Design Decisions

Why C++ Engine?

GWAS analysis involves matrix operations on potentially millions of SNPs. Python with NumPy would be too slow:

OperationPythonC++ (Eigen)Speedup
10K SNPs linear regression60s3s20x
100K SNPs chi-square5min15s20x
1M SNPs parallelN/A5min

Why Subprocess (not Python bindings)?

  1. Isolation - C++ crash doesn't affect Python process
  2. Debugging - Can run CLI directly for testing
  3. Simplicity - JSON in/out, no complex bindings
  4. Deployment - Just copy binary, no compilation on server

Why Claude AI with MCP?

  1. Tool Use - Claude natively calls Zygotrix tools
  2. Context - Maintains conversation history
  3. Accuracy - Better genetics knowledge than base models
  4. Streaming - Real-time response generation

Directory Structure

Zygotrix/
├── backend/ # Python FastAPI backend
│ ├── app/
│ │ ├── routes/ # API endpoints
│ │ ├── services/ # Business logic
│ │ ├── repositories/ # Data access
│ │ ├── schema/ # Pydantic models
│ │ ├── mcp/ # MCP tool integration
│ │ └── chatbot_tools/ # AI chatbot tools
│ └── .env.example
├── zygotrix_ai/ # React AI chatbot frontend
├── zygotrix_engine_cpp/ # C++ high-performance engine
│ ├── src/ # C++ source files
│ ├── include/ # Header files
│ ├── build/ # Compiled binaries
│ └── third_party/ # Eigen, json11
├── zygotrix_university/ # Educational platform
└── zygotrix_docs/ # This documentation

Next Steps