# cmudig/draco2 architecture

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

- Interactive diagram: https://gitdiagram.com/cmudig/draco2
- Repository: https://github.com/cmudig/draco2

## Overview

##### Main Components

a) Core Components:
- ASP (Answer Set Programming) Engine
- Constraints Module
- Generator Module
- Optimizer Module
- Learning System
- Renderer System
- Server Component
- API Layer

b) External Dependencies:
- Clingo Solver Integration
- Altair Visualization Library

##### Specific Elements

a) Input Processing:
- Data flow from input facts
- Schema validation
- Fact utilities

b) Processing Pipeline:
- Constraint application
- Solution generation
- Optimization

c) Output Generation:
- Renderer system (Altair)
- Visualization output

##### Key Relationships to Highlight

- API endpoints and their connections to internal services
- Integration points with external systems
- Learning system's interaction with constraints

##### Important Details

- ASP constraint files location and relationship
- Test infrastructure
- Documentation system
- Learning system components
- Server architecture (FastAPI routes and services)

##### Specific Implementation Notes

- The modular nature of the system (separate modules for ASP, learning, rendering)
- The server architecture with clear separation of routers and services
- The extensible renderer system with Altair implementation
- The integration of the learning system with the constraint solver

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef processing fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef data fill:#F0E68C,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        API[API Layer]:::api
        ServerComp[Server Component]:::api
        APIModels[API Models]:::api
        ServerServices[Server Services]:::api
    end

    %% Core Processing Layer
    subgraph CoreLayer
        CoreEngine[Core Engine]:::core
        SchemaDefinitions[Schema Definitions]:::core
        
        subgraph LearningSystem
            Learn[Learning System]:::processing
        end
        
        subgraph RendererSystem
            Renderer[Renderer System]:::processing
            AltairRenderer[Altair Renderer]:::processing
        end
    end

    %% ASP Layer
    subgraph ASPLayer
        subgraph ASPEngine
            Constraints[Constraints Module]:::processing
            Generator[Generator Module]:::processing
            Optimizer[Optimizer Module]:::processing
            HardConstraints[Hard Constraints]:::processing
            SoftConstraints[Soft Constraints]:::processing
            Weights[Weight Definitions]:::processing
        end
        
        ClingoSolver[Clingo Solver]:::external
        Altair[Altair Library]:::external
    end

    %% Relationships
    API --> ServerComp
    ServerComp --> ServerServices
    ServerComp --> APIModels
    ServerServices --> CoreEngine
    CoreEngine --> SchemaDefinitions
    CoreEngine --> Learn
    CoreEngine --> Renderer
    Renderer --> AltairRenderer
    AltairRenderer --> Altair
    CoreEngine --> ASPEngine
    Constraints --> ClingoSolver
    Generator --> ClingoSolver
    Optimizer --> ClingoSolver
    HardConstraints --> Constraints
    SoftConstraints --> Constraints
    Weights --> Optimizer

    %% Click Events
    click API "https://github.com/cmudig/draco2/tree/main/draco/server/routers/"
    click ServerComp "https://github.com/cmudig/draco2/tree/main/draco/server/"
    click APIModels "https://github.com/cmudig/draco2/tree/main/draco/server/models/"
    click ServerServices "https://github.com/cmudig/draco2/tree/main/draco/server/services/"
    click CoreEngine "https://github.com/cmudig/draco2/blob/main/draco/draco.py"
    click SchemaDefinitions "https://github.com/cmudig/draco2/blob/main/draco/schema.py"
    click Learn "https://github.com/cmudig/draco2/blob/main/draco/learn.py"
    click Renderer "https://github.com/cmudig/draco2/tree/main/draco/renderer/"
    click AltairRenderer "https://github.com/cmudig/draco2/blob/main/draco/renderer/altair/altair_renderer.py"
    click Constraints "https://github.com/cmudig/draco2/blob/main/draco/asp/constraints.lp"
    click Generator "https://github.com/cmudig/draco2/blob/main/draco/asp/generate.lp"
    click Optimizer "https://github.com/cmudig/draco2/blob/main/draco/asp/optimize.lp"
    click HardConstraints "https://github.com/cmudig/draco2/blob/main/draco/asp/hard.lp"
    click SoftConstraints "https://github.com/cmudig/draco2/blob/main/draco/asp/soft.lp"
    click Weights "https://github.com/cmudig/draco2/blob/main/draco/asp/weights.lp"

    %% Legend
    subgraph Legend
        L1[API Components]:::api
        L2[Core Components]:::core
        L3[External Dependencies]:::external
        L4[Processing Modules]:::processing
        L5[Data Components]:::data
    end
```
