Skip to content

Commit f74e714

Browse files
committed
docs: add mermaid architecture diagrams
1 parent 26929c1 commit f74e714

2 files changed

Lines changed: 207 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Contract (`contracts`)
4545
Architecture decision records
4646

4747
- Key architecture choices are documented in `adr/`.
48+
- Mermaid architecture diagrams are documented in `docs/architecture.md`.
4849
- See `adr/0001-sqlite-off-chain-mvp.md` for the SQLite off-chain MVP decision.
4950
- See `adr/0002-react-express-mvp.md` for the React + Express + Soroban MVP architecture decision.
5051

docs/architecture.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Stellar Goal Vault Architecture
2+
3+
This page captures the main runtime flows in GitHub-renderable Mermaid diagrams.
4+
5+
## Pledge Flow
6+
7+
```mermaid
8+
sequenceDiagram
9+
autonumber
10+
actor Contributor
11+
participant Frontend as React/Vite Dashboard
12+
participant Backend as Express Backend API
13+
participant Soroban as Soroban Contract Core
14+
participant Freighter as Freighter Wallet
15+
participant SQLite as SQLite store
16+
17+
Contributor->>Frontend: Select campaign, amount, and asset
18+
Frontend->>Backend: GET /api/config
19+
Backend-->>Frontend: contractId, RPC URL, network, asset map
20+
Frontend->>Soroban: Load contributor source account
21+
Soroban-->>Frontend: Account sequence and ledger state
22+
Frontend->>Soroban: Simulate contribute(campaignId, contributor, token, amount)
23+
Soroban-->>Frontend: Prepared transaction data
24+
Frontend->>Contributor: Show transaction preview
25+
Contributor-->>Frontend: Approve preview
26+
Frontend->>Freighter: signTransaction(prepared XDR)
27+
Freighter-->>Frontend: Signed transaction XDR
28+
Frontend->>Soroban: Submit signed transaction
29+
Soroban-->>Frontend: Confirmed transaction hash and timestamp
30+
Frontend->>Backend: POST /api/campaigns/:id/pledges/reconcile
31+
Backend->>Backend: Validate campaign, amount, contributor, tx hash
32+
Backend->>SQLite: Insert pledge, update campaign total, record event
33+
SQLite-->>Backend: Reconciled campaign state
34+
Backend-->>Frontend: Updated campaign and transaction hash
35+
Frontend-->>Contributor: Show pledge confirmation and refreshed campaign
36+
```
37+
38+
## Frontend Components
39+
40+
```mermaid
41+
flowchart LR
42+
subgraph Shell["React/Vite dashboard shell"]
43+
App["App.tsx"]
44+
WalletWidget["WalletWidget"]
45+
CampaignsTable["CampaignsTable"]
46+
DetailPanel["CampaignDetailPanel"]
47+
CreateForm["CreateCampaignForm"]
48+
Timeline["CampaignTimeline"]
49+
Analytics["CreatorAnalytics"]
50+
Backlog["IssueBacklog"]
51+
Preview["TransactionPreviewModal"]
52+
Toasts["ToastContainer"]
53+
Shortcuts["KeyboardShortcutsOverlay"]
54+
end
55+
56+
subgraph State["Client state and hooks"]
57+
FreighterHook["useFreighter"]
58+
LocalStorageHook["useLocalStorage"]
59+
ToastHook["useToast"]
60+
AppState[("campaigns, selectedCampaign, history, appConfig")]
61+
Preferences[("theme, filters, sort order")]
62+
Notifications[("toast queue")]
63+
end
64+
65+
subgraph Services["Frontend service layer"]
66+
ApiService["services/api.ts"]
67+
FreighterService["services/freighter.ts"]
68+
SorobanService["services/soroban.ts"]
69+
end
70+
71+
subgraph BackendRoutes["Express API endpoints"]
72+
CampaignRoutes["/api/campaigns"]
73+
ConfigRoute["/api/config"]
74+
HistoryRoute["/api/campaigns/:id/history"]
75+
ReconcileRoute["/api/campaigns/:id/pledges/reconcile"]
76+
RefundRoute["/api/campaigns/:id/refund"]
77+
IssuesRoute["/api/open-issues"]
78+
end
79+
80+
App --> WalletWidget
81+
App --> CampaignsTable
82+
App --> DetailPanel
83+
App --> CreateForm
84+
App --> Timeline
85+
App --> Analytics
86+
App --> Backlog
87+
App --> Preview
88+
App --> Toasts
89+
App --> Shortcuts
90+
91+
App --> FreighterHook
92+
App --> LocalStorageHook
93+
App --> ToastHook
94+
FreighterHook --> WalletWidget
95+
LocalStorageHook --> Preferences
96+
ToastHook --> Notifications
97+
AppState --> CampaignsTable
98+
AppState --> DetailPanel
99+
AppState --> Timeline
100+
AppState --> Analytics
101+
102+
App --> ApiService
103+
App --> FreighterService
104+
App --> SorobanService
105+
ApiService --> CampaignRoutes
106+
ApiService --> ConfigRoute
107+
ApiService --> HistoryRoute
108+
ApiService --> ReconcileRoute
109+
ApiService --> RefundRoute
110+
ApiService --> IssuesRoute
111+
FreighterService --> Preview
112+
SorobanService --> RefundRoute
113+
```
114+
115+
## SQLite Data Flow
116+
117+
```mermaid
118+
erDiagram
119+
CAMPAIGNS ||--o{ PLEDGES : receives
120+
CAMPAIGNS ||--o{ CAMPAIGN_EVENTS : records
121+
122+
CAMPAIGNS {
123+
TEXT id PK
124+
TEXT creator
125+
TEXT title
126+
TEXT description
127+
TEXT accepted_tokens_json
128+
REAL target_amount
129+
REAL pledged_amount
130+
INTEGER deadline
131+
INTEGER created_at
132+
INTEGER claimed_at
133+
TEXT metadata_json
134+
INTEGER max_per_contributor
135+
INTEGER deleted_at
136+
}
137+
138+
PLEDGES {
139+
INTEGER id PK
140+
TEXT campaign_id FK
141+
TEXT contributor
142+
REAL amount
143+
TEXT asset_code
144+
INTEGER created_at
145+
INTEGER refunded_at
146+
TEXT transaction_hash UK
147+
}
148+
149+
CAMPAIGN_EVENTS {
150+
INTEGER id PK
151+
TEXT campaign_id FK
152+
TEXT event_type
153+
INTEGER timestamp
154+
TEXT actor
155+
REAL amount
156+
TEXT metadata
157+
TEXT blockchain_metadata
158+
}
159+
```
160+
161+
```mermaid
162+
flowchart LR
163+
subgraph Writes["Write paths"]
164+
CreateCampaign["POST /api/campaigns"]
165+
LocalPledge["POST /api/campaigns/:id/pledges"]
166+
ChainPledge["POST /api/campaigns/:id/pledges/reconcile"]
167+
Claim["POST /api/campaigns/:id/claim"]
168+
Refund["POST /api/campaigns/:id/refund"]
169+
end
170+
171+
subgraph Tables["SQLite persistence"]
172+
Campaigns[("CAMPAIGNS")]
173+
Pledges[("PLEDGES")]
174+
Events[("CAMPAIGN_EVENTS")]
175+
end
176+
177+
subgraph Reads["Read models"]
178+
ListCampaigns["GET /api/campaigns"]
179+
Detail["GET /api/campaigns/:id"]
180+
History["GET /api/campaigns/:id/history"]
181+
Contributors["GET /api/campaigns/:id/contributors"]
182+
Stats["GET /api/stats and /api/leaderboard"]
183+
end
184+
185+
CreateCampaign --> Campaigns
186+
CreateCampaign --> Events
187+
LocalPledge --> Pledges
188+
LocalPledge --> Campaigns
189+
LocalPledge --> Events
190+
ChainPledge --> Pledges
191+
ChainPledge --> Campaigns
192+
ChainPledge --> Events
193+
Claim --> Campaigns
194+
Claim --> Events
195+
Refund --> Pledges
196+
Refund --> Campaigns
197+
Refund --> Events
198+
199+
Campaigns --> ListCampaigns
200+
Campaigns --> Detail
201+
Pledges --> Detail
202+
Events --> History
203+
Pledges --> Contributors
204+
Campaigns --> Stats
205+
Pledges --> Stats
206+
```

0 commit comments

Comments
 (0)