Skip to content

Getting Started

Yan Justino edited this page Apr 4, 2021 · 12 revisions

C4Sharp is a .net library for building C4 Diagrams. Learn what C4S is all about on our homepage or in the tutorial.

Installation

This package is available through Nuget Packages: https://www.nuget.org/packages/C4Sharp

Package Version Downloads
C4Sharp NuGet Nuget

Nuget

Install-Package C4Sharp

.NET CLI

dotnet add package C4Sharp

Dependencies

You need these things to run C4Sharp:

Creating basic structure

C4S diagrams have a basic structure containing a Title, a set of C4 structures and their Relationships. As shown in following code:

var diagram = new <Diagram Type>
{
    Title = "...",
    Structures = new Structure[] { },
    Relationships = new Relationship[]{ }
};

Saving Diagrama

For saving your diagram as a PUML:

PlantumlFile.Save(diagram);
PlantumlFile.Save(diagram, [output path]);

PlantumlFile.SaveAsync(diagram);
PlantumlFile.SaveAsync(diagram, [output path]);

For saving your diagram as a PUML and PNG file:

PlantumlFile.Export(diagram);
PlantumlFile.Export(diagram, [output path]);
PlantumlFile.Export(diagram, [Plantuml Session]);
PlantumlFile.Export(diagram, [output path], [Plantuml Session]);

PlantumlFile.ExportAsync(diagram);
PlantumlFile.ExportAsync(diagram, [output path]);
PlantumlFile.ExportAsync(diagram, [Plantuml Session]);
PlantumlFile.ExportAsync(diagram, [output path], [Plantuml Session]);

Export in batch

var diagrams = new Diagram[]
{
    DiagramFixture.BuildContextDiagram(),
    DiagramFixture.BuildContainerDiagram(),
    DiagramFixture.BuildComponentDiagram(),
    DiagramFixture.BuildDeploymentDiagram()
};

using (var session = new PlantumlSession())
{
    PlantumlFile.Export(diagrams, session);
}

Export with authentication

using (var session = new PlantumlSession("username", "password"))
{
    PlantumlFile.Export(diagrams, session);
}

By Default the files PUML and PNG will be create on path '[current directory]/c4/diagram.png'