Skip to content

Modules

Source paths are relative to src/middleware_forge/ unless they start with ui/, template/, tests/ or scripts/. The code is on GitHub.

Backend packages

api: HTTP layer

Module Responsibility
api/app.py create_app(): middleware, exception handlers, routers. lifespan validates configuration, marks interrupted runs, starts the retention loop and stops the job pools on shutdown.
api/middleware.py ApiKeyMiddleware (constant-time check of X-Forge-Api-Key, /health* exempt) and RequestIdMiddleware (accepts or generates X-Request-ID and binds it to the logs).
api/errors.py Uniform 422 bodies for validation errors and ValueError.
api/routers/sessions.py Session, document, message, event-stream, plan, approval and run endpoints. Thin: everything goes to SessionService.
api/routers/runs.py Run history, snapshot, run SSE, artifacts (list, file, ZIP), resume and cancel.
api/routers/repository.py Repository list, preview, diff and apply.
api/routers/meta.py, health.py Enum documentation; liveness and readiness probes.

services: use cases

Module Responsibility
services/sessions.py SessionService: sessions, documents (add_document classifies each file's role), the versioned plan (save_plan, edit_plan, plan_view), approval (approve), runs (start_run, cancel_run, rerun_preview), chat messages and session events. session_issues and decisions add session-level blockers and questions to plan validation. It listens to run progress and turns run outcomes into chat messages.
services/plan_ops.py Deterministic plan editing and validation: apply_patch (all plan operations), effective_groups / effective_business_services (defaults when the plan has none), validate_plan, blocking_messages.
services/planning.py extract_plan: the first plan for a set of documents (LLM suggestion, then facts read from the documents, then explicit values). infer_artifact_type, mark_confirmed.
services/grouping.py Grouping suggestions (single, by path segment, by tag/port type, by source document) and propose_groups_from_text, which validates an LLM grouping against the operation catalog.
services/runs.py prepare_run (context, checklist, run_started), plan_to_graph_input, execute_graph, execute_confirmed_plan, resume_run, continue_interrupted_run, and the CLI entry points start_structured_run / start_prompt_run.
services/jobs.py Two thread pools: generation runs (one per run id at a time) and session turns (one at a time per session).
services/repository/ config.py (FORGE_REPOS model), git.py (GitRunner: credentials through GIT_ASKPASS, redacted errors), changes.py (RepositoryService: preview, diff, apply, manifest), providers.py (pull requests on Azure DevOps Server and GitHub).
services/uploads.py, downloads.py Server-controlled upload storage; artifact listing, reading and ZIP for a run (only files the run wrote, inside its folder).
services/retention.py purge_expired_data: deletes old runs, idle sessions, orphan uploads, temp files and checkpoints.
services/session_events.py SessionEventBus: in-process fan-out of session events to SSE subscribers.

agent: LangGraph graphs

Module Responsibility
agent/session_agent.py The turn graph ingest → interpret → act → respond (build_turn_graph, run_turn). TurnInterpretation is the JSON contract the LLM fills: an intent, plan operations, an optional grouping request and a reply.
agent/graph.py The generation graph (build_graph) and route_after_validate, which picks the branch (OSB, documents, .NET stub) and sets the run's checklist.
agent/nodes/intake.py parse_document (metadata, layout, unit fingerprints, previous run), validate_document, human_review (interrupt for missing documents), stub_dotnet.
agent/nodes/generate.py One node per artifact family, each running its units through a UnitRunner; write_output, final_validate, generate_documentation, summarize_run.
agent/nodes/common.py tracked (publishes node start/finish/failure), artifact_kind, artifact merging helpers.
agent/graph_cache.py Compiles each graph once per process with its SQLite checkpointer.
agent/state.py AgentState, the generation graph's state.

generators: artifacts

Module Responsibility
generators/layout.py resolve_layout (plan + metadata → OsbLayout with every proxy, pipeline, route, schema contract and business service resolved), generation units (planned_units, xslt_units, run_units, UnitRunner, diff_units) and RunCancelled.
generators/composition.py OSB composition rules: build_routes (routes per business service with forwarded headers), split_routes (routing-table cases and default), assign_contracts (which schema defines each operation of each proxy: own, reused or reduced).
generators/xsd_deps.py Dependencies between the global components of an XSD: dependency_closure, covers_schema (does importing the schema expose anything unused?) and extract_definitions (an element with the types it needs).
generators/artifacts.py Per-unit artifact functions: business service, base pipeline, pipeline, proxy, XSLT, documents; persist_artifacts, run_final_validation.
generators/builders.py Deterministic builders: build_wsdl, build_xsd, build_wadl, build_xslt, build_openapi, plus example values used by the documentation samples.
generators/templates.py TemplateRenderer: fills template/{project_name}/ files; every value is XML-escaped. Pipelines are assembled from the route fragments in Pipelines/_fragments/ (direct route or routing table).
generators/llm_xml.py LLMXmlGenerator: builder first, then the LLM critique loop when the output fails validation.
generators/validate.py, xml_quality.py Artifact validation and cross-references (validate_artifacts), and the completeness checks used inside the LLM loop.
generators/strategy.py, context.py Which strategy an artifact kind uses; per-node trace collection (collect_traces).
generators/writer.py, xmlsafe.py Writing files only inside the output folder; XML escaping and NCName helpers.
generators/docs/ Documentation: solution_model.py reads the generated files back into a model (including routes and schema contracts); consumer.py gathers what a consumer needs per proxy (endpoints, authentication, headers, examples, OpenAPI); icd.py fills the ICD template and writes the consumer guide; docx_writer.py (technical design), postman.py, soapui.py and samples.py (request/response examples).

parsers: documents

Module Responsibility
parsers/detect.py detect_document_type from extension and content; INTERFACE_RANK for choosing the primary document.
parsers/inspect.py inspect_document (typed ServiceMetadata, merged across interface documents) and inspect_source (planning facts: protocol, SOAP version, namespace, operations); validate_metadata (missing schemas).
parsers/openapi.py, wsdl.py, wadl.py, xsd.py Format parsers producing operations with fields, parameters, responses and contracts.
parsers/schemas.py Resolving schemaLocation references, including stale or flattened paths; staging uploaded XSDs next to the document.
parsers/icd.py, db_mapping.py Text extraction from PDF/Word specifications; the DB-mapping stub.
parsers/registry.py Dispatches a document type to its parser.

llm, models, progress, persistence and cross-cutting modules

Module Responsibility
llm/client.py LiteLLMClient (OpenAI-compatible completion with timeout in a worker thread) and the LLMClient protocol that tests replace.
llm/structured.py complete_structured: JSON-schema reply validated by a Pydantic model, with one repair round.
llm/prompts.py Prompts for the XML fallback and PLAN_OPERATIONS_GUIDE, shared by every prompt that produces plan operations.
models/plan.py Plan operations (PlanPatchOp), ProxyGroup, BusinessServiceSpec, PlanIssue, and the resolved OsbLayout.
models/domain.py GenerationPlan, PlannedOperation, ServiceMetadata and the parsed contract models.
models/enums.py Input enums (ServiceType, DocumentType, SoapVersion, ArtifactType) with case-insensitive parsing and aliases.
models/requests.py, responses.py CLI run inputs, ResumeRequest, run command replies, the meta-types response.
progress/broker.py, models.py ProgressBroker: run snapshots, checklist, cancellation flags and SSE fan-out, written through to the run store; checklist_for defines each output type's steps.
persistence/ Database (SQLite WAL, Alembic migrations at startup), RunStore, SessionStore, RepoChangeStore, SQLAlchemy models.
config.py, startup.py Settings and their derived paths; startup validation.
container.py AppContainer: the LLM client, parsers, XML generator, templates, broker, and lazily the session and repository services. Tests replace it with set_container.
logging_setup.py, naming.py Text or JSON logging with request/session/run ids; safe names, ids, file names and path containment.
cli/app.py, cli/runner.py The middleware-forge command and its live progress view.

Web UI (ui/src/MiddlewareForge.Web)

Folder / file Responsibility
Program.cs Services, the typed ForgeApiClient with a resilience pipeline, the long-lived event-stream client, Data Protection keys, and the /download/... endpoints that stream artifacts through the UI server.
Services/ForgeApiClient.cs, Contracts.cs Typed API calls and the JSON contracts (snake_case). The contracts are checked against fixtures captured from the real API.
Services/SessionEventStream.cs SSE reader with Last-Event-ID resume and exponential backoff.
Services/WorkspaceState.cs State of the open task per browser circuit, refreshed from events.
Services/DesignerModel.cs The Service Designer's editable model: operations can belong to several proxies (Assign, Unassign, MoveMembership), routes per proxy (RoutesOf); produces the set_groups and other plan operations on save.
Services/StageModel.cs Lifecycle stages shown on the Progress tab, derived only from backend state.
Components/Pages Generation tasks, the workspace, execution history, system status.
Components/Workspace Chat and the Overview, Documents, Designer, Progress, Artifacts, Repository and Settings tabs.

Other folders

Folder Contents
template/{project_name}/ OSB 12c templates with {placeholder} tokens: REST and SOAP proxy and business service, the pipeline, its route fragments, the base pipeline and CommonSchema.xsd
template/docs/ The Interface Control Document template
example/ Sample specifications and the reference OSB project example/OSB/TravelService (also the examples for the LLM fallback)
deploy/ Container environment example, IIS web.config, the smoke-test compose overlay
scripts/ Mock backend, stub LLM server, UI fixture capture, end-to-end smoke test
tests/ pytest suite; tests/_support has the mock and scripted LLMs, git helpers and test-only helpers; tests/fixtures the test documents
ui/tests/ bUnit and contract tests for the web UI