High-level system architecture, design patterns, and module structure for the Quantis platform.
- System Architecture
- Architecture Diagram
- Component Overview
- Module Structure
- Data Flow
- Technology Stack
- Design Patterns
- Scalability
- Security Architecture
Quantis follows a microservices architecture with clear separation of concerns. The platform is organized into three main service layers:
- Data Services Layer: Data ingestion, processing, and storage
- Analytical Services Layer: ML models, statistical analysis, predictions
- Presentation Layer: API gateway, web frontend, monitoring
- Microservices: Independent, loosely-coupled services
- API-First: RESTful API as the primary interface
- Event-Driven: Asynchronous processing via message queues
- Stateless: Horizontally scalable, no session affinity required
- Database Per Service: Each service owns its data
- Cloud-Native: Containerized, Kubernetes-ready
┌─────────────────────────────────────────────────────────────────┐
│ Client Layer │
├──────────────────────┬──────────────────────┬───────────────────┤
│ Web Dashboard │ Mobile App │ API Clients │
│ (React/TypeScript) │ (Planned) │ (Python/JS) │
└──────────┬───────────┴──────────────────────┴───────────┬───────┘
│ │
│ HTTPS / WebSocket │
│ │
┌──────────▼───────────────────────────────────────────────▼───────┐
│ API Gateway Layer │
├────────────────────────────────────────────────────────────────-─┤
│ • FastAPI Application (code/api/app.py) │
│ • Authentication & Authorization │
│ • Rate Limiting & Request Validation │
│ • CORS & Security Headers │
│ • API Documentation (OpenAPI/Swagger) │
└──────────┬───────────────────────────────────────────────┬───────┘
│ │
┌──────────▼───────────────────────────────────────────────▼───────┐
│ Service Layer │
├──────────────────────┬────────────────────┬─────────────────────┤
│ Auth Service │ Model Service │ Data Service │
│ ┌────────────────┐ │ ┌──────────────┐ │ ┌─────────────┐ │
│ │ User Mgmt │ │ │ Training │ │ │ Ingestion │ │
│ │ JWT Tokens │ │ │ Inference │ │ │ Processing │ │
│ │ RBAC │ │ │ Versioning │ │ │ Validation │ │
│ │ Sessions │ │ │ Comparison │ │ │ Storage │ │
│ └────────────────┘ │ └──────────────┘ │ └─────────────┘ │
├──────────────────────┼────────────────────┼─────────────────────┤
│ Financial Service │ Prediction Service │ Monitoring Service │
│ ┌────────────────┐ │ ┌──────────────┐ │ ┌─────────────┐ │
│ │ Transactions │ │ │ Single Pred │ │ │ Metrics │ │
│ │ NPV Calc │ │ │ Batch Pred │ │ │ Health │ │
│ │ Interest │ │ │ History │ │ │ Audit Logs │ │
│ │ Compliance │ │ │ Analytics │ │ │ Alerts │ │
│ └────────────────┘ │ └──────────────┘ │ └─────────────┘ │
└──────────────────────┴────────────────────┴─────────────────────┘
│ │ │
┌──────────▼──────────────────────▼─────────────────────▼───────────┐
│ Data Layer │
├───────────────────┬─────────────────────┬──────────────────────────┤
│ PostgreSQL │ Redis │ Object Storage │
│ ┌─────────────┐ │ ┌───────────────┐ │ ┌──────────────────┐ │
│ │ Users │ │ │ Cache │ │ │ ML Models │ │
│ │ Models │ │ │ Sessions │ │ │ Datasets │ │
│ │ Datasets │ │ │ Rate Limits │ │ │ Artifacts │ │
│ │ Predictions │ │ │ Task Queue │ │ │ Logs │ │
│ │ Transactions│ │ └───────────────┘ │ └──────────────────┘ │
│ │ Audit Logs │ │ │ │
│ └─────────────┘ │ │ │
└───────────────────┴─────────────────────┴──────────────────────────┘
│ │ │
┌──────────▼──────────────────────▼─────────────────────▼───────────┐
│ Infrastructure Layer │
├────────────────────┬────────────────────┬─────────────────────────┤
│ Docker Compose │ Kubernetes │ Monitoring Stack │
│ (Local Dev) │ (Production) │ (Prometheus/Grafana) │
└────────────────────┴────────────────────┴─────────────────────────┘
Purpose: Single entry point for all client requests
Responsibilities:
- Request routing to appropriate services
- Authentication and authorization
- Rate limiting and throttling
- Request/response validation
- API documentation generation
- CORS handling
Key Files:
app.py- Main FastAPI applicationauth.py- Authentication helpersconfig.py- Configuration managementdatabase.py- Database connectionsmodels.py- SQLAlchemy ORM modelsschemas.py- Pydantic validation schemas
Purpose: Business logic implementation for each domain
Modules:
| Module | Purpose | Key Endpoints |
|---|---|---|
auth.py |
Authentication & authorization | Login, register, MFA, API keys |
users.py |
User management | CRUD users, roles, permissions |
datasets.py |
Dataset operations | Upload, stats, preview, download |
models.py |
ML model management | Create, train, compare, metrics |
prediction.py |
Inference service | Single/batch predictions, history |
financial.py |
Financial operations | Transactions, NPV, interest calc |
monitoring.py |
System monitoring | Health, stats, audit logs |
notifications.py |
User notifications | Get, mark read, delete |
websocket.py |
Real-time communication | WebSocket connections |
Purpose: Machine learning training and serving
Components:
train_model.py- Model training logic (LSTM, TFT)mlflow_tracking.py- Experiment tracking integrationaws_deploy.py- Cloud deployment utilitieshyperparameter_tuning/optimize.py- Auto-tuningmodel_serving/serve.py- Model serving endpoints
Purpose: Data transformation and feature engineering
Components:
process_data.py- ETL pipeline with Daskfeatures/- Feature engineering modules
Purpose: Deployment and orchestration
Components:
docker-compose.yml- Local multi-container setupkubernetes/- K8s manifests for productionterraform/- Infrastructure as Code for cloudansible/- Configuration management
Purpose: Observability and alerting
Components:
prometheus.yml- Metrics collection configgrafana_dashboards/- Pre-built dashboardsmodel_monitor.py- ML drift detection
Quantis/
├── code/ # Application code
│ ├── api/ # FastAPI backend
│ │ ├── endpoints/ # API endpoints by domain
│ │ ├── middleware/ # Request/response middleware
│ │ ├── services/ # Business logic layer
│ │ ├── app.py # Main application
│ │ ├── models.py # Database models
│ │ ├── schemas.py # Pydantic schemas
│ │ ├── config.py # Settings management
│ │ ├── database.py # DB connection & sessions
│ │ └── tasks.py # Celery background tasks
│ ├── data/ # Data processing
│ │ ├── process_data.py # ETL pipeline
│ │ └── features/ # Feature engineering
│ ├── models/ # ML models
│ │ ├── train_model.py # Training logic
│ │ ├── mlflow_tracking.py # Experiment tracking
│ │ ├── aws_deploy.py # Cloud deployment
│ │ └── hyperparameter_tuning/ # Auto-tuning
│ └── scripts/ # Utility scripts
├── docs/ # Documentation
├── infrastructure/ # Deployment configs
│ ├── docker-compose.yml # Docker setup
│ ├── kubernetes/ # K8s manifests
│ ├── terraform/ # IaC templates
│ └── ansible/ # Config management
├── monitoring/ # Observability
│ ├── prometheus.yml # Metrics config
│ ├── grafana_dashboards/ # Dashboards
│ └── model_monitor.py # Drift detection
├── scripts/ # Automation scripts
│ ├── setup_quantis_env.sh # Initial setup
│ ├── run_quantis.sh # Start services
│ ├── test_quantis.sh # Run tests
│ └── build_quantis.sh # Build artifacts
├── tests/ # Test suites
│ ├── conftest.py # Test configuration
│ ├── test_api.py # API tests
│ └── requirements-test.txt # Test dependencies
├── web-frontend/ # React application
│ ├── public/ # Static assets
│ ├── src/ # React components
│ └── package.json # Node dependencies
└── README.md # Project overview
User → POST /auth/login
↓
API Gateway (auth.py)
↓
Validate credentials (bcrypt)
↓
Check MFA if enabled (TOTP)
↓
Generate JWT tokens (access + refresh)
↓
Create session record (database)
↓
Log audit event
↓
Return tokens to user
User → POST /models/{id}/train
↓
API Gateway (models.py)
↓
Validate request & auth
↓
Create training task (Celery)
↓
Background Worker:
├─ Load dataset from storage
├─ Preprocess data (scaling, encoding)
├─ Initialize model (LSTM/TFT)
├─ Train model (epochs, batches)
├─ Track metrics (MLflow)
├─ Save model artifacts
└─ Update model status
↓
Return training ID to user
↓
User polls /models/{id}/training-status
User → POST /predict
↓
API Gateway (prediction.py)
↓
Rate limit check (Redis)
↓
Validate input schema (Pydantic)
↓
Load model from cache/storage
↓
Preprocess input data
↓
Run inference (model.predict)
↓
Calculate confidence score
↓
Store prediction record (database)
↓
Log metrics (Prometheus)
↓
Return prediction result
System Event (e.g., training complete)
↓
Create notification record (database)
↓
Publish to WebSocket connections
↓
Active WebSocket clients receive message
↓
Frontend displays notification
↓
User acknowledges (PATCH /notifications/{id}/read)
| Technology | Version | Purpose |
|---|---|---|
| Python | 3.9+ | Primary language |
| FastAPI | 0.109+ | Web framework |
| Uvicorn | 0.27+ | ASGI server |
| SQLAlchemy | 2.0+ | ORM layer |
| Pydantic | 2.5+ | Data validation |
| Celery | 5.3+ | Task queue |
| Redis | 5.0+ | Cache & queue |
| PostgreSQL | 14+ | Relational database |
| Technology | Version | Purpose |
|---|---|---|
| PyTorch | 2.0+ | Deep learning |
| scikit-learn | 1.4+ | Classical ML |
| pandas | 2.2+ | Data manipulation |
| numpy | 1.26+ | Numerical computing |
| Dask | Latest | Parallel processing |
| MLflow | 2.8+ | Experiment tracking |
| Technology | Version | Purpose |
|---|---|---|
| Docker | 20.10+ | Containerization |
| Kubernetes | 1.20+ | Orchestration |
| Terraform | 1.0+ | Infrastructure as Code |
| Ansible | 2.9+ | Configuration management |
| Prometheus | 2.45+ | Metrics collection |
| Grafana | 10.2+ | Visualization |
Used in: Database access layer
# code/api/database.py
class BaseRepository:
def __init__(self, db: Session):
self.db = db
def get(self, id: int):
return self.db.query(Model).filter(Model.id == id).first()
def create(self, obj: dict):
db_obj = Model(**obj)
self.db.add(db_obj)
self.db.commit()
return db_objUsed in: FastAPI endpoints
# code/api/endpoints/users.py
@router.get("/users")
async def get_users(
db: Session = Depends(get_db), # DB injection
current_user = Depends(get_current_user) # Auth injection
):
return db.query(User).all()Used in: Request/response processing
# code/api/middleware/auth.py
class AuthMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
# Pre-processing
token = request.headers.get("Authorization")
# Process request
response = await call_next(request)
# Post-processing
return responseUsed in: Model instantiation
# code/models/train_model.py
def create_model(model_type: str, params: dict):
if model_type == "lstm":
return LSTMModel(**params)
elif model_type == "tft":
return TFTModel(**params)
else:
raise ValueError(f"Unknown model type: {model_type}")Used in: Event-driven notifications
# WebSocket notifications
class NotificationManager:
def __init__(self):
self.subscribers = []
def subscribe(self, websocket):
self.subscribers.append(websocket)
async def notify(self, message):
for subscriber in self.subscribers:
await subscriber.send_json(message)Stateless Design: All API instances are stateless, enabling horizontal scaling
# Kubernetes HorizontalPodAutoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70- Read Replicas: Distribute read load across replicas
- Connection Pooling: Reuse connections efficiently
- Caching: Redis for frequently accessed data
- Partitioning: Table partitioning for large datasets
# Multi-layer caching
┌─────────────┐
│ Redis │ ← Session data, rate limits (TTL: seconds-minutes)
├─────────────┤
│ Application│ ← Model cache, configs (TTL: hours)
├─────────────┤
│ Database │ ← Persistent storage
└─────────────┘Layer 1: Network Security
- Firewall rules
- VPC isolation (cloud deployments)
- TLS/SSL encryption
Layer 2: API Gateway
- Rate limiting
- Input validation
- CORS policies
- Authentication
Layer 3: Application
- JWT token validation
- RBAC enforcement
- SQL injection prevention (ORM)
- XSS protection
Layer 4: Data
- Encrypted at rest (database)
- Encrypted in transit (TLS)
- Audit logging
- Backup encryption
# Password hashing
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
hashed = pwd_context.hash(plain_password)
# JWT with short expiration
token = create_access_token(
data={"sub": user.id},
expires_delta=timedelta(minutes=30)
)
# Rate limiting
@rate_limit(max_requests=100, window_seconds=60)
async def protected_endpoint():
passcode/api/app.py
├─ endpoints/* (API routes)
├─ middleware/* (Request processing)
├─ database.py (DB connections)
├─ models.py (ORM models)
├─ schemas.py (Validation)
└─ config.py (Settings)
code/api/endpoints/*
├─ services/* (Business logic)
├─ middleware/auth.py (Auth checks)
├─ schemas.py (Input/output schemas)
└─ database.py (DB sessions)
code/models/train_model.py
├─ mlflow_tracking.py (Experiment tracking)
├─ data/process_data.py (Data preprocessing)
└─ PyTorch/scikit-learn (ML frameworks)
Application
├─ Structured Logs (structlog) → Log Aggregation
├─ Prometheus Metrics → Prometheus Server → Grafana
├─ MLflow Tracking → MLflow Server
└─ Audit Logs → Database → Compliance Reports