C4Sharp (C4S
) is a .net library for building C4 Model diagrams. It's works like a superset of C4-PlantUML through which developers can create, share, and consume C4 Model diagrams as code (C#) such as Context, Container, Component and Deployment diagrams.
This package is available through Nuget Packages: https://www.nuget.org/packages/C4Sharp
Package | Version | Downloads | Maintainability |
---|---|---|---|
C4Sharp |
Nuget
Install-Package C4Sharp
.NET CLI
dotnet add package C4Sharp
You need these things to run C4Sharp:
To create C4S diagrams, we need a set of C4 structures and inform their Relationships, as shown in the following example:
To start using C4S, you should create the basic structures of your architecture design, like this:
//Person
public static Person Customer => new Person("customer", "Personal Banking Customer")
{
Description = "A customer of the bank, with personal bank accounts."
};
// Systems
public static SoftwareSystem BankingSystem => new SoftwareSystem("BankingSystem", "Internet Banking System")
{
Description = "Allows customers to view information about their bank accounts, and make payments."
};
public static SoftwareSystem Mainframe => new SoftwareSystem("Mainframe", "Mainframe Banking System")
{
Description = "Stores all of the core banking information about customers, accounts, transactions, etc.",
Boundary = Boundary.External
};
public static SoftwareSystem MailSystem => new SoftwareSystem("MailSystem", "E-mail system")
{
Description = "The internal Microsoft Exchange e-mail system.",
Boundary = Boundary.External
};
Then, you'll be able to create a C4 Context Diagram:
var diagram = new ContextDiagram
{
Title = "System Context diagram for Internet Banking System",
Structures = new Structure[]
{
Customer,
BankingSystem,
Mainframe,
MailSystem
},
Relationships = new []
{
(Customer > BankingSystem),
(Customer < MailSystem)["Sends e-mails to"],
(BankingSystem > MailSystem)["Sends e-mails", "SMTP"][Neighbor],
(BankingSystem > Mainframe),
}
};
new PlantumlSession()
.UseDiagramImageBuilder()
.UseStandardLibraryBaseUrl()
.Export(diagrams);
See more in our sample code:
The result will be:
To learn more about C4S
access our wiki.
This is a guide to contributing to this open source project that uses GitHub. It’s mostly based on how many open sorce projects operate. That’s all there is to it. The fundamentals are:
- Fork the project & clone locally.
- Create an upstream remote and sync your local copy before you branch.
- Branch for each separate piece of work.
- Do the work, write good commit messages, and read the CONTRIBUTING file if there is one.
- Push to your origin repository.
- Create a new PR in GitHub.
- Respond to any code review feedback.
If you want to contribute to an open source project, the best one to pick is one that you are using yourself. The maintainers will appreciate it!