Example #1
0
        private static void AddDocumentationDiagram(Workspace workspace, StructurizrDocumentationTemplate template)
        {
            Model model = workspace.Model;

            SoftwareSystem documentationProjectSoftwareSystem = model.AddSoftwareSystem(
                Location.Internal,
                "Documentation Project",
                "Visual Studio Project (or VS Code Workspace) containing all documentation artifacts");

            Container diagramsDefinitionsContainer = documentationProjectSoftwareSystem.AddContainer("Diagram Definitions",
                                                                                                     "This is core Structurizr Library functionality - architecture diagrams defined as a code",
                                                                                                     "C# code");

            Container documentationSectionsContainer = documentationProjectSoftwareSystem.AddContainer("Documentation Sections",
                                                                                                       "Documentation sections in Markdown format - these can reference screenshots and diagrams",
                                                                                                       "Markdown");

            Container screenshotsContainer = documentationProjectSoftwareSystem.AddContainer("Screenshots",
                                                                                             "Screenshots and other images that we want to include in the documentation",
                                                                                             "PNG");

            SoftwareSystem gitHubRepositorySoftwareSystem = model.AddSoftwareSystem(
                Location.Unspecified,
                "GitHub Repository",
                "Used as remote repository; we use it as online host for screenshots");

            Container onlineScreenshotsContainer = gitHubRepositorySoftwareSystem.AddContainer("Online Screenshots", "Screenshots in GitHub available with public URL", "PNG, HTTP");

            SoftwareSystem structurizrWorkspaceSoftwareSystem = model.AddSoftwareSystem(
                Location.Unspecified,
                "Online Structurizr Workspace",
                "Transforms diagram definitions into interactive diagrams and also hosts diagrams as images; hosts online documentation");

            Container interactiveDiagramsContainer = structurizrWorkspaceSoftwareSystem.AddContainer("Interactive Diagrams", "User can modify diagram layout; there is additional functionality that helps getting architecture insights", "Structurizr SAAS");

            Container diagramsAsImagesContainer = structurizrWorkspaceSoftwareSystem.AddContainer("Diagram PNGs", "Interactive diagrams are automatically exported to PNG format and made available online", "PNG, HTTP");

            Container documentationAsHtmlContainer = structurizrWorkspaceSoftwareSystem.AddContainer("Documentation Online", "Markdown documents are automatically presented as online HTML", "HTTP, HTML");

            // what uses what
            documentationProjectSoftwareSystem.Uses(gitHubRepositorySoftwareSystem, "Uses it as a Git Remote");

            documentationSectionsContainer.Uses(onlineScreenshotsContainer, "Markdown documents reference online screenshots on GitHub");

            documentationProjectSoftwareSystem.Uses(structurizrWorkspaceSoftwareSystem, "Pushes diagram definitions and documentation sections into Structurizr workspace");

            documentationAsHtmlContainer.Uses(diagramsAsImagesContainer, "Generated HTML references diagrams as images (replacement for customer references to interactive diagrams)");

            documentationAsHtmlContainer.Uses(onlineScreenshotsContainer, "Generated HTML references online screenshots on GitHub");

            interactiveDiagramsContainer.Uses(diagramsAsImagesContainer, "Are transformed to images automatically");

            diagramsDefinitionsContainer.Uses(interactiveDiagramsContainer, "Code is transformed to interactive diagrams");

            documentationSectionsContainer.Uses(documentationAsHtmlContainer, "Markdown documents are presented as HTML on Structurizr");

            documentationSectionsContainer.Uses(diagramsAsImagesContainer, "Markdown documents reference diagrams hosted on Structurizr");

            // diagrams
            ViewSet views = workspace.Views;

            SystemContextView documentationSystemContextView = views.CreateSystemContextView(
                documentationProjectSoftwareSystem,
                "DocumentationSystemContext",
                "Documentation System Context diagram.");

            documentationSystemContextView.AddNearestNeighbours(documentationProjectSoftwareSystem);

            ContainerView documentationContainerView = views.CreateContainerView(documentationProjectSoftwareSystem, "DocumentationContainerDiagram", "Documentation container diagram");

            documentationContainerView.AddAllContainers();

            foreach (var githubContainer in gitHubRepositorySoftwareSystem.Containers)
            {
                githubContainer.AddTags("GitHub Container");
                documentationContainerView.Add(githubContainer);
            }

            foreach (var structurizrContainer in structurizrWorkspaceSoftwareSystem.Containers)
            {
                structurizrContainer.AddTags("Structurizr Container");
                documentationContainerView.Add(structurizrContainer);
            }

            // styles
            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle("GitHub Container")
            {
                Background = "#00BFFF"
            });
            styles.Add(new ElementStyle("Structurizr Container")
            {
                Background = "#ADFF2F"
            });

            // documentation sections
            var documentationFolderPath = Path.Combine(AppContext.BaseDirectory, "Documentation");

            template.AddSection(documentationProjectSoftwareSystem, "Documentation system", 1,
                                new FileInfo(Path.Combine(documentationFolderPath, "DocumentationOfDocumentation.md")));
        }
