MALI TERMINAL
System Architecture
Next.js frontend, FastAPI intelligence layer, GLM/DeepSeek LLM providers. Most AI tabs call the providers from Next.js; the rest go through the backend's gemini_service.py.
Request Flow
Debate, forecast, screen (and data for brief, flow)
Next.js /api/ai/*
proxyToPython() / pythonAIResult(), as the signed-in user
→
DeepSeek / GLM
Frontend — Next.js 16
- AI Intelligence workspace tabs (brief, debate, regime, screener, causality, options, compliance, autopilot, ensemble, chart, flow, backtest, platform)
- Dashboard Shell with its workspaces and sub-tabs
- AI routes (src/app/api/ai/*): autopilot, causality, options and regime call the model providers directly through llm(); debate, forecast, screen, brief and flow also ask the Python backend
- Provider order in Next.js: DeepSeek, then Zhipu (GLM), then Google and OpenAI where keys exist (AI_PROVIDER_ORDER overrides it)
Python Backend — FastAPI
- gemini_service.py: unified LLM router — DeepSeek V3 (heavy), GLM-4.7 (fallback), GLM-4.6V-Flash (vision), GLM-4.5-Flash (light)
- AI capability modules in ai_capabilities/ (chart, autopilot, voice, RAG, brief, debate, regime, screener, causality, options, onboarding, explainability, adaptive UI, backtesting, alt data, compliance, flow, ensemble, memory)
- CrewAI multi-agent framework: peer reviewer, research analyst, quant agents
- ai_capabilities_routes.py: the backend's /api/ai/* endpoints
AI Providers
- DeepSeek V3 at api.deepseek.com — first choice in both Next.js and the backend
- GLM-4.5-Flash at open.bigmodel.cn — the Next.js AI tabs' fallback, and the backend's light tasks
- GLM-4.7 — the backend's heavy-task fallback only (gemini_service.py); the Next.js AI tabs don't use it
- GLM-4.6V-Flash — chart image analysis, tried first since DeepSeek has no vision model
- Gemini and OpenAI — tried after Zhipu in Next.js where the deployment has keys (AI_PROVIDER_ORDER can change the order)
Data & Infrastructure
- PostgreSQL — SQLAlchemy models for the backend and a Drizzle schema for Next.js
- DragonflyDB (Redis-compatible) — caching, rate limiting, SSE pub/sub
- ChromaDB — vector store for RAG and agent long-term memory
- Schema changes: Alembic migrations for the backend, Drizzle migrations for Next.js