-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from nao1215/feat/arch
Add Architecture Diagrams
- Loading branch information
Showing
15 changed files
with
711 additions
and
1 deletion.
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
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,18 @@ | ||
## Architecture Diagram | ||
```mermaid | ||
architecture-beta | ||
service left_disk(disk)[Disk] | ||
service top_disk(disk)[Disk] | ||
service bottom_disk(disk)[Disk] | ||
service top_gateway(internet)[Gateway] | ||
service bottom_gateway(internet)[Gateway] | ||
junction junctionCenter | ||
junction junctionRight | ||
left_disk:R -- L:junctionCenter | ||
top_disk:B -- T:junctionCenter | ||
bottom_disk:T -- B:junctionCenter | ||
junctionCenter:R -- L:junctionRight | ||
top_gateway:B -- T:junctionRight | ||
bottom_gateway:T -- B:junctionRight | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,107 @@ | ||
//go:build linux || darwin | ||
|
||
// Package main is generating mermaid sequence diagram. | ||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/nao1215/markdown" | ||
"github.com/nao1215/markdown/mermaid/arch" | ||
) | ||
|
||
//go:generate go run main.go | ||
|
||
func main() { | ||
f, err := os.Create("generated.md") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
diagram := arch.NewArchitecture(io.Discard). | ||
Service("left_disk", arch.IconDisk, "Disk"). | ||
Service("top_disk", arch.IconDisk, "Disk"). | ||
Service("bottom_disk", arch.IconDisk, "Disk"). | ||
Service("top_gateway", arch.IconInternet, "Gateway"). | ||
Service("bottom_gateway", arch.IconInternet, "Gateway"). | ||
Junction("junctionCenter"). | ||
Junction("junctionRight"). | ||
LF(). | ||
Edges( | ||
arch.Edge{ | ||
ServiceID: "left_disk", | ||
Position: arch.PositionRight, | ||
Arrow: arch.ArrowNone, | ||
}, | ||
arch.Edge{ | ||
ServiceID: "junctionCenter", | ||
Position: arch.PositionLeft, | ||
Arrow: arch.ArrowNone, | ||
}). | ||
Edges( | ||
arch.Edge{ | ||
ServiceID: "top_disk", | ||
Position: arch.PositionBottom, | ||
Arrow: arch.ArrowNone, | ||
}, | ||
arch.Edge{ | ||
ServiceID: "junctionCenter", | ||
Position: arch.PositionTop, | ||
Arrow: arch.ArrowNone, | ||
}). | ||
Edges( | ||
arch.Edge{ | ||
ServiceID: "bottom_disk", | ||
Position: arch.PositionTop, | ||
Arrow: arch.ArrowNone, | ||
}, | ||
arch.Edge{ | ||
ServiceID: "junctionCenter", | ||
Position: arch.PositionBottom, | ||
Arrow: arch.ArrowNone, | ||
}). | ||
Edges( | ||
arch.Edge{ | ||
ServiceID: "junctionCenter", | ||
Position: arch.PositionRight, | ||
Arrow: arch.ArrowNone, | ||
}, | ||
arch.Edge{ | ||
ServiceID: "junctionRight", | ||
Position: arch.PositionLeft, | ||
Arrow: arch.ArrowNone, | ||
}). | ||
Edges( | ||
arch.Edge{ | ||
ServiceID: "top_gateway", | ||
Position: arch.PositionBottom, | ||
Arrow: arch.ArrowNone, | ||
}, | ||
arch.Edge{ | ||
ServiceID: "junctionRight", | ||
Position: arch.PositionTop, | ||
Arrow: arch.ArrowNone, | ||
}). | ||
Edges( | ||
arch.Edge{ | ||
ServiceID: "bottom_gateway", | ||
Position: arch.PositionTop, | ||
Arrow: arch.ArrowNone, | ||
}, | ||
arch.Edge{ | ||
ServiceID: "junctionRight", | ||
Position: arch.PositionBottom, | ||
Arrow: arch.ArrowNone, | ||
}).String() //nolint | ||
|
||
err = markdown.NewMarkdown(f). | ||
H2("Architecture Diagram"). | ||
CodeBlocks(markdown.SyntaxHighlightMermaid, diagram). | ||
Build() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,66 @@ | ||
// Package arch is mermaid architecture diagram builder. | ||
// The building blocks of an architecture are groups, services, edges, and junctions. | ||
// The arch package incorporates beta features of Mermaid, so the specifications are subject to significant changes. | ||
package arch | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/nao1215/markdown/internal" | ||
) | ||
|
||
// Architecture is a architecture diagram builder. | ||
type Architecture struct { | ||
// body is architecture diagram body. | ||
body []string | ||
// config is the configuration for the architecture diagram. | ||
config *config | ||
// dest is output destination for architecture diagram body. | ||
dest io.Writer | ||
// err manages errors that occur in all parts of the architecture building. | ||
err error | ||
} | ||
|
||
// NewArchitecture returns a new Architecture. | ||
func NewArchitecture(w io.Writer, opts ...Option) *Architecture { | ||
c := newConfig() | ||
|
||
for _, opt := range opts { | ||
opt(c) | ||
} | ||
|
||
return &Architecture{ | ||
body: []string{"architecture-beta"}, | ||
dest: w, | ||
config: c, | ||
} | ||
} | ||
|
||
// String returns the architecture diagram body. | ||
func (a *Architecture) String() string { | ||
return strings.Join(a.body, internal.LineFeed()) | ||
} | ||
|
||
// Build writes the architecture diagram body to the output destination. | ||
func (a *Architecture) Build() error { | ||
if _, err := a.dest.Write([]byte(a.String())); err != nil { | ||
if a.err != nil { | ||
return fmt.Errorf("failed to write: %w: %s", err, a.err.Error()) //nolint:wrapcheck | ||
} | ||
return fmt.Errorf("failed to write: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
// Error returns the error that occurred during the architecture diagram building. | ||
func (a *Architecture) Error() error { | ||
return a.err | ||
} | ||
|
||
// LF add a line feed to the architecture diagram body. | ||
func (a *Architecture) LF() *Architecture { | ||
a.body = append(a.body, "") | ||
return a | ||
} |
Oops, something went wrong.