An ultra-lightweight, modular MLOps pipeline and API Gateway designed for intelligent model routing, local developer productivity, zero-PyTorch low-latency ONNX inference, and strict resource constraints.
Mesh-Mind combines a high-concurrency Go API Gateway with decoupled Python ONNX microservices and an interactive Go Terminal CLI. It features smart model routing, multi-stage container optimization, zero runtime PyTorch dependencies, and dual-layer SQLite state management.
┌─────────────────────────────────────────────────────────────────┐
│ LOCAL CLIENT │
│ │
│ Mesh-Mind CLI (Go + Cobra) │
│ └── Storage: Local SQLite (~/.mesh-mind/config.db) │
│ ├── Settings (Gateway URL, Saved JWT Token) │
│ └── Prediction History & Latency Logs │
└────────────────────────────────┬────────────────────────────────┘
│
│ HTTP POST /api/v1/predict
│ Body: { "text": "...", "model": "auto" }
▼
┌─────────────────────────────────────────────────────────────────┐
│ CLOUD / SERVER │
│ │
│ Go API Gateway & Router (Port 8080) │
│ ├── JWT Authentication Middleware │
│ ├── Dynamic Router Engine (Auto-Detect vs. Explicit Override) │
│ └── Storage: Server SQLite (/data/gateway.db) │
│ └── User Credentials (bcrypt) & Activity Logs │
└────────────────────────────────┬────────────────────────────────┘
│
┌─────────────┴─────────────┐
▼ ▼
┌────────────────────────────┐ ┌────────────────────────────┐
│ Python ONNX Sentiment │ │ Python ONNX Intent/Emotion │
│ Model Worker (256MB Limit) │ │ Model Worker (512MB Limit) │
│ └── Pure onnxruntime + │ │ └── Pure onnxruntime + │
│ tokenizers (No PyTorch)│ │ tokenizers (No PyTorch)│
└────────────────────────────┘ └────────────────────────────┘
-
⚡ Zero-PyTorch Runtime Inference: Model workers run on pure C++ backends (
onnxruntime+ Rust-backedtokenizers), dropping runtime memory usage dramatically while serving low-latency CPU predictions. -
📦 Multi-Stage Container Optimization: PyTorch is used strictly during model conversion (
export_models.py) to convert Hugging Face checkpoints to ONNX. Production worker images contain zero PyTorch/Torchvision binaries. -
🔀 Smart & Explicit Model Forwarding: Go Gateway parses input text to route requests to the appropriate ONNX worker (
model-sentimentvs.model-intent) or accepts target overrides (--model). -
🧠 Real Dynamic Logit Decoding: Workers calculate softmax probability distributions over ONNX output tensors in real time and map class IDs to human-readable strings using dynamic
id2labeldictionary parsing with built-in fallbacks. -
🏥 Production Healthchecks & Startup Synchronization: Docker Compose monitors FastAPI worker readiness via Uvicorn HTTP probes (
python3 -c urllib), preventing gateway cold-start connection race conditions. -
💻 Interactive Terminal CLI: Built with Go + Cobra for developer workflows.
-
💾 Dual-Layer SQLite Persistence:
-
Client-Side (
~/.mesh-mind/config.db): Stores JWT tokens, server configuration, and local prediction history. -
Server-Side (
/data/gateway.db): Handles user registration,bcryptpassword hashing, and audit logs. -
🛡️ Calibrated Container Memory Allocations: Stack resource limits are finely tuned (64MB for Go Gateway, 256MB for MiniLM Sentiment, 512MB for BERT Emotion) to prevent OOM kills during initial model tensor load.
.
├── cmd/
│ └── mesh-mind/ # Binary entrypoint for the CLI
├── internal/ # Shared CLI internal modules
│ ├── cli/ # Cobra commands (register, login, predict, history, config)
│ ├── config/ # Pure Go SQLite initialization (modernc.org/sqlite)
│ └── store/ # Local SQLite Data Access Objects
├── gateway/ # Go API Gateway & Dynamic Router
│ ├── internal/auth/ # JWT authentication middleware
│ ├── internal/handlers/ # Predict & HTTP forwarding handlers
│ └── internal/db/ # Server SQLite schema & user repository
├── models/ # Python ONNX inference services
│ ├── app.py # Zero-PyTorch FastAPI worker (onnxruntime + tokenizers)
│ ├── export_models.py # ONNX export script (MiniLM SST-2 & BERT Emotion)
│ ├── requirements-export.txt # Export tooling dependencies (Optimum + Transformers)
│ ├── requirements-runtime.txt# Production worker dependencies (ONNXRuntime + Fast Tokenizers)
│ └── Dockerfile # Parameterized multi-stage container build
├── docker-compose.yml # Microservice orchestration, healthchecks & limits
└── README.md
- Go (v1.21 or higher)
- Docker & Docker Compose
Spin up the Go Gateway and zero-PyTorch Python workers in containerized microservices:
# Build and run containers in detached mode
docker compose up -d --build
Verify service readiness and container health status:
docker compose ps
Expected output:
NAME SERVICE STATUS
mesh-mind-gateway-1 gateway Up (healthy)
mesh-mind-model-sentiment-1 model-sentiment Up (healthy)
mesh-mind-model-intent-1 model-intent Up (healthy)
Compile the CLI binary:
go build -o mesh-mind ./cmd/mesh-mind
./mesh-mind config set-url http://localhost:8080
# Output: ✔ Gateway URL set to: http://localhost:8080
# Register a new account
./mesh-mind register -u devuser -p supersecret123
# Output: ✔ Account created successfully!
# Log in and store JWT locally
./mesh-mind login -u devuser -p supersecret123
# Output: ✔ Login successful!
# Output: ✔ JWT token saved to local SQLite database (~/.mesh-mind/config.db)
The Gateway automatically evaluates the query and forwards it to the sentiment worker:
./mesh-mind predict "I hate Milk"
# 🧠 Model Response:
# {"text":"I hate Milk","model_used":"onnx-sentiment-v1","sentiment":"negative","latency_ms":54.48}
./mesh-mind predict "I love milk"
# 🧠 Model Response:
# {"text":"I love milk","model_used":"onnx-sentiment-v1","sentiment":"positive","latency_ms":3.12}
Force execution against the BERT Emotion/Intent classification microservice (model-intent):
./mesh-mind predict "How do I reset my account password?" --model intent
# 🧠 Model Response:
# {"text":"How do I reset my account password?","model_used":"onnx-intent-v1","intent":"anger","latency_ms":179.96}
Watch incoming HTTP requests and ONNX runtime executions in real time:
docker compose logs -f gateway model-sentiment model-intent
Check live RAM utilization across running containers:
docker stats
- Password Security: User passwords are hashed using
bcrypton the Go Gateway before storage. - Stateless Authorization: Routes are secured using JWT bearer tokens (HS256).
- Development Auth Bypass: Set
DISABLE_AUTH=truein gateway environment settings to bypass login during rapid testing.
Distributed under the MIT License. See LICENSE for details.