{"id":37026847,"url":"https://github.com/diagramsascode/diagramsascode","last_synced_at":"2026-01-14T03:10:20.495Z","repository":{"id":51334229,"uuid":"340389935","full_name":"diagramsascode/diagramsascode","owner":"diagramsascode","description":"Generate valid diagrams from source code","archived":false,"fork":false,"pushed_at":"2024-04-09T12:21:10.000Z","size":306,"stargazers_count":42,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-09T09:14:40.749Z","etag":null,"topics":["diagrams-as-code","java","living-documentation","plantuml","uml","uml-diagram","unified-modeling-language"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diagramsascode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-02-19T14:16:03.000Z","updated_at":"2024-12-11T17:07:59.000Z","dependencies_parsed_at":"2024-04-09T12:57:32.282Z","dependency_job_id":"5fab9b1a-b2f5-4b15-bbf5-2fee4549cbf9","html_url":"https://github.com/diagramsascode/diagramsascode","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/diagramsascode/diagramsascode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diagramsascode%2Fdiagramsascode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diagramsascode%2Fdiagramsascode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diagramsascode%2Fdiagramsascode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diagramsascode%2Fdiagramsascode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diagramsascode","download_url":"https://codeload.github.com/diagramsascode/diagramsascode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diagramsascode%2Fdiagramsascode/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diagrams-as-code","java","living-documentation","plantuml","uml","uml-diagram","unified-modeling-language"],"created_at":"2026-01-14T03:10:20.018Z","updated_at":"2026-01-14T03:10:20.486Z","avatar_url":"https://github.com/diagramsascode.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Diagrams as code\n[![Gitter](https://badges.gitter.im/diagramsascode/community.svg)](https://gitter.im/diagramsascode/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n*Diagrams as code* is a term used for storing the source of a diagram image as a text file.\nExamples are architecture diagrams, or diagrams showing a system's behavior or design.\nA generator tool like [PlantUML](https://plantuml.com/) then generates an image from the text, and automatically layouts it. According to the [ThoughtWorks Technology Radar](https://www.thoughtworks.com/radar/techniques/diagrams-as-code), a key benefit is that \nyou can use version control on the text files.\n\nThe diagrams as code project presented here has additional advantages.\n\nBy representing the diagrams as models in Java source code, \nyou can automatically check if the generated diagrams are modeled correctly.\nAnd you get better syntax highlighting and auto-completion, compared to solutions like PlantUML.\n\n# Getting started\nDiagrams as code is available on Maven Central.\n\nIf you are using Maven, include the following in your POM:\n\n``` xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.diagramsascode\u003c/groupId\u003e\n  \u003cartifactId\u003ediagramsascode-image\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.5\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nIf you are using Gradle, include the following in your build.gradle:\n\n```\nimplementation 'org.diagramsascode:diagramsascode-image:0.1.5'\n```\n\nThe jar files are also available in 'Releases'.\n\nAt least Java 11 is required to run diagrams as code.\n\n# Generate diagram images\n## Generate a sequence diagram image\nThe following sequence diagram image has been generated by the source code below:\n\n![Image of a sequence diagram](docs/sample_sequence_diagram.png)\n\nHere's the code:\n\n``` java\n// Create the participants (that exchange messages)\nvar participant1  = new Participant(\"Client\");\nvar participant2  = new Participant(\"Server\");\n\n// Create the request and response message\nvar message1 = new Message(participant1, participant2, \"Request Message\");\nvar message2 = new Message(participant2, participant1, \"Response Message\");\n\n// Build the diagram\nvar diagram = Diagram.builder()\n  .withNodes(participant1, participant2)\n  .withEdges(message1, message2)\n  .withConstraints(new SequenceDiagramConstraints())\n  .build();\n\t\n// Create the image of the diagram and write it to a PNG file.\nvar outputFile = File.createTempFile(\"sequence\", \".png\");\nSequenceDiagramImage.of(diagram).writeToPngFile(outputFile);\n\nSystem.out.println(\"Sequence diagram written to: \" + outputFile);\n```\n\n## Generate a state diagram image\nThe following state diagram image has been generated by the source code below:\n\n![Image of an state diagram](docs/sample_state_diagram.png)\n\n``` java\n // Create the nodes\nvar node0  = new State(\"Node 0\");\nvar node1  = new State(\"Node 1\");\n\n// Create the edges\nvar edge0 = new Transition(node0, node1, \"Forward\");\nvar edge1 = new Transition(node1, node0, \"Backward\");\n\n// Build the diagram\nvar diagram = Diagram.builder()\n  .withNodes(node0, node1)\n  .withEdges(edge0, edge1)\n  .withConstraints(new StateDiagramConstraints())\n  .build();\n\n// Create the image of the diagram and write it to a PNG file.\nvar outputFile = File.createTempFile(\"state\", \".png\");\nStateDiagramImage.of(diagram).writeToPngFile(outputFile);\n\nSystem.out.println(\"State diagram written to: \" + outputFile);\n```\n    \n## Generate an activity diagram image\nThe following activity diagram image has been generated by the source code below:\n\n![Image of an activity diagram](docs/sample_activity_diagram.png)\n\nHere's the code:\n\n``` java\n// Create the initial and final node (to define where the flow starts and ends)\nvar initialNode = new InitialNode();\nvar finalNode = new FinalNode();\n\t\n// Create the decision and merge node (to split the flow and merge it back together)\nvar decisionNode = new DecisionNode();\nvar mergeNode = new MergeNode();\n\t\n// Create actions (for the flow steps)\nvar action1 = new Action(\"Action1\");\nvar action2a = new Action(\"Action2a\");\nvar action2b = new Action(\"Action2b\");\nvar action3 = new Action(\"Action3\");\n\n// Connect the nodes with control flow edges.\n// If they originate from a decision node, the third constructor parameter\n// specifies the decision's condition (e.g. \"x \u003c 100\")\nvar edge1 = new ControlFlow(initialNode, action1);\nvar edge2 = new ControlFlow(action1, decisionNode);\nvar edge3_a = new ControlFlow(decisionNode, action2a, \"x \u003c 100\");\nvar edge3_b = new ControlFlow(decisionNode, action2b, \"x \u003e= 100\");\nvar edge4_a = new ControlFlow(action2a, mergeNode);\nvar edge4_b = new ControlFlow(action2b, mergeNode);\nvar edge5 = new ControlFlow(mergeNode, action3);\nvar edge6 = new ControlFlow(action3, finalNode);\n\n// Build the diagram\nvar diagram = Diagram.builder()\n  .withNodes(initialNode, finalNode, decisionNode, mergeNode, action1, action2a, action2b, action3)\n  .withEdges(edge1, edge2, edge3_a, edge3_b, edge4_a, edge4_b, edge5, edge6)\n  .withConstraints(new ActivityDiagramConstraints())\n  .build();\n\n// Create the image of the diagram and write it to a PNG file.\nvar outputFile = File.createTempFile(\"activity\", \".png\");\nActivityDiagramImage.of(diagram).writeToPngFile(outputFile);\n\nSystem.out.println(\"Activity diagram written to: \" + outputFile);\n```\n\n# Constraints\n## Sequence diagram constraints\nA sequence diagram has to take the following constraints into account:\n\n* Only sequence diagram nodes are shown on the diagram, i.e. participants\n* Only sequence diagram edges are shown on the diagram, i.e. messages\n* Each participant has a name\n\nThese constraints are defined in the [SequenceDiagramConstraints](https://github.com/diagramsascode/diagramsascode/blob/main/diagramsascode-sequence/src/main/java/org/diagramsascode/sequence/constraint/SequenceDiagramConstraints.java) instance. \n\n## State diagram constraints\nA state diagram has to take the following constraints into account:\n\n* Only state diagram nodes are shown on the diagram, i.e. states\n* Only state diagram edges are shown on the diagram, i.e. transitions\n* Each state has a name\n\nThese constraints are defined in the [StateDiagramConstraints](https://github.com/diagramsascode/diagramsascode/blob/main/diagramsascode-state/src/main/java/org/diagramsascode/state/constraint/StateDiagramConstraints.java) instance. \n\n## Activity diagram constraints\nAn activity diagram has to take the following constraints into account:\n\n* Only activity diagram nodes are shown on the diagram, i.e. initial/final nodes, decision/merge nodes, and actions\n* Only activity diagram edges are shown on the diagram, i.e. control flow\n* Each action has a name\n* Each decision node has one incoming edge\n* Each decision node has at least one outgoing edge\n* Each merge node has at least one incoming edge\n* Each merge node has one outgoing edge\n* An initial node has no incoming edges\n* A final node has no outgoing edges\n\nThese constraints are defined in the [ActivityDiagramConstraints](https://github.com/diagramsascode/diagramsascode/blob/main/diagramsascode-activity/src/main/java/org/diagramsascode/activity/constraint/ActivityDiagramConstraints.java) instance.\n\n## General notes on constraints\nThe constraints are validated implicitly when you create an `ImageSource` instance.\nYou can also validate them explicitly by calling `diagram.validate()`.\n\nYou can omit validating constraints by skipping the part `.withConstraints(...)` part when building the diagram. \nWhile this is not recommended in general since it allows building invalid diagrams, it may be useful for prototyping.\n\nYou can enforce more or less strict constraints by implementing the `DiagramConstraints` interface and provide your own constraints,\nor reuse existing ones.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiagramsascode%2Fdiagramsascode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiagramsascode%2Fdiagramsascode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiagramsascode%2Fdiagramsascode/lists"}