# evolutionary-algorithms-on-click/evocv2_llm_microservice architecture

> Architecture diagram of the GitHub repository evolutionary-algorithms-on-click/evocv2_llm_microservice, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/evolutionary-algorithms-on-click/evocv2_llm_microservice
- Repository: https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice

## Overview

#### Purpose and runtime
EVOC DEAP Agent is a Python 3.11+ FastAPI service that generates, modifies, and repairs DEAP evolutionary-algorithm notebooks. Its central output constraint is a purely functional, fixed 12-cell Jupyter notebook. The ASGI entry point is `app/main.py`; container deployment is defined by `Dockerfile` and `docker-compose.yml`.

#### API boundary
HTTP endpoints separate the three user operations:
- Generate a complete notebook from structured JSON: `app/routes/generate.py`
- Modify an existing notebook from natural-language instructions: `app/routes/modify.py`
- Fix notebook/code failures from traceback context: `app/routes/fix.py`

`app/main.py` mounts these routes and exposes service/health behavior. Request and response schemas are centralized in `app/models.py`, providing the typed boundary between arbitrary client JSON and internal workflows.

#### Request normalization and specifications
`app/core/request_parser.py` converts flexible incoming JSON into the application’s canonical generation specification, preserving unrecognized fields as LLM-facing supplemental requirements. Runtime configuration, including API credentials and model settings, is sourced through `app/config.py` and environment values such as the Groq key.

#### LangGraph orchestration
`app/graph.py` defines the stateful LangGraph workflow used by generate, modify, and fix flows. It coordinates agent stages, validation/revision loops, and workflow state rather than allowing routes to invoke LLM logic directly. Shared state and session context are maintained through `app/memory.py`, which integrates Mem0 for history and user preferences.

#### Agent layer and structured LLM boundary
Mode-specific agents implement the substantive transformations:
- Initial notebook construction: `app/agents/generator.py`
- Targeted notebook edits: `app/agents/modifier.py`
- Error-driven code repair: `app/agents/fixer.py`

Their prompts are isolated by operation in `app/prompts/generator.py`, `app/prompts/modifier.py`, and `app/prompts/fixer.py`. LLM calls use Groq-compatible inference and Instructor/Pydantic-style structured outputs, so model responses are expected as validated data rather than markdown or free-form notebook text.

#### Notebook assembly and dependency correctness
`app/core/llm_cell_generator.py` turns model-generated content into the mandated cell-oriented representation. It enforces generation around the architecture’s 12 semantic stages: imports, problem setup, DEAP creator definitions, evaluation/operators, initialization, toolbox registration, evolution loop, and results. Dependency and ordering support spans `app/core/llm_cell_generator.py` and `app/utils/cell_names.py`, enabling hybrid static and LLM-informed detection when code is changed or repaired.

#### Export boundary and artifacts
The internal notebook/cell model is rendered into Jupyter-compatible artifacts by `app/utils/notebook_exporter.py`. Generated outputs may also be exported as Python, as illustrated by `test_outputs/test_tsp_problem.ipynb` and `test_outputs/test_tsp_problem.py`. The service’s external contract is therefore structured API input/output, with notebook serialization confined to the export layer rather than API route handlers.

