# baobabsoluciones/cornflow architecture

> Architecture diagram of the GitHub repository baobabsoluciones/cornflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baobabsoluciones/cornflow
- Repository: https://github.com/baobabsoluciones/cornflow

## Overview

##### Project type and purpose
- This is a monorepo for “cornflow,” an open-source, optimization-deployment platform.
- It comprises three main deliverables:
a. A server (cornflow-server) exposing a JSON/REST API for problem definitions, solution execution, and result retrieval.
b. A set of Airflow DAGs (cornflow-dags) that orchestrate the execution of optimization problems using different solver libraries.
c. A Python client library and CLI (libs/client) that users integrate into their code or use interactively.

##### File structure
- Top-level modules:
- cornflow-server/ – the backend monolith (API definitions, ORM models, CLI, migrations, tests)
- cornflow-dags/ – Airflow DAG definitions, per-problem schemas, data, solver wrappers
- libs/client/ – client SDK and command-line tool to consume the server API or trigger DAGs
- docs/ – Sphinx-based documentation, including architecture and deployment guides
- docker-compose*.yml & Github workflows – container orchestration and CI/CD pipelines
- Architectural cues:
- REST endpoints under server/cornflow/endpoints
- Database models under server/cornflow/models + alembic migrations
- JSONSchema definitions in DAG schemas for input/output validation
- Airflow plugins and scripts under airflow_config

##### README for additional insights
- It stresses JSONSchema-driven, technique-agnostic problem definitions.
- It outlines use cases: local testing, adding new solvers, private server deployment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        ClientSDK["Python Client SDK"]:::frontend
        ClientCLI["Client CLI (entry point)"]:::frontend
        ClientHelpers["Airflow Helpers"]:::frontend
        ClientSchema["Schema Management"]:::frontend
        ClientCore["Core Classes"]:::frontend
    end

    %% Server Layer
    subgraph "API Layer"
        direction TB
        API_Server["API Server"]:::service
        Endpoints["HTTP/REST Endpoints"]:::service
        Models["ORM Models & Persistence"]:::service
        Schemas["JSON-Schema Definitions"]:::service
        Migrations["Alembic Migrations"]:::service
        CLI_Server["Server CLI & Commands"]:::service
        Plugins["Airflow Config & Plugins"]:::service
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DB["Relational Database"]:::db
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        Scheduler["Airflow Scheduler & Workers"]:::service
    end

    %% Airflow DAGs
    subgraph "Airflow DAG Definitions"
        direction TB
        DAGs["DAGs Directory"]:::service
        AutoScripts["Auto-Scripts & Utilities"]:::service
        subgraph "Bar Cutting Problem"
            direction TB
            BarCore["Core Logic"]:::plugin
            BarData["Sample Data"]:::plugin
            BarSchemas["I/O Schemas"]:::plugin
            BarSolvers["Solver Wrappers"]:::plugin
        end
    end

    %% Solver Engines
    subgraph "Solver Engines"
        direction TB
        ORTools["OR-Tools, Pyomo, Heuristics"]:::plugin
    end

    %% Infrastructure
    subgraph "Infrastructure & DevOps"
        direction TB
        Docker["Docker & Compose"]:::infra
        CD["CI/CD Workflows"]:::infra
        Docs["Project Documentation"]:::infra
    end

    %% Connections
    ClientSDK -->|"HTTPS/JSON"| API_Server
    ClientCLI -->|"HTTPS/JSON"| API_Server
    ClientHelpers -->|"HTTPS/JSON"| API_Server
    ClientSchema -->|"HTTPS/JSON"| API_Server
    ClientCore -->|"HTTPS/JSON"| API_Server

    API_Server --> Endpoints
    API_Server --> Models
    API_Server --> Schemas
    API_Server --> Migrations
    API_Server --> CLI_Server
    API_Server --> Plugins
    API_Server -->|"SQL queries"| DB
    API_Server -->|"REST trigger"| Scheduler
    Scheduler -->|"Load DAGs"| DAGs
    Scheduler --> AutoScripts
    DAGs --> BarCore
    DAGs --> BarData
    DAGs --> BarSchemas
    DAGs --> BarSolvers
    BarSolvers --> ORTools
    BarCore -->|"Write solution"| DB
    Scheduler -->|"Task execution"| ORTools
    Scheduler -->|"Callback"| API_Server

    Docker --> API_Server
    Docker --> Scheduler
    Docker --> DB
    CD --> Docker
    Docs -.-> API_Server
    Docs -.-> Scheduler

    %% Click Events
    click ClientSDK "https://github.com/baobabsoluciones/cornflow/tree/master/libs/client/cornflow_client/"
    click ClientCLI "https://github.com/baobabsoluciones/cornflow/blob/master/libs/client/setup.py"
    click ClientHelpers "https://github.com/baobabsoluciones/cornflow/blob/master/libs/client/cornflow_client/airflow/api.py"
    click ClientSchema "https://github.com/baobabsoluciones/cornflow/tree/master/libs/client/cornflow_client/schema/"
    click ClientCore "https://github.com/baobabsoluciones/cornflow/tree/master/libs/client/cornflow_client/core/"
    click API_Server "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/"
    click Endpoints "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/cornflow/endpoints/"
    click Models "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/cornflow/models/"
    click Schemas "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/cornflow/schemas/"
    click Migrations "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/cornflow/migrations/"
    click CLI_Server "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/cornflow/cli/"
    click Plugins "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-server/airflow_config/"
    click DAGs "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-dags/DAG/"
    click AutoScripts "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-dags/DAG/auto_scripts/"
    click BarCore "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-dags/DAG/bar_cutting/core/"
    click BarData "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-dags/DAG/bar_cutting/data/"
    click BarSchemas "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-dags/DAG/bar_cutting/schemas/"
    click BarSolvers "https://github.com/baobabsoluciones/cornflow/tree/master/cornflow-dags/DAG/bar_cutting/solvers/"
    click Docker "https://github.com/baobabsoluciones/cornflow/blob/master/docker-compose.yml"
    click CD "https://github.com/baobabsoluciones/cornflow/blob/master/.github/workflows/ci.yml"
    click Docs "https://github.com/baobabsoluciones/cornflow/blob/master/docs/source/main/architecture.rst"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px
    classDef service fill:#bbf,stroke:#333,stroke-width:1px
    classDef db fill:#afa,stroke:#333,stroke-width:1px,shape:cylinder
    classDef plugin fill:#dba,stroke:#333,stroke-width:1px
    classDef infra fill:#ccc,stroke:#333,stroke-width:1px
```
