How ltplus-ag/nhmzh-plugin-lca works
Project type and purpose
• Full-stack “plugin” application for Life Cycle Assessment (LCA) in the NHMzh ecosystem
• Provides a React-based UI for users to manage materials and run LCA calculations
• Hosts a small socket-based backend service that consumes and publishes Kafka messages and integrates with the KBOB material database
File structure
• Top-level files:
– Dockerfile.frontend, nginx.conf, index.html → static build & serving of the React app
– package.json, vite.config.ts, tsconfig.json → Vite-based frontend
– .github/workflows/docker-publish.yml → CI/CD pipeline to build & publish Docker images
• socket-backend folder:
– server.ts → entry point for the Node.js/Kafka/WebSocket backend
– KafkaService.ts, LcaCalculationService.ts → core services for message streaming & LCA logic
– config.ts → Kafka topics & connection settings
– dbSeeder.ts → script to seed initial data into a database (e.g., MongoDB)
• src folder (frontend):
– components/LCACalculator, services/, utils/, types/ → modular React app following feature & utility folders
– src/main.tsx → ReactDOM bootstrap
– socket-based or REST service connectors in services/ for Kafka & WebSocket
Key insights from README
• React 18, TypeScript, Tailwind CSS, Vite, Radix UI
• Consumes “qto-elements” Kafka topic, publishes “lca-data” topic
• Integrates with external KBOB Material Database API (lcadata.ch)
• Integrates upstream (QTO Plugin) and downstream (Cost Plugin, Central DB) in NHMzh
Main components
a. Frontend (React + Vite + Tailwind)
– Builds & serves UI via Nginx or Vite dev server
– Hosts LCACalculator component tree
– Communicates over WebSocket (or HTTP) to backend
b. Backend (Node.js + TypeScript)
– WebSocket server (server.ts) for real‐time updates
– Kafka consumer (“qto-elements”) and producer (“lca-data”)
– LcaCalculationService for core logic
– Optional DB seeder (dbSeeder.ts) writing to MongoDB
c. Kafka Cluster
– “qto-elements” topic (input)
– “lca-data” topic (output)
d. External services
– KBOB Material Database API (lcadata.ch)
– Central Database (MongoDB) in NHMzh ecosystem
– Other plugins (QTO, Cost) as upstream/downstream clients
e. DevOps & CI/CD
– Docker images (frontend & backend)
– GitHub Actions pipeline
– Nginx reverse proxy
Relationships & data flow
1) User interacts with the React App in browser
2) React → WebSocket → backend server
3) Backend consumes “qto-elements” from Kafka → LcaCalculationService
4) LcaCalculationService may call KBOB API for material coefficients
5) Results published to “lca-data” Kafka topic
6) Results optionally stored in MongoDB (dbSeeder or direct writes)
7) Other NHMzh modules subscribe to “lca-data”
Architectural patterns & principles
• Micro-service style: frontend & backend in separate containers
• Event-driven: Kafka pub/sub for decoupling
• Single-Page App (SPA) using feature-based component structure
• Separation of concerns: services layer → business logic → data models