Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/new builders and themes #52

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ System_Ext(MailSystem, "E-mail system", "The internal Microsoft Exchange e-mail

System_Boundary(c1, "Internet Banking") {
Container(Corporate.Finance.Limits.Service.ServiceBus, "WebApp", "Web Application:C#, WebApi", "Delivers the static content and the Internet banking SPA")
Container(Spa, "SPA", "Spa:JavaScript, Angular", "Provides all the Internet banking functionality to customers via their web browser")
Container(Spa, "Spa", "Spa:JavaScript, Angular", "Delivers the static content and the Internet banking SPA")
Container(MobileApp, "MobileApp", "Mobile:C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device")
ContainerDb(Database, "SqlDatabase", "Database:SQL Database", "Stores user registration information, hashed auth credentials, access logs, etc.")
ContainerQueue(Queue, "RabbitMQ", "Queue:RabbitMQ", "Stores user registration information, hashed auth credentials, access logs, etc.")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ LAYOUT_LEFT_RIGHT()

title Internet Banking System API Application

Container(Spa, "SPA", "Spa:JavaScript, Angular", "Provides all the Internet banking functionality to customers via their web browser")
Container(MobileApp, "MobileApp", "Mobile:C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device")
ContainerDb(Database, "SqlDatabase", "Database:SQL Database", "Stores user registration information, hashed auth credentials, access logs, etc.")
System_Ext(Mainframe, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
Expand Down
9 changes: 5 additions & 4 deletions samples/ModelDiagrams/Diagrams/ComponentDiagramSample.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using C4Sharp.Diagrams;
using C4Sharp.Diagrams.Builders;
using C4Sharp.Elements;
using C4Sharp.Elements.Containers;
using C4Sharp.Elements.Relationships;
using static C4Sharp.Elements.Relationships.Boundary;
using static ModelDiagrams.Structures.Systems;
using static ModelDiagrams.Structures.Containers;
using static ModelDiagrams.Structures.Components;
Expand All @@ -15,11 +17,10 @@ public class ComponentDiagramSample : ComponentDiagram

protected override IEnumerable<Structure> Structures => new Structure[]
{
Spa,
MobileApp,
SqlDatabase,
Mainframe,
Boundary("c1", "API Application",
Bound("c1", "API Application",
Sign,
Accounts,
Security,
Expand All @@ -34,8 +35,8 @@ public class ComponentDiagramSample : ComponentDiagram
Security > SqlDatabase | ("Read & write to", "JDBC"),
MainframeFacade > Mainframe | ("Uses", "XML/HTTPS"),

Spa > Sign | ("Uses", "JSON/HTTPS"),
Spa > Accounts | ("Uses", "JSON/HTTPS"),
SpaApp > Sign | ("Uses", "JSON/HTTPS"),
SpaApp > Accounts | ("Uses", "JSON/HTTPS"),
MobileApp > Sign | ("Uses", "JSON/HTTPS"),
MobileApp > Accounts | ("Uses", "JSON/HTTPS")
};
Expand Down
33 changes: 22 additions & 11 deletions samples/ModelDiagrams/Diagrams/ContainerDiagramSample.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
using C4Sharp.Diagrams.Builders;
using C4Sharp.Elements;
using C4Sharp.Elements.Relationships;

using ModelDiagrams.Structures;
using static C4Sharp.Elements.ContainerType;
using static ModelDiagrams.Structures.Systems;
using static ModelDiagrams.Structures.Containers;
using static ModelDiagrams.Structures.People;

namespace ModelDiagrams.Diagrams;

public class ContainerDiagramSample: ContainerDiagram
public class ContainerDiagramSample : ContainerDiagram
{
protected override string Title => "Container diagram for Internet Banking System";

protected override IEnumerable<Structure> Structures => new Structure[]
{
Customer,
BankingSystem,
MailSystem,
Boundary("c1", "Internet Banking",
WebApp,
Spa,
Person.None | Boundary.External
| ("customer", "Personal Banking Customer", "A customer of the bank, with personal bank accounts."),

SoftwareSystem.None | ("BankingSystem", "Internet Banking System",
"Allows customers to view information about their bank accounts, and make payments."),

SoftwareSystem.None | Boundary.External
| ("MailSystem", "E-mail system", "The internal Microsoft Exchange e-mail system."),

Bound("c1", "Internet Banking",
Container.None | (WebApplication, "Corporate.Finance.Limits.Service.ServiceBus", "WebApp", "C#, WebApi",
"Delivers the static content and the Internet banking SPA"),

Container.None | (Spa, "Spa", "Spa", "JavaScript, Angular",
"Delivers the static content and the Internet banking SPA"),

MobileApp,
SqlDatabase,
RabbitMq,
Expand All @@ -30,11 +41,11 @@ public class ContainerDiagramSample: ContainerDiagram
protected override IEnumerable<Relationship> Relationships => new[]
{
Customer > WebApp | ("Uses", "HTTPS"),
Customer > Spa | ("Uses", "HTTPS"),
Customer > Containers.SpaApp | ("Uses", "HTTPS"),
Customer > MobileApp | "Uses",

WebApp > Spa | "Delivers" | Position.Neighbor,
Spa > BackendApi | ("Uses", "async, JSON/HTTPS"),
WebApp > Containers.SpaApp | "Delivers" | Position.Neighbor,
Containers.SpaApp > BackendApi | ("Uses", "async, JSON/HTTPS"),
MobileApp > BackendApi | ("Uses", "async, JSON/HTTPS"),
SqlDatabase < BackendApi | ("Uses", "async, JSON/HTTPS") | Position.Neighbor,
RabbitMq < BackendApi | ("Uses", "async, JSON"),
Expand Down
6 changes: 3 additions & 3 deletions samples/ModelDiagrams/Diagrams/DeploymentDiagramSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class DeploymentDiagramSample: DeploymentDiagram
Nodes.Ubuntu("bigbankdb02", "bigbank-db02", Nodes.OracleNode("oracle2", Containers.OracleDatabase["Data Reader"])),
Nodes.Ubuntu("bb2", "bigbank-web***\tx4", Nodes.ApacheTomCat("apache2", Containers.WebApp))),
Nodes.Ios("ios", Containers.MobileApp),
Nodes.PersonalComputer("computer", Nodes.Browser("browser", Containers.Spa))
Nodes.PersonalComputer("computer", Nodes.Browser("browser", Containers.SpaApp))
};

protected override IEnumerable<Relationship> Relationships => new[]
{
Containers.MobileApp > Containers.BackendApi | ("Makes API calls to", "json/HTTPS"),
Containers.Spa > Containers.BackendApi | ("Makes API calls to", "json/HTTPS"),
Containers.WebApp > Containers.Spa | "Delivers to the customer's web browser"| Position.Up,
Containers.SpaApp > Containers.BackendApi | ("Makes API calls to", "json/HTTPS"),
Containers.WebApp > Containers.SpaApp | "Delivers to the customer's web browser"| Position.Up,
Containers.BackendApi > Containers.OracleDatabase[1] | ("Writes to", "JDBC"),
Containers.BackendApi < Containers.OracleDatabase["Data Reader"] | ("Reads from", "JDBC"),
Containers.OracleDatabase[1] > Containers.OracleDatabase["Data Reader"] | ("Replicates data to", "JDBC") | Position.Right,
Expand Down
6 changes: 3 additions & 3 deletions samples/ModelDiagrams/Diagrams/EnterpriseDiagramSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class EnterpriseDiagramSample: ContextDiagram
protected override IEnumerable<Structure> Structures => new Structure[]
{
Customer,
Boundary("enterprise.boundary", "Domain A",
Bound("enterprise.boundary", "Domain A",
BankingSystem,
Boundary("enterprise.boundary.1", "Domain Internal Users", InternalCustomer),
Boundary("enterprise.boundary.2", "Domain Managers", Manager)
Bound("enterprise.boundary.1", "Domain Internal Users", InternalCustomer),
Bound("enterprise.boundary.2", "Domain Managers", Manager)
),
Mainframe,
MailSystem
Expand Down
2 changes: 1 addition & 1 deletion samples/ModelDiagrams/Diagrams/SequenceDiagramSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SequenceDiagramSample : SequenceDiagram
new Container("cA", "Single-Page Application", ContainerType.None, "JavaScript and Angular",
"Provides all of the Internet banking functionality to customers via their web browser."),

Boundary("b", "Api Application",
Bound("b", "Api Application",
new("cB", "Sign In Controller", ComponentType.None, "Spring MVC Rest Controller",
"Allows users to sign in to the Internet Banking System."),
new("cC", "Security Component", ComponentType.None, "Spring Bean",
Expand Down
4 changes: 3 additions & 1 deletion samples/ModelDiagrams/Structures/Containers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using C4Sharp.Elements;
using C4Sharp.Elements.Containers;
using C4Sharp.Elements.Relationships;

namespace ModelDiagrams.Structures;

Expand All @@ -11,7 +13,7 @@ public static class Containers
Technology: "C#, WebApi"
);

public static ClientSideWebApp Spa => new (
public static ClientSideWebApp SpaApp => new (
Alias: "Spa",
Label: "SPA",
Technology: "JavaScript, Angular",
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Builders/ComponentDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public abstract class ComponentDiagram: DiagramBuilder
protected override string Title { get; } = "Component Diagram";
protected override DiagramType DiagramType { get; } = DiagramType.Component;

protected ContainerBoundary Boundary(string tag, string name, params Component[] components)
protected ContainerBoundary Bound(string tag, string name, params Component[] components)
=> new(tag, name, components);
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Builders/ContainerDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public abstract class ContainerDiagram: DiagramBuilder
protected override string Title { get; } = "Container Diagram";
protected override DiagramType DiagramType { get; } = DiagramType.Container;

protected SoftwareSystemBoundary Boundary(string tag, string name, params Container[] components)
protected SoftwareSystemBoundary Bound(string tag, string name, params Container[] components)
=> new(tag, name, components);
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Builders/ContextDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public abstract class ContextDiagram: DiagramBuilder
protected override string Title { get; } = "Context Diagram";
protected override DiagramType DiagramType { get; } = DiagramType.Component;

protected EnterpriseBoundary Boundary(string alias, string label, params Structure[] structures) =>
protected EnterpriseBoundary Bound(string alias, string label, params Structure[] structures) =>
new(alias, label, structures);
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Builders/SequenceDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public abstract class SequenceDiagram: DiagramBuilder
protected override string Title { get; } = "Sequence Diagram";
protected override DiagramType DiagramType { get; } = DiagramType.Sequence;

protected SequenceContainerBoundary Boundary(string alias, string label, params Component[] structures) =>
protected SequenceContainerBoundary Bound(string alias, string label, params Component[] structures) =>
new(alias, label, structures);
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/DiagramBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract partial class DiagramBuilder : IDiagramBuilder
protected abstract IEnumerable<Structure> Structures { get; }
protected abstract IEnumerable<Relationship> Relationships { get; }

public Diagram Build(IDiagramTheme? theme)
public Diagram Build(IDiagramTheme? theme = null)
{
_structures.AddRange(Structures);

Expand Down
23 changes: 13 additions & 10 deletions src/C4Sharp/Elements/Component.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using C4Sharp.Commons.Extensions;
using C4Sharp.Elements.Relationships;

namespace C4Sharp.Elements;

Expand All @@ -12,18 +13,13 @@ namespace C4Sharp.Elements;
/// space. In the C4 model, components are not separately deployable units.
/// <see href="https://c4model.com/"/>
/// </summary>
public record Component : Structure
public record Component(string Alias, string Label) : Structure(Alias, Label)
{
public string? Technology { get; init; }
public ComponentType ComponentType { get; init; } = ComponentType.None;
public static Component None => new("none", "None");

public ComponentType ComponentType { get; init; }

public Component(string alias, string label): base(alias, label)
{
ComponentType = ComponentType.None;
}

public Component(StructureIdentity alias, string label): base(alias, label)
public Component(StructureIdentity alias, string label): this(alias.Value, label)
{
ComponentType = ComponentType.None;
}
Expand All @@ -47,7 +43,14 @@ public Component(string alias, string label, string technology, string descripti
public Component(string alias, string label, ComponentType componentType, string technology, string description): this(alias, label, technology, description)
{
ComponentType = componentType;
}
}

public static Component operator |(Component a, Boundary boundary) => a with{ Boundary = boundary};
public static Component operator |(Component a, ComponentType b) => a with{ ComponentType = b };
public static Component operator |(Component a, (string alias, string label) b) => new (b.alias, b.label);
public static Component operator |(Component a, (string alias, string label, string technology) b) => new Component(b.alias, b.label, b.technology);
public static Component operator |(Component a, (string alias, string label, string technology , string description) b) => new (b.alias, b.label, b.technology, b.description);

}

public record Component<T> : Component
Expand Down
14 changes: 14 additions & 0 deletions src/C4Sharp/Elements/Container.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using C4Sharp.Commons.Extensions;
using C4Sharp.Elements.Relationships;

namespace C4Sharp.Elements;

Expand All @@ -21,6 +22,8 @@ public record Container : Structure
public string? Technology { get; init; }
public Container this[int index] => GetInstance(index.ToString());
public Container this[string instanceName] => GetInstance(instanceName);

public static Container None => new("None", "None", ContainerType.None, "None");

public Container(string alias, string label)
: base(alias, label)
Expand All @@ -44,11 +47,22 @@ public Container(string alias, string label, ContainerType type, string? technol
Description = description ?? string.Empty;
}

public Container(string alias, string label, ContainerType type, string? technology, string? description, Boundary? boundary)
: this(alias, label, type, technology, description)
{
Boundary = boundary ?? Boundary.Internal;
}

public Container(string alias, string label, ContainerType type, string? technology, string? description, IEnumerable<string> tags)
: this(alias, label, type, technology, description)
{
Tags = tags;
}

public static Container operator |(Container a, Boundary boundary) => a with{ Boundary = boundary};
public static Container operator |(Container a, (ContainerType type, string alias, string label) b) => new (b.alias, b.label);
public static Container operator |(Container a, (ContainerType type, string alias, string label, string? technology) b) => new (b.alias, b.label, b.type, b.technology);
public static Container operator |(Container a, (ContainerType type, string alias, string label,string? technology , string? description) b) => new (b.alias, b.label, b.type, b.technology, b.description);

/// <summary>
/// Get or Create a instance of current container
Expand Down
13 changes: 10 additions & 3 deletions src/C4Sharp/Elements/Containers/Queue.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using C4Sharp.Elements.Relationships;

namespace C4Sharp.Elements.Containers;

public record Queue(string Alias, string Label, string Technology, string? Description = null)
: Container(Alias, Label, ContainerType.Queue, Technology, Description);

public record Queue(
string Alias,
string Label,
string Technology,
string? Description = null,
Boundary Boundary = Boundary.Internal)
: Container(Alias, Label, ContainerType.Queue, Technology, Description, Boundary);

public record Queue<T>(string Technology, string? Description = null)
: Container<T>(ContainerType.Queue, Technology, Description);
12 changes: 7 additions & 5 deletions src/C4Sharp/Elements/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ namespace C4Sharp.Elements;
/// A person represents one of the human users of your software system (e.g. actors, roles, personas, etc)
/// <see href="https://c4model.com/"/>
/// </summary>
public sealed record Person : Structure
public sealed record Person(string Alias, string Label) : Structure(Alias, Label)
{
public Person(string alias, string label) : base(alias, label)
{
}

public static Person None => new("none", "None");

public Person(string alias, string label, string description) : this(alias, label)
{
Description = description;
Expand All @@ -22,4 +20,8 @@ public Person(string alias, string label, string description, Boundary boundary)
Description = description;
Boundary = boundary;
}

public static Person operator |(Person a, Boundary boundary) => a with{ Boundary = boundary };
public static Person operator |(Person a, (string alias, string label) b) => new (b.alias, b.label);
public static Person operator |(Person a, (string alias, string label, string description) b) => new (b.alias, b.label, b.description);
}
15 changes: 9 additions & 6 deletions src/C4Sharp/Elements/SoftwareSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ namespace C4Sharp.Elements;
/// a single software development team.
/// <see href="https://c4model.com/"/>
/// </summary>
public sealed record SoftwareSystem : Structure
public sealed record SoftwareSystem(string Alias, string Label) : Structure(Alias, Label)
{
public SoftwareSystem(string alias, string label) : base(alias, label)
{
}

public static SoftwareSystem None => new("none", "None");

public SoftwareSystem(string alias, string label, string description) : this(alias, label)
{
Description = description;
Expand All @@ -24,5 +22,10 @@ public SoftwareSystem(string alias, string label, string description, Boundary b
{
Description = description;
Boundary = boundary;
}
}

public static SoftwareSystem operator |(SoftwareSystem a, Boundary boundary) => a with{ Boundary = boundary};
public static SoftwareSystem operator |(SoftwareSystem a, (string alias, string label) b) => new (b.alias, b.label);
public static SoftwareSystem operator |(SoftwareSystem a, (string alias, string label, string description) b) => new (b.alias, b.label, b.description);

}
Loading