Engineers at the Microfabrika laboratory addressed the issue of AI-generated code becoming disorganized by using the C4 model and Structurizr DSL. AI tools, while accelerating development, often lead to technical debt, code duplication, and broken encapsulation because they lack a structured architectural overview.
The C4 model provides a hierarchical approach to system documentation, consisting of four levels: Context, Containers, Components, and Code. This methodology allows teams to maintain focus on specific abstraction layers without being overwhelmed by the entire system structure at once.
Structurizr separates architectural semantics from visual layout. The semantics are stored in a git-friendly workspace.dsl file, while layout information is kept in a separate workspace.json file. This separation prevents git diffs from becoming unreadable and ensures that manual layout adjustments are preserved.
The team runs Structurizr in a Docker container to view live diagrams in a browser, which allows for navigation between abstraction levels. They opted against static PNG or SVG exports, preferring the dynamic interface that updates automatically upon saving the DSL file.
By applying this approach to their project, 'Trafaretka', the team successfully mapped their existing architecture. This visual clarity helped them identify structural issues, resulting in a refactoring process that took one evening instead of the originally estimated week.





