Deploy MOI: Local Development Setup
This skill automates the complete local development environment setup for MatrixFlow with 6 idempotent stages.
Core Workflow: 6-Stage Pipeline
The deployment follows this sequence (each stage is idempotent):
Stage 1: Environment Diagnostics
- Check Docker and required tools (docker-compose, mysql, python, go, dotnet)
- Validate repo structure and Makefile
- Detect existing containers/processes
- Report current state without making changes
Stage 2: Infrastructure Setup (Docker/Volumes)
- Pull latest container images
- Create persistent volumes (mo_data, redis_data, minio_storage, rmq_data)
- Start infrastructure: MySQL/MatrixOne, Redis, MinIO, RabbitMQ, UNO server
- Wait for health checks to pass
Stage 3: Database & Message Queue Initialization
- Load SQL schemas (account, luke, byoa, mocloud_meta, account-local-moi, tpl_init, nl2sql, webhook)
- Create RocketMQ topics (task, connector_job, event, notify_job, load_completion, connect_rpc_event_alert)
- Verify MySQL connectivity
- Confirm MQ topics are created
Stage 4: Build & Start Backend Services
- Build connector-rpc (Go + tRPC)
- Start all backend services in order:
- connector-rpc, augmentation, workflow-scheduler, catalog-service
- license-service, local-service, mock-service, openxml-service
- Log each service start to
tmp/service-name.log
- Note: apiserver and job-consumer often require retry (see Stage 4b below)
Stage 4b: Restart apiserver & job-consumer (if needed)
These services often fail on first attempt due to poetry initialization delays. This stage explicitly restarts them with proper environment setup.
What apiserver does:
- Loads env vars from
optools/matrixflow/.env
- Sets PYTHONPATH to include workflow_be modules
- Runs
poetry install to ensure dependencies are ready
- Starts Python process:
poetry run python3 byoa/main.py
- Logs to
tmp/apiserver.log
- Port: 8000
What job-consumer does:
- Loads env vars from
optools/matrixflow/.env
- Sets PYTHONPATH to include workflow_be modules
- Enables metrics:
JOB_CONSUMER_METRICS_ENABLED=true
- Starts Python process:
poetry run python3 byoa/job_consumer.py
- Logs to
tmp/job-consumer.log
- Runs as background daemon
Retry sequence:
# Option 1: Direct commands (environment-aware)
cd ~/go/src/github.com/matrixorigin/matrixflow
sh start-apiserver.sh # Calls: make start-apiserver DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}
sh start-jobconsumer.sh # Calls: poetry run python3 byoa/job_consumer.py with metrics enabled
# Option 2: Make targets (if scripts unavailable)
cd ~/go/src/github.com/matrixorigin/matrixflow
make start-apiserver
make start-job-consumer # Alternative: may vary by Makefile version
- Wait 5 seconds for services to initialize
- Verify both services appear in
make status with running PIDs
Stage 5: Build & Start Frontend
- Checkout/update moi-frontend repo
- Install pnpm dependencies (suppress deprecation warnings)
- Prebuild/build frontend assets
- Start Vite dev server on port 5173
- Open browser to http://localhost:5173/local-moi-account/dev
Stage 6: Verification & Testing
- Health check: Call GET /auth/login (apiserver)
- Auth test: POST /auth/login with test credentials → extract Access-Token + Refresh-Token
- API key test: GET /user/me/api-key with token → extract new API key
- CLI setup: Update genai-cli.yaml with new API key
- CLI test: Run genai-cli pipeline on a sample document
- MinIO test: Verify bucket structure with mc
- Show final service status dashboard
Quick Start
Full deployment (Stages 1→6):
# Stages 2-3: Infrastructure & DB/MQ init
make start-env && make wait-mo && make init-env
# Stage 4: Start all services
make start
# Stage 4b: Restart apiserver & job-consumer (often needed)
sh start-apiserver.sh && sh start-jobconsumer.sh && make status
# Stage 6: Verify everything works
curl -X POST http://127.0.0.1:8000/auth/login \
-H 'Content-Type: application/json' \
--data-raw '{"account_name":"local-moi-account","username":"admin:accountadmin","password":"123456","type":"workspace"}'
Checkpoint locations:
- After
make start-env → Containers running: docker ps | grep matrixflow
- After
make init-env → DB ready: make status shows databases initialized
- After
make start → Most services up: make status (apiserver/job-consumer may be STOPPED)
- After
sh start-apiserver.sh && sh start-jobconsumer.sh → Full deployment: make status shows all GREEN
User interaction points:
- If MySQL isn't ready, retry
make wait-mo before make init-env
- If apiserver/job-consumer show STOPPED after
make start, run Stage 4b: sh start-apiserver.sh && sh start-jobconsumer.sh
- If frontend build fails, clear node_modules and retry pnpm install
- Check logs:
tail -f tmp/apiserver.log or tail -f tmp/job-consumer.log if services won't start
Troubleshooting Reference
| Problem |
Diagnosis |
Solution |
| Docker containers stuck |
docker ps -a |
make clean-env then restart Stage 2 |
| MySQL connection refused |
mysql -h 127.0.0.1 -P 6001 -u dump -p111 system -e "SHOW DATABASES;" |
Wait longer, then retry init-env |
| Python module not found |
Check logs: tail -f tmp/apiserver.log |
poetry install from workflow_be/src |
| Service port conflict |
lsof -i :8000 (apiserver) |
Kill conflicting process or use different port |
| Frontend build hangs |
tail -f tmp/moi-frontend.log |
Ctrl+C, rm -rf node_modules, retry pnpm install |
| genai-cli fails |
Check .genai-cli.yaml endpoint/api_key |
Run auth login first, update api_key with new token |
Implementation Notes
- Idempotency: Each stage can be re-run safely. Existing services are not killed, new ones are started alongside.
- Concurrency: Some builds (connector-rpc, workflow-scheduler, catalog-service) can run in parallel in Stage 4.
- Logging: All service logs go to
tmp/*.log for debugging.
- State persistence: After Stage 2, volumes preserve data across restarts (
make stop then make start works).
- API key rotation: Auth tokens expire hourly; testing the API key endpoint generates a fresh one.
- Frontend hot-reload: Vite dev server watches for changes; no rebuild needed for frontend tweaks.
Understanding apiserver & job-consumer
Stage 4b exists because these Python services have special startup requirements. They're not always available (script-based environments may use direct commands instead).
See references/apiserver-jobconsumer.md for:
- What these services do (REST API vs async worker)
- Full startup commands and environment setup
- Why they fail and how to debug
- Platform-specific issues (macOS DYLD_LIBRARY_PATH, Linux LD_LIBRARY_PATH)
- Poetry dependency resolution details
- When/how to run them if scripts don't exist
When to Use This Skill
✅ Initial setup — Starting from a fresh clone
✅ After breaking changes — Reinitialized schema or containers crashed
✅ Troubleshooting failures — Diagnose what stage failed and why
✅ Verifying health — Confirm all services are running and talking to each other
✅ Full E2E test — Auth → API key → CLI → document parsing → verify results
✅ Port conflicts — Detect and resolve port clashes with existing processes
❌ Quick service restart — If just one service crashed, use make stop-SERVICE and make start-SERVICE
❌ Code changes — If you only modified a service, rebuild that service directly (e.g., cd connector_rpc && make)
Source: xzxiong/ai-cli — distributed by TomeVault.
1---2name: xzxiong-ai-cli-deploy-moi3description: Deploy MOI: Local Development Setup4---56# Deploy MOI: Local Development Setup78This skill automates the complete local development environment setup for MatrixFlow with 6 idempotent stages.910## Core Workflow: 6-Stage Pipeline1112The deployment follows this sequence (each stage is idempotent):1314### Stage 1: Environment Diagnostics15- Check Docker and required tools (docker-compose, mysql, python, go, dotnet)16- Validate repo structure and Makefile17- Detect existing containers/processes18- Report current state without making changes1920### Stage 2: Infrastructure Setup (Docker/Volumes)21- Pull latest container images22- Create persistent volumes (mo_data, redis_data, minio_storage, rmq_data)23- Start infrastructure: MySQL/MatrixOne, Redis, MinIO, RabbitMQ, UNO server24- Wait for health checks to pass2526### Stage 3: Database & Message Queue Initialization27- Load SQL schemas (account, luke, byoa, mocloud_meta, account-local-moi, tpl_init, nl2sql, webhook)28- Create RocketMQ topics (task, connector_job, event, notify_job, load_completion, connect_rpc_event_alert)29- Verify MySQL connectivity30- Confirm MQ topics are created3132### Stage 4: Build & Start Backend Services33- Build connector-rpc (Go + tRPC)34- Start all backend services in order:35 - connector-rpc, augmentation, workflow-scheduler, catalog-service36 - license-service, local-service, mock-service, openxml-service37- Log each service start to `tmp/service-name.log`38- **Note**: apiserver and job-consumer often require retry (see Stage 4b below)3940### Stage 4b: Restart apiserver & job-consumer (if needed)4142These services often fail on first attempt due to poetry initialization delays. This stage explicitly restarts them with proper environment setup.4344**What apiserver does:**45- Loads env vars from `optools/matrixflow/.env`46- Sets PYTHONPATH to include workflow_be modules47- Runs `poetry install` to ensure dependencies are ready48- Starts Python process: `poetry run python3 byoa/main.py`49- Logs to `tmp/apiserver.log`50- Port: 80005152**What job-consumer does:**53- Loads env vars from `optools/matrixflow/.env`54- Sets PYTHONPATH to include workflow_be modules55- **Enables metrics**: `JOB_CONSUMER_METRICS_ENABLED=true`56- Starts Python process: `poetry run python3 byoa/job_consumer.py`57- Logs to `tmp/job-consumer.log`58- Runs as background daemon5960**Retry sequence:**61```bash62# Option 1: Direct commands (environment-aware)63cd ~/go/src/github.com/matrixorigin/matrixflow64sh start-apiserver.sh # Calls: make start-apiserver DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}65sh start-jobconsumer.sh # Calls: poetry run python3 byoa/job_consumer.py with metrics enabled6667# Option 2: Make targets (if scripts unavailable)68cd ~/go/src/github.com/matrixorigin/matrixflow69make start-apiserver70make start-job-consumer # Alternative: may vary by Makefile version71```7273- Wait 5 seconds for services to initialize74- Verify both services appear in `make status` with running PIDs7576### Stage 5: Build & Start Frontend77- Checkout/update moi-frontend repo78- Install pnpm dependencies (suppress deprecation warnings)79- Prebuild/build frontend assets80- Start Vite dev server on port 517381- Open browser to http://localhost:5173/local-moi-account/dev8283### Stage 6: Verification & Testing84- Health check: Call GET /auth/login (apiserver)85- Auth test: POST /auth/login with test credentials → extract Access-Token + Refresh-Token86- API key test: GET /user/me/api-key with token → extract new API key87- CLI setup: Update genai-cli.yaml with new API key88- CLI test: Run genai-cli pipeline on a sample document89- MinIO test: Verify bucket structure with mc90- Show final service status dashboard9192## Quick Start9394**Full deployment (Stages 1→6):**95```bash96# Stages 2-3: Infrastructure & DB/MQ init97make start-env && make wait-mo && make init-env9899# Stage 4: Start all services100make start101102# Stage 4b: Restart apiserver & job-consumer (often needed)103sh start-apiserver.sh && sh start-jobconsumer.sh && make status104105# Stage 6: Verify everything works106curl -X POST http://127.0.0.1:8000/auth/login \107 -H 'Content-Type: application/json' \108 --data-raw '{"account_name":"local-moi-account","username":"admin:accountadmin","password":"123456","type":"workspace"}'109```110111**Checkpoint locations:**112- After `make start-env` → Containers running: `docker ps | grep matrixflow`113- After `make init-env` → DB ready: `make status` shows databases initialized114- After `make start` → Most services up: `make status` (apiserver/job-consumer may be STOPPED)115- After `sh start-apiserver.sh && sh start-jobconsumer.sh` → Full deployment: `make status` shows all GREEN116117**User interaction points:**118- If MySQL isn't ready, retry `make wait-mo` before `make init-env`119- If apiserver/job-consumer show STOPPED after `make start`, **run Stage 4b**: `sh start-apiserver.sh && sh start-jobconsumer.sh`120- If frontend build fails, clear node_modules and retry pnpm install121- Check logs: `tail -f tmp/apiserver.log` or `tail -f tmp/job-consumer.log` if services won't start122123## Troubleshooting Reference124125| Problem | Diagnosis | Solution |126|---------|-----------|----------|127| Docker containers stuck | `docker ps -a` | `make clean-env` then restart Stage 2 |128| MySQL connection refused | `mysql -h 127.0.0.1 -P 6001 -u dump -p111 system -e "SHOW DATABASES;"` | Wait longer, then retry init-env |129| Python module not found | Check logs: `tail -f tmp/apiserver.log` | `poetry install` from workflow_be/src |130| Service port conflict | `lsof -i :8000` (apiserver) | Kill conflicting process or use different port |131| Frontend build hangs | `tail -f tmp/moi-frontend.log` | Ctrl+C, `rm -rf node_modules`, retry pnpm install |132| genai-cli fails | Check .genai-cli.yaml endpoint/api_key | Run auth login first, update api_key with new token |133134## Implementation Notes135136- **Idempotency**: Each stage can be re-run safely. Existing services are not killed, new ones are started alongside.137- **Concurrency**: Some builds (connector-rpc, workflow-scheduler, catalog-service) can run in parallel in Stage 4.138- **Logging**: All service logs go to `tmp/*.log` for debugging.139- **State persistence**: After Stage 2, volumes preserve data across restarts (`make stop` then `make start` works).140- **API key rotation**: Auth tokens expire hourly; testing the API key endpoint generates a fresh one.141- **Frontend hot-reload**: Vite dev server watches for changes; no rebuild needed for frontend tweaks.142143## Understanding apiserver & job-consumer144145Stage 4b exists because these Python services have special startup requirements. They're not always available (script-based environments may use direct commands instead).146147**See [references/apiserver-jobconsumer.md](./references/apiserver-jobconsumer.md) for:**148- What these services do (REST API vs async worker)149- Full startup commands and environment setup150- Why they fail and how to debug151- Platform-specific issues (macOS DYLD_LIBRARY_PATH, Linux LD_LIBRARY_PATH)152- Poetry dependency resolution details153- When/how to run them if scripts don't exist154155## When to Use This Skill156157✅ **Initial setup** — Starting from a fresh clone158✅ **After breaking changes** — Reinitialized schema or containers crashed159✅ **Troubleshooting failures** — Diagnose what stage failed and why160✅ **Verifying health** — Confirm all services are running and talking to each other161✅ **Full E2E test** — Auth → API key → CLI → document parsing → verify results162✅ **Port conflicts** — Detect and resolve port clashes with existing processes163164❌ **Quick service restart** — If just one service crashed, use `make stop-SERVICE` and `make start-SERVICE`165❌ **Code changes** — If you only modified a service, rebuild that service directly (e.g., `cd connector_rpc && make`)166167---168> Source: [xzxiong/ai-cli](https://github.com/xzxiong/ai-cli) — distributed by [TomeVault](https://tomevault.io).169<!-- tomevault:4.0:skill_md:2026-06-15 -->