-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#24: Synergy.Architecture: Added README.md
It contains first version of description how to add sequence diagrams to application.
- Loading branch information
1 parent
e453297
commit c015f43
Showing
9 changed files
with
529 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,124 @@ | ||
[//]: # (TODO Introduce docs for generating Sequence Diagrams from code) | ||
# Synergy.Architecture nuget packages | ||
|
||
Here is the documentation of the `Synergy.Architecture.Diagrams` and `Synergy.Architecture.Annotations` nuget packages. | ||
They were created to help developers to add sequence diagrams from code. | ||
It is based on the idea of *Diagrams as Code* | ||
|
||
Find packages on nuget: | ||
- [Synergy.Architecture.Diagrams](https://www.nuget.org/packages/Synergy.Architecture.Diagrams/) | ||
- [Synergy.Architecture.Annotations](https://www.nuget.org/packages/Synergy.Architecture.Annotations/) | ||
|
||
## Enlisting Public API | ||
|
||
To enlist public API, we use the following tool: | ||
|
||
```csharp | ||
using Synergy.Architecture.Annotations.Diagrams.Sequence; | ||
using Synergy.Architecture.Diagrams.Documentation; | ||
using Synergy.Architecture.Diagrams.Sequence; | ||
using Synergy.Documentation.Annotations; | ||
using Synergy.Documentation.Code; | ||
using static Synergy.Architecture.Annotations.Diagrams.Sequence.SequenceDiagramGroupType; | ||
|
||
namespace Synergy.Architecture.Tests.Samples; | ||
|
||
[CodeFilePath] | ||
public class SequenceDiagramSamples | ||
{ | ||
public static CodeFile SequenceDiagrams => CodeFolder.Current() | ||
.File($"{nameof(SequenceDiagramSamples)}.md"); | ||
|
||
[Fact] | ||
public async Task Sequence() | ||
{ | ||
var blueprint = TechnicalBlueprint | ||
.Titled("Sequence diagrams samples") | ||
.Add(this.IfElseDiagrams()) | ||
.Add(this.LoopAfterLoopDiagram()) | ||
.Add(this.DatabaseDiagrams()) | ||
.Add(this.OverrideMessageAndResultDiagrams()) | ||
; | ||
|
||
await File.WriteAllTextAsync(SequenceDiagrams.FilePath, blueprint.Render()); | ||
} | ||
|
||
private IEnumerable<SequenceDiagram> IfElseDiagrams() | ||
{ | ||
yield return SequenceDiagram | ||
.From(new SequenceDiagramActor("Some Actor", Note: "very hand some")) | ||
.Calling<SequenceDiagramSamples>(c => c.IfElse()) | ||
.Footer("This diagram shows if-else." | ||
); | ||
} | ||
|
||
[SequenceDiagramExternalCall("Chrome", "https://www.google.com", Group = SequenceDiagramGroupType.Alt, GroupHeader = "when google is available")] | ||
[SequenceDiagramExternalCall("Firefox", "https://www.foogle.com", Group = SequenceDiagramGroupType.Alt, GroupHeader = "when google is available")] | ||
[SequenceDiagramExternalCall("Firefox", "https://www.google.com", Group = SequenceDiagramGroupType.Else, GroupHeader = "otherwise")] | ||
private void IfElse() | ||
{ | ||
} | ||
|
||
private IEnumerable<SequenceDiagram> LoopAfterLoopDiagram() | ||
{ | ||
yield return SequenceDiagram | ||
.From(new SequenceDiagramActor("Upset Actor", Note: "very upset", Colour: "red")) | ||
.Calling<SequenceDiagramSamples>(c => c.LoopAfterLoop()) | ||
.Footer("This diagram shows loop placed after another loop." | ||
); | ||
} | ||
|
||
[SequenceDiagramExternalCall("Chrome", "https://www.google.com", Group = Loop, GroupHeader = "Looping until something happens")] | ||
[SequenceDiagramExternalCall("Firefox", "https://www.foogle.com", Group = Loop, GroupHeader = "Looping until something happens")] | ||
[SequenceDiagramExternalCall("Firefox", "https://www.google.com", Group = Loop, GroupHeader = "This should be different loop")] | ||
private void LoopAfterLoop() | ||
{ | ||
} | ||
|
||
private IEnumerable<SequenceDiagram> DatabaseDiagrams() | ||
{ | ||
yield return SequenceDiagram | ||
.From(new SequenceDiagramActor("Some\\nactor", Archetype:SequenceDiagramArchetype.Participant)) | ||
.Calling<SequenceDiagramSamples>(c => c.Upsert()) | ||
.Footer("This diagram shows standard database operations." | ||
); | ||
} | ||
|
||
[SequenceDiagramDatabaseCall($"SELECT * FROM [Item] WHERE [Id] = @itemId")] | ||
[SequenceDiagramDatabaseCall($"INSERT INTO [Item] VALUES ...", Group = Alt, GroupHeader = "if item does not exist yet")] | ||
[SequenceDiagramDatabaseCall($"UPDATE [Item] SET ... WHERE [Id] = @itemId", Group = Else, GroupHeader = "else")] | ||
private void Upsert() | ||
{ | ||
} | ||
|
||
private IEnumerable<SequenceDiagram> OverrideMessageAndResultDiagrams() | ||
{ | ||
yield return SequenceDiagram | ||
.From(new SequenceDiagramActor("Some\\nactor", Archetype:SequenceDiagramArchetype.Control)) | ||
.Calling<SequenceDiagramSamples>(c => c.OverrideMessageAndResult()) | ||
.Footer("This diagram shows how to override message and result for ordinary [SequenceDiagramCall]." | ||
); | ||
} | ||
|
||
[SequenceDiagramCall(typeof(Helper), nameof(Helper.SomeStaticMethod), | ||
Message = "GET https://www.google.com", | ||
Result = "200 OK")] | ||
private void OverrideMessageAndResult() | ||
{ | ||
} | ||
} | ||
|
||
internal class Helper | ||
{ | ||
public static void SomeStaticMethod() | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
For sample code, please check: [SequenceDiagramSamples.cs](Synergy.Architecture.Tests/Samples/SequenceDiagramSamples.cs) | ||
|
||
To see the results, please check: [SequenceDiagramSamples.md](Synergy.Architecture.Tests/Samples/SequenceDiagramSamples.md) | ||
|
||
**Note:** | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Architecture/Synergy.Architecture.Tests/Docs/README.Generate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Synergy.Architecture.Tests.Samples; | ||
using Synergy.Documentation.Code; | ||
using Synergy.Documentation.Markup; | ||
|
||
namespace Synergy.Architecture.Tests.Docs; | ||
|
||
// TODO: Marcin Celej [from: Marcin Celej on: 09-01-2024]: Extract this to a separate project Synergy.Documentation.Docs with all needed samples inside | ||
|
||
partial class README | ||
{ | ||
private static readonly CodeFile readmeFile = CodeFolder.Current().Up(2).File($"{nameof(README)}.md"); | ||
|
||
private CodeFile SampleSequenceDiagramsFile => CodeFile.For<SequenceDiagramSamples>(); | ||
private Markdown.Link SampleSequenceDiagramsLink => Markdown.Link.To(this.SampleSequenceDiagramsFile).RelativeFrom(readmeFile); | ||
|
||
private CodeFile SequenceDiagramsFile => SequenceDiagramSamples.SequenceDiagrams; | ||
private Markdown.Link SequenceDiagramsLink => Markdown.Link.To(this.SequenceDiagramsFile).RelativeFrom(readmeFile); | ||
|
||
[Fact] | ||
public void Generate() | ||
{ | ||
var content = this.TransformText(); | ||
File.WriteAllText(readmeFile.FilePath, content); | ||
} | ||
} |
Oops, something went wrong.