Main entry points: [`app/graph.py`](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/graph.py) (LangGraph workflow), [`app/core/llm_cell_generator.py`](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/core/llm_cell_generator.py) (Cell assembly), [`app/main.py`](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/main.py) (ASGI application), [`app/routes/generate.py`](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/generate.py) (Generate endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_main{{"ASGI application<br/>FastAPI entry point<br/>[main.py]"}}
  node_generate_route["Generate endpoint<br/>HTTP route<br/>[generate.py]"]
  node_modify_route["Modify endpoint<br/>HTTP route<br/>[modify.py]"]
  node_fix_route["Fix endpoint<br/>HTTP route<br/>[fix.py]"]
  node_schemas["Request/response schemas<br/>Pydantic models<br/>[models.py]"]
end

subgraph group_workflow["Workflow & agents"]
  node_request_parser["Request normalization<br/>specification parser<br/>[request_parser.py]"]
  node_workflow_graph{{"LangGraph workflow<br/>stateful orchestrator<br/>[graph.py]"}}
  node_memory[("Session memory<br/>Mem0 context<br/>[memory.py]")]
  node_config["Runtime configuration<br/>environment settings<br/>[config.py]"]
  node_generator["Generation agent<br/>notebook construction agent<br/>[generator.py]"]
  node_modifier["Modification agent<br/>notebook edit agent<br/>[modifier.py]"]
  node_fixer["Repair agent<br/>[fixer.py]"]
  node_prompts["Operation prompts<br/>agent prompt set<br/>[generator.py]"]
end

subgraph group_notebook["Notebook pipeline"]
  node_cell_generator["Cell assembly<br/>12-stage cell generator"]
  node_cell_names["Dependency ordering<br/>cell dependency analysis<br/>[cell_names.py]"]
  node_exporter["Notebook exporter<br/>artifact renderer"]
end

node_deployment["Container deployment<br/>Docker deployment"]
node_compose["Compose environment<br/>container orchestration<br/>[docker-compose.yml]"]
node_notebook_artifact["Notebook artifacts<br/>Jupyter/Python output"]

node_compose -->|"builds"| node_deployment
node_deployment -->|"runs"| node_main
node_main -->|"mounts"| node_generate_route
node_main -->|"mounts"| node_modify_route
node_main -->|"mounts"| node_fix_route
node_generate_route -->|"validates with"| node_schemas
node_modify_route -->|"validates with"| node_schemas
node_fix_route -->|"validates with"| node_schemas
node_generate_route -->|"normalizes input"| node_request_parser
node_generate_route -->|"starts generate flow"| node_workflow_graph
node_modify_route -->|"starts modify flow"| node_workflow_graph
node_fix_route -->|"starts repair flow"| node_workflow_graph
node_workflow_graph -->|"uses context"| node_memory
node_workflow_graph -->|"dispatches generate"| node_generator
node_workflow_graph -->|"dispatches modify"| node_modifier
node_workflow_graph -->|"dispatches repair"| node_fixer
node_generator -->|"uses"| node_prompts
node_generator -->|"uses model settings"| node_config
node_modifier -->|"uses model settings"| node_config
node_fixer -->|"uses model settings"| node_config
node_generator -->|"produces cells"| node_cell_generator
node_modifier -->|"updates cells"| node_cell_generator
node_fixer -->|"repairs cells"| node_cell_generator
node_cell_generator -->|"checks dependencies"| node_cell_names
node_cell_generator -->|"passes cell model"| node_exporter
node_exporter -->|"renders"| node_notebook_artifact

click node_deployment "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/tree/main/Dockerfile"
click node_compose "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/docker-compose.yml"
click node_main "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/main.py"
click node_generate_route "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/generate.py"
click node_modify_route "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/modify.py"
click node_fix_route "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/fix.py"
click node_schemas "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/models.py"
click node_request_parser "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/core/request_parser.py"
click node_workflow_graph "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/graph.py"
click node_memory "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/memory.py"
click node_config "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/config.py"
click node_generator "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/agents/generator.py"
click node_modifier "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/agents/modifier.py"
click node_fixer "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/agents/fixer.py"
click node_prompts "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/prompts/generator.py"
click node_cell_generator "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/core/llm_cell_generator.py"
click node_cell_names "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/utils/cell_names.py"
click node_exporter "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/utils/notebook_exporter.py"
click node_notebook_artifact "https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/test_outputs/test_tsp_problem.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_generate_route,node_modify_route,node_fix_route,node_schemas toneBlue
class node_request_parser,node_workflow_graph,node_memory,node_config,node_generator,node_modifier,node_fixer,node_prompts toneAmber
class node_cell_generator,node_cell_names,node_exporter toneMint
class node_deployment,node_compose,node_notebook_artifact toneNeutral
```

## Components

### HTTP API

- [ASGI application](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/main.py): FastAPI entry point · Mounts API routes and exposes health behavior. · `app/main.py`
- [Generate endpoint](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/generate.py): HTTP route · `app/routes/generate.py`
- [Modify endpoint](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/modify.py): HTTP route · `app/routes/modify.py`
- [Fix endpoint](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/routes/fix.py): HTTP route · `app/routes/fix.py`
- [Request/response schemas](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/models.py): Pydantic models · Typed boundary for client JSON and workflow results. · `app/models.py`

### Workflow & agents

- [Request normalization](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/core/request_parser.py): specification parser · Converts flexible JSON into a canonical generation specification. · `app/core/request_parser.py`
- [LangGraph workflow](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/graph.py): stateful orchestrator · Coordinates mode-specific stages and validation/revision loops. · `app/graph.py`
- [Session memory](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/memory.py): Mem0 context · Maintains history and user preferences. · `app/memory.py`
- [Runtime configuration](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/config.py): environment settings · Loads Groq credentials and model settings. · `app/config.py`
- [Generation agent](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/agents/generator.py): notebook construction agent · `app/agents/generator.py`
- [Modification agent](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/agents/modifier.py): notebook edit agent · `app/agents/modifier.py`
- [Repair agent](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/agents/fixer.py): error repair agent · `app/agents/fixer.py`
- [Operation prompts](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/prompts/generator.py): agent prompt set · Separate prompts guide generation, modification, and repair. · `app/prompts/generator.py`

### Notebook pipeline

- [Cell assembly](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/core/llm_cell_generator.py): 12-stage cell generator · Builds the required functional 12-cell notebook representation. · `app/core/llm_cell_generator.py`
- [Dependency ordering](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/utils/cell_names.py): cell dependency analysis · Supports static and LLM-informed code-change ordering. · `app/utils/cell_names.py`
- [Notebook exporter](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/app/utils/notebook_exporter.py): artifact renderer · Serializes the internal model as Jupyter notebooks or Python. · `app/utils/notebook_exporter.py`

### Other components

- [Container deployment](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/tree/main/Dockerfile): Docker deployment · Runs the ASGI service with environment configuration. · `Dockerfile`
- [Compose environment](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/docker-compose.yml): container orchestration · `docker-compose.yml`
- [Notebook artifacts](https://github.com/evolutionary-algorithms-on-click/evocv2_llm_microservice/blob/main/test_outputs/test_tsp_problem.ipynb): Jupyter/Python output · `test_outputs/test_tsp_problem.ipynb`

## Connections

- Compose environment → Container deployment: builds
- Container deployment → ASGI application: runs
- ASGI application → Generate endpoint: mounts
- ASGI application → Modify endpoint: mounts
- ASGI application → Fix endpoint: mounts
- Generate endpoint → Request/response schemas: validates with
- Modify endpoint → Request/response schemas: validates with
- Fix endpoint → Request/response schemas: validates with
- Generate endpoint → Request normalization: normalizes input
- Generate endpoint → LangGraph workflow: starts generate flow
- Modify endpoint → LangGraph workflow: starts modify flow
- Fix endpoint → LangGraph workflow: starts repair flow
- LangGraph workflow → Session memory: uses context
- LangGraph workflow → Generation agent: dispatches generate
- LangGraph workflow → Modification agent: dispatches modify
- LangGraph workflow → Repair agent: dispatches repair
- Generation agent → Operation prompts: uses
- Generation agent → Runtime configuration: uses model settings
- Modification agent → Runtime configuration: uses model settings
- Repair agent → Runtime configuration: uses model settings
- Generation agent → Cell assembly: produces cells
- Modification agent → Cell assembly: updates cells
- Repair agent → Cell assembly: repairs cells
- Cell assembly → Dependency ordering: checks dependencies
- Cell assembly → Notebook exporter: passes cell model
- Notebook exporter → Notebook artifacts: renders
