Skip to content

Commit ca092e9

Browse files
Add go-structurizr (#36)
1 parent f670c0a commit ca092e9

12 files changed

Lines changed: 976 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# Dependency directories (remove the comment below to include it)
1717
vendor/
1818

19+
# Tools
20+
.idea
21+
1922
.terraform
2023
*.tfstate
2124
*.tfstate.*backup

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ fmt:
3535
mycli:
3636
mycli -u ${MYSQL_USER} -p ${MYSQL_PASSWORD} ${MYSQL_DATABASE}
3737

38+
.PHONY: c4
39+
c4:
40+
cd tools/c4 && go mod tidy && sh generate.sh
41+
3842
test:
3943
@./scripts/test.sh common .e2e.env
4044
@./scripts/test.sh trainer .test.env

tools/c4/generate.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
export FIRESTORE_EMULATOR_HOST=fake:8787
4+
export TRAINER_GRPC_ADDR=fake:3000
5+
export USERS_GRPC_ADDR=fake:3001
6+
7+
rm -rf out
8+
mkdir out
9+
10+
go run .
11+
12+
if ! type "plantuml" > /dev/null; then
13+
echo "Please install plantuml to generate PNG diagrams automatically"
14+
fi
15+
16+
for f in out/*.plantuml; do plantuml "$f"; done

tools/c4/go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/c4
2+
3+
go 1.16
4+
5+
require (
6+
github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer v0.0.0-00010101000000-000000000000
7+
github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainings v0.0.0-00010101000000-000000000000
8+
github.com/krzysztofreczek/go-structurizr v0.1.2
9+
)
10+
11+
replace (
12+
github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common => ../../internal/common/
13+
github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer => ../../internal/trainer/
14+
github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainings => ../../internal/trainings/
15+
)

tools/c4/go.sum

Lines changed: 546 additions & 0 deletions
Large diffs are not rendered by default.

tools/c4/main.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/krzysztofreczek/go-structurizr/pkg/scraper"
9+
"github.com/krzysztofreczek/go-structurizr/pkg/view"
10+
11+
trainerService "github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/service"
12+
trainingsService "github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainings/service"
13+
)
14+
15+
const (
16+
scraperConfig = "scraper.yml"
17+
viewConfig = "view.yml"
18+
outputFile = "out/view-%s.plantuml"
19+
)
20+
21+
func main() {
22+
ctx := context.Background()
23+
24+
trainerApp := trainerService.NewApplication(ctx)
25+
scrape(trainerApp, "trainer")
26+
27+
trainingsApp, _ := trainingsService.NewApplication(ctx)
28+
scrape(trainingsApp, "trainings")
29+
}
30+
31+
func scrape(app interface{}, name string) {
32+
s, err := scraper.NewScraperFromConfigFile(scraperConfig)
33+
if err != nil {
34+
panic(err)
35+
}
36+
37+
structure := s.Scrape(app)
38+
39+
outFileName := fmt.Sprintf(outputFile, name)
40+
outFile, err := os.Create(outFileName)
41+
if err != nil {
42+
panic(err)
43+
}
44+
45+
defer func() {
46+
_ = outFile.Close()
47+
}()
48+
49+
v, err := view.NewViewFromConfigFile(viewConfig)
50+
if err != nil {
51+
panic(err)
52+
}
53+
54+
err = v.RenderStructureTo(structure, outFile)
55+
if err != nil {
56+
panic(err)
57+
}
58+
}

tools/c4/out/view-trainer.plantuml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
This diagram has been generated with go-structurizr
2+
[https://github.com/krzysztofreczek/go-structurizr]
3+
4+
@startuml
5+
6+
title Service components
7+
8+
skinparam {
9+
shadowing false
10+
arrowFontSize 10
11+
defaultTextAlignment center
12+
wrapWidth 200
13+
maxMessageSize 100
14+
}
15+
hide stereotype
16+
top to bottom direction
17+
18+
scale 4096 width
19+
20+
skinparam rectangle<<_GROUP>> {
21+
FontColor #ffffff
22+
BorderColor #ffffff
23+
}
24+
25+
skinparam rectangle<<DOMAIN>> {
26+
BackgroundColor #ffffff
27+
FontColor #000000
28+
BorderColor #000000
29+
}
30+
31+
skinparam database<<DB>> {
32+
BackgroundColor #c8c8c8
33+
FontColor #000000
34+
BorderColor #000000
35+
}
36+
37+
skinparam rectangle<<ROOT>> {
38+
BackgroundColor #ffffff
39+
FontColor #000000
40+
BorderColor #000000
41+
}
42+
43+
skinparam rectangle<<APP>> {
44+
BackgroundColor #1a4577
45+
FontColor #ffffff
46+
BorderColor #000000
47+
}
48+
49+
skinparam rectangle<<ADAPTER>> {
50+
BackgroundColor #2d69b7
51+
FontColor #ffffff
52+
BorderColor #000000
53+
}
54+
55+
rectangle 0ROOT <<_GROUP>> {
56+
rectangle "==app.Application\n<size:10>[component]</size>\n\napplication context" <<ROOT>> as 2102746645
57+
}
58+
rectangle 0ROOT <<_GROUP>> {
59+
rectangle "==app.Commands\n<size:10>[component]</size>\n\napplication context" <<ROOT>> as 1118686339
60+
}
61+
rectangle 0ROOT <<_GROUP>> {
62+
rectangle "==app.Queries\n<size:10>[component]</size>\n\napplication context" <<ROOT>> as 441257907
63+
}
64+
2102746645 .[#000000].> 1118686339 : ""
65+
2102746645 .[#000000].> 441257907 : ""
66+
rectangle 11186863391APP <<_GROUP>> {
67+
rectangle "==command.CancelTrainingHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 1938493317
68+
}
69+
1118686339 .[#000000].> 1938493317 : ""
70+
rectangle 11186863391APP <<_GROUP>> {
71+
rectangle "==command.ScheduleTrainingHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 644318352
72+
}
73+
1118686339 .[#000000].> 644318352 : ""
74+
rectangle 11186863391APP <<_GROUP>> {
75+
rectangle "==command.MakeHoursAvailableHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 2676216945
76+
}
77+
1118686339 .[#000000].> 2676216945 : ""
78+
rectangle 11186863391APP <<_GROUP>> {
79+
rectangle "==command.MakeHoursUnavailableHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 3319250726
80+
}
81+
1118686339 .[#000000].> 3319250726 : ""
82+
rectangle 4412579071APP <<_GROUP>> {
83+
rectangle "==query.HourAvailabilityHandler\n<size:10>[component]</size>\n\napplication query" <<APP>> as 2484812079
84+
}
85+
441257907 .[#000000].> 2484812079 : ""
86+
rectangle 4412579071APP <<_GROUP>> {
87+
rectangle "==query.AvailableHoursHandler\n<size:10>[component]</size>\n\napplication query" <<APP>> as 1971034922
88+
}
89+
441257907 .[#000000].> 1971034922 : ""
90+
rectangle 6443183522ADAPTER <<_GROUP>> {
91+
rectangle "==adapters.FirestoreHourRepository\n<size:10>[component]</size>\n\nadapter component" <<ADAPTER>> as 3637611987
92+
}
93+
644318352 .[#000000].> 3637611987 : ""
94+
2676216945 .[#000000].> 3637611987 : ""
95+
3319250726 .[#000000].> 3637611987 : ""
96+
2484812079 .[#000000].> 3637611987 : ""
97+
rectangle 19710349222ADAPTER <<_GROUP>> {
98+
rectangle "==adapters.DatesFirestoreRepository\n<size:10>[component]</size>\n\nadapter component" <<ADAPTER>> as 2388943490
99+
}
100+
1971034922 .[#000000].> 2388943490 : ""
101+
1938493317 .[#000000].> 3637611987 : ""
102+
rectangle 36376119873DB <<_GROUP>> {
103+
database "==Firestore\n<size:10>[component]</size>\n\nfirestore client" <<DB>> as 650530190
104+
}
105+
3637611987 .[#000000].> 650530190 : ""
106+
rectangle 36376119873DOMAIN <<_GROUP>> {
107+
rectangle "==hour.Factory\n<size:10>[component]</size>\n\ndomain component" <<DOMAIN>> as 2036754401
108+
}
109+
3637611987 .[#000000].> 2036754401 : ""
110+
2388943490 .[#000000].> 650530190 : ""
111+
rectangle 23889434903DOMAIN <<_GROUP>> {
112+
rectangle "==hour.FactoryConfig\n<size:10>[component]</size>\n\ndomain component" <<DOMAIN>> as 415674051
113+
}
114+
2388943490 .[#000000].> 415674051 : ""
115+
2036754401 .[#000000].> 415674051 : ""
116+
@enduml

tools/c4/out/view-trainer.png

274 KB
Loading
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
This diagram has been generated with go-structurizr
2+
[https://github.com/krzysztofreczek/go-structurizr]
3+
4+
@startuml
5+
6+
title Service components
7+
8+
skinparam {
9+
shadowing false
10+
arrowFontSize 10
11+
defaultTextAlignment center
12+
wrapWidth 200
13+
maxMessageSize 100
14+
}
15+
hide stereotype
16+
top to bottom direction
17+
18+
scale 4096 width
19+
20+
skinparam rectangle<<_GROUP>> {
21+
FontColor #ffffff
22+
BorderColor #ffffff
23+
}
24+
25+
skinparam rectangle<<APP>> {
26+
BackgroundColor #1a4577
27+
FontColor #ffffff
28+
BorderColor #000000
29+
}
30+
31+
skinparam rectangle<<ADAPTER>> {
32+
BackgroundColor #2d69b7
33+
FontColor #ffffff
34+
BorderColor #000000
35+
}
36+
37+
skinparam rectangle<<DOMAIN>> {
38+
BackgroundColor #ffffff
39+
FontColor #000000
40+
BorderColor #000000
41+
}
42+
43+
skinparam database<<DB>> {
44+
BackgroundColor #c8c8c8
45+
FontColor #000000
46+
BorderColor #000000
47+
}
48+
49+
skinparam rectangle<<ROOT>> {
50+
BackgroundColor #ffffff
51+
FontColor #000000
52+
BorderColor #000000
53+
}
54+
55+
rectangle 0ROOT <<_GROUP>> {
56+
rectangle "==app.Application\n<size:10>[component]</size>\n\napplication context" <<ROOT>> as 1595196051
57+
}
58+
rectangle 0ROOT <<_GROUP>> {
59+
rectangle "==app.Queries\n<size:10>[component]</size>\n\napplication context" <<ROOT>> as 2827497597
60+
}
61+
rectangle 0ROOT <<_GROUP>> {
62+
rectangle "==app.Commands\n<size:10>[component]</size>\n\napplication context" <<ROOT>> as 2042358025
63+
}
64+
1595196051 .[#000000].> 2042358025 : ""
65+
1595196051 .[#000000].> 2827497597 : ""
66+
rectangle 28274975971APP <<_GROUP>> {
67+
rectangle "==query.AllTrainingsHandler\n<size:10>[component]</size>\n\napplication query" <<APP>> as 3287812968
68+
}
69+
2827497597 .[#000000].> 3287812968 : ""
70+
rectangle 28274975971APP <<_GROUP>> {
71+
rectangle "==query.TrainingsForUserHandler\n<size:10>[component]</size>\n\napplication query" <<APP>> as 1094798405
72+
}
73+
2827497597 .[#000000].> 1094798405 : ""
74+
rectangle 20423580251APP <<_GROUP>> {
75+
rectangle "==command.ApproveTrainingRescheduleHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 3887158788
76+
}
77+
2042358025 .[#000000].> 3887158788 : ""
78+
rectangle 20423580251APP <<_GROUP>> {
79+
rectangle "==command.CancelTrainingHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 224341371
80+
}
81+
2042358025 .[#000000].> 224341371 : ""
82+
rectangle 20423580251APP <<_GROUP>> {
83+
rectangle "==command.RejectTrainingRescheduleHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 2302791080
84+
}
85+
2042358025 .[#000000].> 2302791080 : ""
86+
rectangle 20423580251APP <<_GROUP>> {
87+
rectangle "==command.RescheduleTrainingHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 3456104041
88+
}
89+
2042358025 .[#000000].> 3456104041 : ""
90+
rectangle 20423580251APP <<_GROUP>> {
91+
rectangle "==command.RequestTrainingRescheduleHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 4186077052
92+
}
93+
2042358025 .[#000000].> 4186077052 : ""
94+
rectangle 20423580251APP <<_GROUP>> {
95+
rectangle "==command.ScheduleTrainingHandler\n<size:10>[component]</size>\n\napplication command" <<APP>> as 142372322
96+
}
97+
2042358025 .[#000000].> 142372322 : ""
98+
rectangle 34561040412ADAPTER <<_GROUP>> {
99+
rectangle "==adapters.TrainingsFirestoreRepository\n<size:10>[component]</size>\n\nadapter component" <<ADAPTER>> as 1383687574
100+
}
101+
3456104041 .[#000000].> 1383687574 : ""
102+
rectangle 34561040412ADAPTER <<_GROUP>> {
103+
rectangle "==adapters.UsersGrpc\n<size:10>[component]</size>\n\nadapter component" <<ADAPTER>> as 881049450
104+
}
105+
3456104041 .[#000000].> 881049450 : ""
106+
rectangle 34561040412ADAPTER <<_GROUP>> {
107+
rectangle "==adapters.TrainerGrpc\n<size:10>[component]</size>\n\nadapter component" <<ADAPTER>> as 2401551451
108+
}
109+
3456104041 .[#000000].> 2401551451 : ""
110+
4186077052 .[#000000].> 1383687574 : ""
111+
3287812968 .[#000000].> 1383687574 : ""
112+
224341371 .[#000000].> 881049450 : ""
113+
224341371 .[#000000].> 2401551451 : ""
114+
224341371 .[#000000].> 1383687574 : ""
115+
2302791080 .[#000000].> 1383687574 : ""
116+
3887158788 .[#000000].> 1383687574 : ""
117+
3887158788 .[#000000].> 881049450 : ""
118+
3887158788 .[#000000].> 2401551451 : ""
119+
142372322 .[#000000].> 1383687574 : ""
120+
142372322 .[#000000].> 881049450 : ""
121+
142372322 .[#000000].> 2401551451 : ""
122+
1094798405 .[#000000].> 1383687574 : ""
123+
rectangle 13836875743DB <<_GROUP>> {
124+
database "==Firestore\n<size:10>[component]</size>\n\nfirestore client" <<DB>> as 650530190
125+
}
126+
1383687574 .[#000000].> 650530190 : ""
127+
@enduml

tools/c4/out/view-trainings.png

226 KB
Loading

0 commit comments

Comments
 (0)