Local AI Microservice Mesh Context
Documents a local AI microservice mesh architecture, request flow, configuration hierarchy, and developer scripts for an intent-based routing gateway.
What this file does
Documents a local AI microservice mesh architecture, request flow, configuration hierarchy, and developer scripts for an intent-based routing gateway.
When to use it
- Onboarding to the docker-compose-ai-gateway project
- Understanding request routing and training pipeline
- Setting up local development with Ollama integration
- Debugging configuration or script usage
Assumes this stack
Local AI Microservice Mesh Context
This document provides full, deep context awareness for AI agents working on the docker-compose-ai-gateway project. It summarizes the architecture, developer workflow, configuration hierarchy, and key operational concepts.
System Architecture & Request Flow
The system is a locally runnable, multi-container microservice mesh where an AI
classifier (ai_router) predicts backend routing based on natural language
intent.
- Gateway: Serves the UI, applies routing policy (
T_ROUTE,T_MARGIN), proxies requests, and aggregates application-level traces. - AI Router: Lightweight intent classifier (TF-IDF + Logistic Regression).
Returns
route,confidence,probabilities, andexplanation(top contributing tokens). - Backends:
search_service,image_service,ops_service. - Trainer Profile: One-shot container that trains
model.joblibfromtrain.csvand outputsmetrics.jsonandmisclassified.csvto a shared volume (model_artifacts). - Refiner Profile / Training API: Improves the dataset via relabeling and
augmenting using Ollama (phi3:mini). Orchestrated via the
training-api. - Redis: Maintains job states and handles Pub/Sub for Server-Sent Events (SSE) to send completion events to the UI.
Configuration & Environment Variables
Configuration follows a rigid hierarchy to ensure reproducibility:
- Source of Truth:
config/PROJECT_CONFIG.yaml(containsdefault,dev, etc. environment sections). - Generation:
scripts/generate_env.pyreadsdefault.ENV(fallbackdev) unless an explicit<env>is passed, then createsenv/.env.<env>. - Consumption: Docker compose files reference the generated
.envfile via theenv_filedirective.
Critical Note: Never hardcode configuration in code or Compose. Edit
PROJECT_CONFIG.yaml and regenerate the env files.
Local LLM Integration (Ollama)
The Refiner relies on Ollama for dataset improvement. Two modes are supported,
defined in OLLAMA_MODE:
native: Connects to Ollama running on the host machine.container: Spins up anollamacontainer alongside the stack via therefine-containerprofile.
Key Developer Scripts
The scripts/demo.sh script is the primary control plane for local operations.
- Start Stack:
./scripts/demo.sh run [--dev](uses dev overlay for reload) - Stop/Teardown:
./scripts/demo.sh stop,restart,delete, orreset(full teardown and rebuild) - Testing:
./scripts/demo.sh test [all|gateway|ai_router]or rawpytest - Train Route:
./scripts/demo.sh train - Refiner Route:
./scripts/demo.sh refine(runs relabel & augment), followed by./scripts/demo.sh promote(promotes candidate if better). - Standalone refine:
scripts/refine_relabel.shandscripts/refine_augment.shfor running phases outsidedemo.sh. - Other utilities:
logs,scaling,failure,curl,load-test.
Technical Policies for Agents
- Routing Thresholds: AI Router returns raw probabilities. The Gateway
enforces the actual routing via
T_ROUTE(minimum confidence) andT_MARGIN(gap between top 2 routes). Do not implement policy in the model code. - One-Shot Training: Training is intentionally not a long-running API. The
trainercontainer spins up, readstrain.csv, writesmodel.joblib, and terminates. - Security rules: All operations are offline. Respect structural bounds
and do not run
catin bash to write files. Always utilizesnyk_code_scanfor new lines of code.
[!TIP] Always review
docs/auxiliary/architecture/TECHNICAL.mdbefore making structural changes to the AI router or gateway.
What's inside
7 sections covering architecture, config hierarchy, Ollama modes, 12 developer scripts, and 3 technical policies
Change this for your project
- Replace
docker-compose-ai-gatewaywith your project name - Replace
config/PROJECT_CONFIG.yamlwith your config path - Replace
scripts/demo.shwith your control script - Replace
phi3:miniwith your Ollama model
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- One-shot training container that writes artifacts to a shared volume
- Configuration hierarchy with a single source of truth YAML and env file generation
- Gateway-enforced routing thresholds separate from model code
Related Documents
PCB Design Sources for Industry-Scale Testing
Lists GitHub repos and communities where you can download real PCB designs for testing optimization at scale.
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.