Repository navigation
Infrastructure
Internet / Browser
│
▼
nginx (:3001) ←── entry point for all traffic
│
├── /api/v1/* ────────────► FastAPI (:8000)
│ /ws/* │
│ ┌───────┴────────┐
│ SQLite DB GPU semaphore
│ (trichome.db) (max 1 concurrent)
│
└── /* ────────────────► Next.js (:3000)
│
React components
@tanstack/react-query
zustand state
native WebSockets
Docker services (optional — annotation profile):
├── Label Studio (:3005)
├── CVAT (:3006)
└── PostgreSQL (:5432, internal only)
MLflow (:3004) ←── started by dev-start.sh (uvicorn, not Docker)
CTIP ships a user-space nginx config at nginx-local/nginx.conf.
No root required — runs as your user, PID stored in nginx-local/nginx.pid.
server {
listen 3001;
server_name your-domain.com localhost _;
# API proxy
location /api/v1/ {
limit_req zone=api burst=60 nodelay;
proxy_pass http://127.0.0.1:8000;
proxy_read_timeout 300s;
}
# WebSocket proxy
location ~ ^/(ws|api/v1/ws)/ {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 3600s;
}
# Frontend (Next.js with HMR support)
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 3600s;
}
}To expose CTIP on a public domain:
- Set in
.env:PUBLIC_DOMAIN=mylab.ddns.net - In nginx config, change
server_nameto your domain - Add SSL (Let's Encrypt recommended):
sudo certbot --nginx -d mylab.ddns.net- Forward port 3001 in your router to the machine running CTIP
# Start
nginx -c "$(pwd)/nginx-local/nginx.conf"
# Reload config without downtime
kill -HUP $(cat nginx-local/nginx.pid)
# Stop
kill $(cat nginx-local/nginx.pid)
# Check config syntax
nginx -t -c "$(pwd)/nginx-local/nginx.conf"Entry point: backend/main.py
# Startup sequence (lifespan)
1. Directories created (DATA_ROOT, MODELS_DIR, OUTPUTS_DIR)
2. Database initialized (SQLite via SQLModel)
3. GPU broadcast loop started (WebSocket heartbeat)
4. asyncio.Semaphore(1) created (GPU guard)
# Router structure
/api/v1/
setup/ # Installation wizard endpoints
detection/ # YOLO inference
segmentation/ # SAM2 inference
maturity/ # Trichome maturity classification
training/ # Training job management
annotation/ # Label Studio integration
analytics/ # Aggregated statistics
system/ # Health, GPU status
/ws/
training # Live training metrics
system # GPU/RAM usage stream
jobs # Background job progress
logs # Live log stream# backend/middleware/gpu_guard.py
_GPU_SEMAPHORE = asyncio.Semaphore(1)
async def with_gpu(fn, *args):
async with _GPU_SEMAPHORE:
return await fn(*args)Only one GPU task runs at a time. Subsequent requests wait in queue. This is intentional for RTX 4060 (8 GB VRAM) — prevents OOM crashes.
# Annotation stack (Label Studio + CVAT + PostgreSQL)
docker compose --profile annotation up -d
# Training stack (GPU YOLO trainer)
docker compose -f docker-compose.yml -f docker-compose.training.yml up -d
# Inference-only (no frontend, no annotation)
docker compose -f docker-compose.inference.yml up -d| Container | Host port | Container port | Service |
|---|---|---|---|
| nginx | 3001 | 80 | Reverse proxy |
| backend | 3002 | 8000 | FastAPI |
| frontend | 3003 | 3000 | Next.js |
| mlflow | 3004 | 5000 | MLflow |
| label-studio | 3005 | 8080 | Label Studio |
| cvat | 3006 | 8080 | CVAT |
| postgres | internal | 5432 | PostgreSQL |
Note: In local dev mode (dev-start.sh), backend is on :8000 directly, not :3002.
# docker/docker-compose.yml (annotation profile)
label-studio:
image: heartexlabs/label-studio:1.13.1
ports:
- "3005:8080"
volumes:
- ls-data:/label-studio/data
environment:
- LABEL_STUDIO_HOST=http://localhost:3005Label Studio stores all projects, tasks, and annotations in the ls-data volume.
Backup this volume before updates.
# Location
trichome.db # in REPO_ROOT (created on startup)
# Schema managed by SQLModel (auto-migration on startup)
# Tables:
# annotation_task — pending/approved/rejected VLM annotations
# training_run — training job records
# inference_result — stored detection results
# calibration — µm/px scale factors per microscopeFor production with multiple users, switch to PostgreSQL:
DATABASE_URL="postgresql://user:pass@localhost:5432/ctip"Started by dev-start.sh using:
mlflow ui --host 0.0.0.0 --port 3004 --backend-store-uri ./mlrunsAll training runs automatically log to MLflow:
- Hyperparameters
- mAP@0.5, mAP@0.5:0.95
- Loss curves (box, cls, dfl)
- Model artifacts
Access: http://localhost:3004
./scripts/dev-start.sh # start all
./scripts/dev-start.sh stop # stop all
./scripts/dev-start.sh restart # stop + start
./scripts/dev-start.sh status # show running services
# Logs
tail -f logs/backend.log
tail -f logs/frontend.log
tail -f logs/mlflow.log
tail -f logs/nginx-error.logCTIP — Cannabis Trichome Intelligence Platform · RTX 4060 / 8 GB VRAM · Backend API · MLflow · Label Studio
Installation & Setup
Scientific Workflow
Reference