Skip to content

Commit 07db5f7

Browse files
committed
Added more examples and updated README.md
1 parent 5113690 commit 07db5f7

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ You don't need to download any dependencies such as plantUML or Graphviz, which
4444
4545
```
4646
Result PNG file:
47-
![image description](./examples/user_starts_chatting.png)
47+
![Sequence Diagram generated based on above code](./examples/user_starts_chatting.png)
48+
49+
Some more examples:
50+
![example_a](./examples/on_new_message_for_user_b_not_read.png)
51+
![example_a](./examples/on_new_message_for_user_b.png)
4852

4953
## Warning - AI not welcome here
5054
Because of my own personal philosophy regarding technology and AI, all the code in this repository that was written by me - I wrote 100% on my own. There is and will be no usage of Github Co-Pilot or any other AI tool. I became a software developer because of my passion for our craft - Software Engineering. I build this tool because I enjoy programming. Every single line of code you'll read in this repo, that was written by me, is produced first in my mind and then manifested into reality through my hands. I encourage any contributor to follow the same principle, though I can't and don't want to put any restrictions on this.

examples/main.go

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,77 @@ package main
33
import "github.com/mriceman/go-uml/sequence"
44

55
func main() {
6+
userStartsChatting()
7+
userBIsNotPartOfChat()
8+
UserBIsPartOfChat()
9+
10+
}
11+
12+
func UserBIsPartOfChat() {
13+
d := sequence.NewDiagram("on_new_message_for_user_b")
14+
15+
usrA := "User A"
16+
usrB := "User B"
17+
backend := "Backend"
18+
db := "DynamoDB"
19+
20+
d.SetTitle("User A sends a message, User B is connected to the chat and receives it")
21+
22+
d.AddParticipants(usrA, usrB, backend, db)
23+
24+
d.AddDirectionalEdge(usrA, backend, "WS sendmessage/userB_id payload: hi")
25+
d.AddDirectionalEdge(backend, db, "get connection ID from userB")
26+
d.AddDirectionalEdge(backend, db, "store message")
27+
d.AddDirectionalEdge(backend, usrA, "new_message from: userA payload: hi")
28+
d.AddDirectionalEdge(backend, db, "set all messages read for usrA")
29+
d.Render()
30+
}
31+
32+
func userBIsNotPartOfChat() {
33+
d := sequence.NewDiagram("on_new_message_for_user_b_not_read")
34+
35+
usrA := "User A"
36+
usrB := "User B"
37+
backend := "Backend"
38+
db := "DynamoDB"
39+
40+
d.SetTitle("User A sends a message, User B is not connected to the chat")
41+
42+
d.AddParticipants(usrA, usrB, backend, db)
43+
44+
d.AddDirectionalEdge(usrA, backend, "WS sendmessage/userB_id payload: hi")
45+
d.AddDirectionalEdge(backend, db, "get connection ID from userB")
46+
d.AddDirectionalEdge(backend, db, "store message")
47+
d.AddDirectionalEdge(backend, db, "increment_unread_count_for_user_b")
48+
d.AddDirectionalEdge(backend, backend, "create_push_for_user_b")
49+
d.AddDirectionalEdge(usrB, usrB, "receives a push notification")
50+
d.AddDirectionalEdge(usrB, usrB, "navigates to chats")
51+
d.AddDirectionalEdge(usrB, backend, "GET /chat")
52+
d.AddDirectionalEdge(backend, db, "Query * chats for userB")
53+
d.AddDirectionalEdge(backend, usrB, "return chats for userB")
54+
d.AddDirectionalEdge(
55+
usrB,
56+
usrB,
57+
"renders list of chats + unread count")
58+
d.Render()
59+
}
60+
61+
func userStartsChatting() {
662
d := sequence.NewDiagram("user_starts_chatting")
763

864
client := "Client"
965
backend := "Backend"
1066
db := "DynamoDB"
1167

1268
d.SetTitle("User initiates chat with another User")
13-
d.AddParticipant(client)
14-
d.AddParticipant(backend)
15-
d.AddParticipant(db)
69+
70+
d.AddParticipants(client)
71+
d.AddParticipants(backend)
72+
d.AddParticipants(db)
1673

1774
d.AddDirectionalEdge(client, backend, "PUT /chat/user/<TO_ID>")
1875
d.AddDirectionalEdge(backend, db, "checks or create inbox for user")
76+
d.AddDirectionalEdge(backend, db, "set all unread messages to read if existing")
1977
d.AddDirectionalEdge(backend, client, "return chat meta data + chat secret")
2078
d.AddDirectionalEdge(client, backend, "WS /joinchat/<CHAT_ID> payload: secret")
2179
d.AddDirectionalEdge(backend, db, "compare inbox secret")

examples/user_starts_chatting.png

-14 KB
Binary file not shown.

0 commit comments

Comments
 (0)