A FastAPI service that orchestrates a LangGraph workflow to generate Mermaid flowcharts with the help of OpenAI models. The app plans, scores, and iterates on each flowchart, exports the final diagrams as both Mermaid source and PNG images, and bundles the results in a downloadable zip file.
- Multi-node LangGraph pipeline that plans, generates, critiques, and routes flowchart creation (
src/nodes.py). - FastAPI endpoints for health checks and a
/download-zipendpoint that returns Mermaid and PNG assets. - Automated diagram rendering that posts Mermaid definitions to the Kroki API and stores the images locally.
- Configurable topics, difficulty steps, and LLM models through
src/constants.pyandsrc/config.py.
- Planner: creates detailed instructions for a flowchart topic at a given difficulty.
- Evaluation Sheet: derives scoring criteria for the requested flow.
- Generator: produces Mermaid syntax from the planner guidance.
- Reflector: scores the diagram and feeds revisions back into the loop when it misses the quality bar.
- Router: cycles through topics and difficulty tiers until enough diagrams are produced.
- Image Export: writes Markdown and Mermaid files, renders them to PNG via Kroki, and returns the file list to the API layer.
The orchestration graph is defined in src/main.py, while the shared state object lives in src/state.py.
- Python 3.12+
- An OpenAI API key with access to the configured models (
gpt-4o,o4-miniby default) curlavailable on the machine (used to call the Kroki rendering service)- Recommended: uv for dependency management
# Clone the repository
git clone https://github.com/jorgemunozl/Synthetic-Data.git
cd Synthetic-Data
# Install uv (one-time)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync
# Ensure output directories exist
mkdir -p flowcharts Mermaids imagesCreate a .env file (or export variables in your shell) with at least:
OPENAI_API_KEY=sk-...
uv run uvicorn src.main:app --reloadOnce the server is running on http://localhost:8000, you can:
GET /healthcheck– confirm the service is ready.POST /download-zip– trigger flowchart generation. The request body expects:The current workflow ignores the free-form prompt list and instead iterates through the topics and difficulty tiers configured in{ "prompt": ["write documentation", "publish release notes"], "difficulty": 1 }src/constants.py. The response streams agenerated_files.zipattachment containing:images/*.png– rendered diagrams.mermaid/*.mmd– raw Mermaid sources.
Example request:
curl -X POST "http://localhost:8000/download-zip" \
-H "Content-Type: application/json" \
-d '{"prompt":["prepare mise en place"],"difficulty":1}' \
--output generated_files.zip- Topics & Difficulty: adjust
topics,dif, and export directories insrc/constants.py. - Model configuration: tweak
GraphConfigdefaults (model names, temperature, recursion limits) insrc/config.py. - Prompts: update the language used by each LangChain node in
src/prompts.py. - Asset folders: the service writes to
flowcharts/,Mermaids/, andimages/. Modify the paths insrc/constants.pyif you want to point elsewhere.
The repository includes a Dockerfile and docker-compose.yml. To build and run the service:
docker compose up --buildIf you run the image manually, make sure the command points at the FastAPI app module:
docker build -t synthetic-flowcharts .
docker run --rm -p 8000:8000 --env-file .env synthetic-flowcharts \
uv run -- uvicorn src.main:app --host 0.0.0.0 --port 8000- Use
uv run pytest(or the Makefile targets) after you add tests. - Kroki calls require outbound network access; if you are working offline you can skip the image step by mocking
convert_mmd_to_png. - The workflow stores intermediate text in
flowcharts/andMermaids/. Clean them out as needed during development.