Skip to content

Data Flows

Overview

crunch_uml has three primary data flows that correspond to the three CLI commands.

graph LR
    subgraph "Import Flow"
        I1["Input File<br/>XMI / JSON / XLSX"] --> I2["Parser.parse()"]
        I2 --> I3["Schema.save()"]
        I3 --> I4["Database.commit()"]
        I4 --> I5[("Database")]
    end

    style I1 fill:#dae8fc,stroke:#6c8ebf
    style I2 fill:#fff2cc,stroke:#d6b656
    style I3 fill:#FFF4E0,stroke:#d79b00
    style I4 fill:#f8cecc,stroke:#b85450
    style I5 fill:#f8cecc,stroke:#b85450
graph LR
    subgraph "Transform Flow"
        T1["Schema A<br/>(source)"] --> T2["Transformer.transform()"]
        T2 --> T3["get_copy() +<br/>materialize"]
        T3 --> T4["Schema B<br/>(target)"]
    end

    style T1 fill:#f8cecc,stroke:#b85450
    style T2 fill:#FFF4E0,stroke:#d79b00
    style T3 fill:#d5e8d4,stroke:#82b366
    style T4 fill:#f8cecc,stroke:#b85450
graph LR
    subgraph "Export Flow"
        E1[("Database")] --> E2["Schema.get_all_*()"]
        E2 --> E3["Renderer.render()"]
        E3 --> E4["Format + Filter"]
        E4 --> E5["Output File<br/>JSON / MD / RDF / XLSX"]
    end

    style E1 fill:#f8cecc,stroke:#b85450
    style E2 fill:#f8cecc,stroke:#b85450
    style E3 fill:#dae8fc,stroke:#6c8ebf
    style E4 fill:#d5e8d4,stroke:#82b366
    style E5 fill:#dae8fc,stroke:#6c8ebf

Import Flow — Detail

sequenceDiagram
    participant User as User
    participant CLI as cli.py
    participant Reg as ParserRegistry
    participant Parser as Parser
    participant Schema as Schema
    participant DB as Database

    User->>CLI: crunch_uml import -f model.xmi -t xmi
    CLI->>Reg: getinstance("xmi")
    Reg-->>CLI: XMIParser instance
    CLI->>DB: Database(db_url)
    CLI->>Schema: Schema(database, schema_name)
    CLI->>Parser: parse(args, schema)

    loop For each element in the source file
        Parser->>Parser: Parse XML structure (phase 1)
        Parser->>Schema: save(package/class/attribute)
    end

    loop For each relationship
        Parser->>Parser: Parse connectors (phase 2)
        Parser->>Schema: save(association/generalization)
    end

    CLI->>DB: commit()
    DB-->>User: Model saved

The XMI parser works in two phases:

  1. Phase 1phase1_process_packages_classes(): extracts packages, classes, attributes and enumerations from the XML tree
  2. Phase 2phase2_process_connectors(): processes associations, generalizations and diagram relationships that reference the objects created in phase 1

Transform Flow — Detail

sequenceDiagram
    participant CLI as cli.py
    participant Reg as TransformerRegistry
    participant Trans as Transformer
    participant SchA as Schema (source)
    participant SchB as Schema (target)
    participant DB as Database

    CLI->>Reg: getinstance("copy")
    Reg-->>CLI: CopyTransformer
    CLI->>Trans: transform(args, database)
    Trans->>SchA: get_package(root_package_id)
    SchA-->>Trans: Package hierarchy
    Trans->>Trans: package.get_copy(materialize=...)

    alt Materialization on
        Trans->>Trans: Copy parent attributes to children
    end

    Trans->>SchB: add(copy, recursive=True)
    CLI->>DB: commit()

Export Flow — Detail

sequenceDiagram
    participant CLI as cli.py
    participant Reg as RendererRegistry
    participant Rend as Renderer
    participant Schema as Schema
    participant File as Output File

    CLI->>Reg: getinstance("json")
    Reg-->>CLI: JSONRenderer
    CLI->>Rend: render(args, schema)
    Rend->>Schema: get_all_packages() / get_all_classes()
    Schema-->>Rend: ORM objects
    Rend->>Rend: object_as_dict() serialization
    Rend->>Rend: Column filtering + mapper
    Rend->>File: Write output

Complete Pipeline

A typical pipeline combines multiple commands:

graph TB
    A["source_file.xmi"] -->|"import"| B[("Schema: v1")]
    B -->|"transform"| C[("Schema: v2")]
    C -->|"export json"| D["output.json"]
    C -->|"export markdown"| E["docs.md"]
    C -->|"export rdf"| F["ontology.ttl"]
    C -->|"export sqla"| G["models.py"]

    style B fill:#f8cecc,stroke:#b85450
    style C fill:#f8cecc,stroke:#b85450