This file is intended for AI coding assistants (Cursor, Copilot, etc.) and human contributors alike. It describes the repository layout, toolchain, and conventions needed to make changes safely.
m_flow/ Python core (FastAPI + pipeline engine)
api/ HTTP routers: add, memorize, search, delete, …
cli/ CLI entrypoint (`mflow`)
adapters/ DB adapters (graph, vector, cache)
llm/ LLM providers, prompts, structured output
core/ Domain models (Episode, Facet, FacetPoint, …)
memory/ Memory processing (episodic, procedural)
retrieval/ Search & retrieval algorithms
pipeline/ Composable pipeline tasks & orchestration
auth/ Authentication & multi-tenancy
eval/ Evaluation harnesses & adapters
shared/ Logging, settings, loaders, cross-cutting utilities
tests/ Pytest suite (unit / integration / CLI)
m_flow-frontend/ Next.js console (pnpm)
m_flow-mcp/ MCP server — exposes memory as tool calls
mflow_workers/ Modal / worker helpers for distributed runs
examples/ Runnable demo scripts (Python, notebooks)
alembic/ SQL migration scripts (Alembic)
- New data source → add a loader under
shared/loaders/ - New pipeline step → add a task under
pipeline/ - New graph DB → implement the adapter interface in
adapters/graph/ - New vector store → implement adapter in
adapters/vector/ - New LLM provider → extend
llm/LLMGateway.py
# Bootstrap
uv sync --dev --all-extras --reinstall
# Run the API server
uv run python -m m_flow.api.client
# CLI quick-start
uv run mflow add "M-flow builds structured memory for agents."
uv run mflow memorize
uv run mflow search "How does M-flow work?"
uv run mflow -ui # launches backend + frontend + MCPcd m_flow-frontend
pnpm install
pnpm dev # http://localhost:3000
pnpm lint && pnpm buildcd m_flow-mcp
uv sync --dev --all-extras
uv run python src/server.py # stdio
uv run python src/server.py --transport sse # SSE modeSee m_flow-mcp/README.md for Docker and API-mode options.
PYTHONPATH=. uv run pytest m_flow/tests/unit/ -v # ~963 test cases
PYTHONPATH=. uv run pytest m_flow/tests/integration/ -v # needs .env keysTest layout:
| Directory | Scope |
|---|---|
m_flow/tests/unit/ |
Pure-logic, no network |
m_flow/tests/integration/ |
Requires LLM / DB credentials |
m_flow/tests/cli_tests/ |
CLI smoke tests |
uv run ruff check . # lint (line-length 100, see pyproject.toml)
uv run ruff format . # auto-format
uv run mypy m_flow/ # optional type-checkCI (.github/workflows/) runs the same commands; passing locally ≈ passing CI.
| Aspect | Rule |
|---|---|
| Indentation | 4 spaces (Python), 2 spaces (TS/YAML) |
| Naming | snake_case functions/modules, PascalCase classes |
| Type hints | Required on public API signatures |
| Error handling | Structured; use m_flow.shared.logging_utils |
| Imports | Sorted by ruff; no wildcard imports |
Follow Conventional Commits:
feat(graph): add temporal edge weighting
fix(api): handle missing auth cookie
docs: update installation instructions
- Branch from
dev. - Include scope, local test commands run, and any UI/MCP impacts.
- Sign commits (
git commit -s) and affirm the DCO (seeCONTRIBUTING.md). - PR titles are validated by CI (
pr_lintworkflow).
docker compose up # backend only
docker compose --profile ui up # backend + frontend
docker compose --profile neo4j up # backend + Neo4jEnvironment variables are documented in .env.template.