Example #2
0
        static void Main()
        {
            Workspace workspace = new Workspace("Widgets Limited", "Sells widgets to customers online.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;
            Styles    styles    = views.Configuration.Styles;

            model.Enterprise = new Enterprise("Widgets Limited");

            Person         customer            = model.AddPerson(Location.External, "Customer", "A customer of Widgets Limited.");
            Person         customerServiceUser = model.AddPerson(Location.Internal, "Customer Service Agent", "Deals with customer enquiries.");
            SoftwareSystem ecommerceSystem     = model.AddSoftwareSystem(Location.Internal, "E-commerce System", "Allows customers to buy widgets online via the widgets.com website.");
            SoftwareSystem fulfilmentSystem    = model.AddSoftwareSystem(Location.Internal, "Fulfilment System", "Responsible for processing and shipping of customer orders.");
            SoftwareSystem taxamo = model.AddSoftwareSystem(Location.External, "Taxamo", "Calculates local tax (for EU B2B customers) and acts as a front-end for Braintree Payments.");

            taxamo.Url = "https://www.taxamo.com";
            SoftwareSystem braintreePayments = model.AddSoftwareSystem(Location.External, "Braintree Payments", "Processes credit card payments on behalf of Widgets Limited.");

            braintreePayments.Url = "https://www.braintreepayments.com";
            SoftwareSystem jerseyPost = model.AddSoftwareSystem(Location.External, "Jersey Post", "Calculates worldwide shipping costs for packages.");

            model.People.Where(p => p.Location == Location.External).ToList().ForEach(p => p.AddTags(ExternalTag));
            model.People.Where(p => p.Location == Location.Internal).ToList().ForEach(p => p.AddTags(InternalTag));

            model.SoftwareSystems.Where(ss => ss.Location == Location.External).ToList().ForEach(ss => ss.AddTags(ExternalTag));
            model.SoftwareSystems.Where(ss => ss.Location == Location.Internal).ToList().ForEach(ss => ss.AddTags(InternalTag));

            customer.InteractsWith(customerServiceUser, "Asks questions to", "Telephone");
            customerServiceUser.Uses(ecommerceSystem, "Looks up order information using");
            customer.Uses(ecommerceSystem, "Places orders for widgets using");
            ecommerceSystem.Uses(fulfilmentSystem, "Sends order information to");
            fulfilmentSystem.Uses(jerseyPost, "Gets shipping charges from");
            ecommerceSystem.Uses(taxamo, "Delegates credit card processing to");
            taxamo.Uses(braintreePayments, "Uses for credit card processing");

            EnterpriseContextView enterpriseContextView = views.CreateEnterpriseContextView("EnterpriseContext", "The enterprise context for Widgets Limited.");

            enterpriseContextView.AddAllElements();

            SystemContextView ecommerceSystemContext = views.CreateSystemContextView(ecommerceSystem, "EcommerceSystemContext", "The system context diagram for the Widgets Limited e-commerce system.");

            ecommerceSystemContext.AddNearestNeighbours(ecommerceSystem);
            ecommerceSystemContext.Remove(customer.GetEfferentRelationshipWith(customerServiceUser));

            SystemContextView fulfilmentSystemContext = views.CreateSystemContextView(fulfilmentSystem, "FulfilmentSystemContext", "The system context diagram for the Widgets Limited fulfilment system.");

            fulfilmentSystemContext.AddNearestNeighbours(fulfilmentSystem);

            DynamicView dynamicView = views.CreateDynamicView("CustomerSupportCall", "A high-level overview of the customer support call process.");

            dynamicView.Add(customer, customerServiceUser);
            dynamicView.Add(customerServiceUser, ecommerceSystem);

            StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace);

            template.AddSection("Enterprise Context", 1, Format.Markdown, "Here is some information about the Widgets Limited enterprise context... ![](embed:EnterpriseContext)");
            template.AddContextSection(ecommerceSystem, Format.Markdown, "This is the context section for the E-commerce System... ![](embed:EcommerceSystemContext)");
            template.AddContextSection(fulfilmentSystem, Format.Markdown, "This is the context section for the Fulfilment System... ![](embed:FulfilmentSystemContext)");

            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Shape = Shape.RoundedBox
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            styles.Add(new ElementStyle(Tags.Element)
            {
                Color = "#ffffff"
            });
            styles.Add(new ElementStyle(ExternalTag)
            {
                Background = "#EC5381", Border = Border.Dashed
            });
            styles.Add(new ElementStyle(InternalTag)
            {
                Background = "#B60037"
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
        public void Test_AddCustomSection_AddsASectionWithAGroupOf1_WhenAGroupLessThan1IsSpecified()
        {
            Section section = _template.AddSection(_softwareSystem, "Custom Section", 0, Format.Markdown, "Custom content");

            Assert.Equal(1, section.Group);
        }