How mod-construction/mod-dlm works
Project Type and Purpose
• This is an open-source Domain-Specific Language (DSL) library and code-generation tool (“mod-dlm”) written in TypeScript.
• Its purpose is to let AEC-industry users describe prefab building elements via a schema, then automatically generate:
• RESTful CRUD APIs (OpenAPI/Redocly docs)
• Client libraries (TypeScript-Fetch, Python, Java/Spring, Go, etc.)
• Server stubs (e.g. FastAPI)
• It ships as an npm package, plus generator configurations, mustache templates, and GitHub Actions workflows to produce language-specific SDKs and docs.
File-Structure Analysis
• src/
• index.ts – public entry point & CLI-style invocation
• createApiDocs.ts – generate OpenAPI specs & HTML docs (uses Redocly)
• types/ – Zod/TypeScript schemas for DSL (common, entities, API types)
• utils/ – helper functions for file I/O, templating, config loading
• generator-configs/ – YAML configurations per generator (python-fastapi, spring, typescript-fetch) plus mustache template directories
• openapi/ + openapitools.json – OpenAPI Generator configuration
• template/apidoc.html – custom HTML template for API docs
• package.json, tsconfig.json – build scripts, dependencies
• .github/workflows – CI to generate docs, clients, servers, publish to npm/PyPI/GitHub Packages
Key README Insights
• Features: DSL definitions → automatic CRUD API generation → multi-language support
• Usage examples show importing the library in a TS project and validating DSL instances
Main Components & Their Interactions
A. Developer Interface
• CLI or programmatic API (index.ts)
• Accepts DSL definitions (JS/TS objects or external YAML)
B. DSL Module
• Zod-based schemas (src/types) define PrefabElement and sub-schemas
• Validation logic
C. Code-Generation Engine
• Loads generator-config YAML (generator-configs/)
• Invokes Mustache template renderer against DSL AST/JSON
• Outputs language-specific code (clients, servers)
D. OpenAPI/Docs Generator
• createApiDocs.ts uses the DSL schema + OpenAPI generator config
• Produces OpenAPI JSON/YAML, then HTML via Redocly/template/apidoc.html
E. Configuration & Templates
• generator-config files guide codegen (package names, file paths, etc.)
• Mustache templates for each target language
F. CI/CD Workflows
• GitHub Actions trigger generation, testing, publishing to npm/PyPI
G. Output Artifacts
• npm package (@mod-construction/mod-dlm)
• Python package (mod-dlm-server)
• Generated client SDKs & server stubs in respective languages
• Hosted API docs
Architectural Patterns & Principles
• Plugin/Template-Driven Architecture: decouples core engine from language targets
• Single Responsibility: separate modules for parsing, templating, docs, utils
• Layered Flow:
1. Input (DSL definitions) →
2. Validation (Zod schemas) →
3. Transformation (JSON/AST) →
4. Codegen (Mustache + generator-configs) →
5. Artifact output (files, docs)
• Config-over-Code: behavior driven by YAML + templates