# ltplus-ag/nhmzh-plugin-qto architecture

> Architecture diagram of the GitHub repository ltplus-ag/nhmzh-plugin-qto, 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/ltplus-ag/nhmzh-plugin-qto
- Repository: https://github.com/ltplus-ag/nhmzh-plugin-qto

## Overview

##### Project type and purpose
- This is a full-stack, event-driven Quantity Take-Off (QTO) plugin for the NHMzh ecosystem.
- Frontend: React + TypeScript + Material-UI for interactive IFC model upload, display, editing.
- Backend: Python + FastAPI, using IfcOpenShell to parse IFC files, MongoDB for persistence, Kafka for event publishing.
- Additional microservice/library (qto_ifc-msg): standalone Node.js/TypeScript code that can publish QTO messages to Kafka and interface with MinIO.

##### File structure
- Top-level directories:
- frontend app under `src/`, with React pages, components, API client, types, styles, Vite config.
- backend under `backend/`, with `main.py`, parsing scripts, Kafka producer (`qto_producer.py`), MongoDB init, requirements, Dockerfile.
- `qto_ifc-msg/`: separate NPM package for Kafka + MinIO messaging, includes source, tests, Dockerfile, workflows.
- Config files & automation: Dockerfiles (`Dockerfile.frontend`, `backend/Dockerfile.backend`, `qto_ifc-msg/Dockerfile`), GitHub Actions workflows, `nginx.conf`, ESLint, tsconfigs.

##### README for insights
- Architecture section: confirms FastAPI + IfcOpenShell + Kafka + MongoDB on backend, React + MUI DataGrid on frontend.
- Kafka topics: `PROJECT_UPDATED` events, batched element data with full IFC metadata.
- Integration: downstream NHMzh modules (cost, LCA) consume these events.

##### Elements
- Backend and microservices in another (e.g., green)

##### Final advice
- Dockerized deployment by optionally grouping containers under a “Docker Compose” boundary.
- Keep labels consistent with code (use exact endpoint names, topic names, container names).
- Provide a small caption or footnote describing tech stack versions (e.g., React 18, FastAPI, Python 3.9, Kafka 2.x).
- Readability: position UI at the top/left, data stores at bottom, event bus in center.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    UI["React App"]:::frontend

    %% Backend Layer
    API["FastAPI Service"]:::backend
    Parser["IfcOpenShell Parser"]:::backend
    QProducer["Kafka Producer (qto_producer.py)"]:::backend

    %% Messaging & Storage
    Mongo["MongoDB"]:::infrastructure
    Kafka["Kafka Broker"]:::infrastructure
    MinIO["MinIO (optional)"]:::infrastructure

    %% QTO Messaging Service
    QtoService["QTO Messaging Service"]:::service

    %% External Consumers
    Cost["Cost Plugin"]:::consumer
    LCA["LCA Plugin"]:::consumer

    %% Data Flows
    UI -->|"HTTP POST /upload-ifc"| API
    API -->|"parse IFC & extract quantities"| Parser
    Parser -->|"invoke producer"| QProducer
    API -->|"store documents"| Mongo
    QProducer -.->|"publish PROJECT_UPDATED"| Kafka
    QtoService -->|"publish/read events"| Kafka
    QtoService -->|"upload/download objects"| MinIO
    Cost -.->|"subscribe PROJECT_UPDATED"| Kafka
    LCA -.->|"subscribe PROJECT_UPDATED"| Kafka

    %% Click Events
    click UI "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/src/App.tsx"
    click UI "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/src/main.tsx"
    click API "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/backend/main.py"
    click Parser "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/backend/ifc_materials_parser.py"
    click QProducer "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/backend/qto_producer.py"
    click Mongo "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/backend/init-mongo.js"
    click QtoService "https://github.com/ltplus-ag/nhmzh-plugin-qto/blob/main/qto_ifc-msg/src/index.ts"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0284C7,color:#03396C;
    classDef backend fill:#D2F8D2,stroke:#2E8B57,color:#006400;
    classDef infrastructure fill:#F0F0F0,stroke:#888888,color:#333333;
    classDef service fill:#FFF4D2,stroke:#D4A017,color:#8B6508;
    classDef consumer fill:#FFE6D9,stroke:#E07200,color:#993300;
```
