Skip to content

Commit f36955f

Browse files
authored
feat(app): ml | cyberver | redesign | + more (#1182)
2 parents b54b808 + fc8df10 commit f36955f

File tree

522 files changed

+19263
-3986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

522 files changed

+19263
-3986
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CHAIN_ID = space-pussy

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"FileReader": true,
3838
"cyblog": "readonly"
3939
},
40+
4041
"rules": {
4142
"valid-jsdoc": "off",
4243
"no-shadow": "off",

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ yarn-error.log*
2929
src/.DS_Store
3030

3131
storybook-static
32-
.env
32+
.env.*.local
3333

3434
# Local Netlify folder
3535
.netlify

.storybook/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const config: StorybookConfig = {
5656
test: /\.cozo$/,
5757
use: 'raw-loader',
5858
},
59+
{
60+
test: /\.rn$/,
61+
type: 'asset/source',
62+
},
5963
],
6064
},
6165
};

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"cybercongress",
66
"cyberlink",
77
"cyberlinks",
8+
"cybernet",
89
"denoms",
910
"helia",
1011
"investmint",
@@ -13,6 +14,8 @@
1314
"negentropy",
1415
"stylelint",
1516
"superintelligence",
17+
"websockets",
18+
"cyberver",
1619
"websockets"
1720
],
1821
"eslint.enable": true,
@@ -23,7 +26,7 @@
2326
"typescriptreact"
2427
],
2528
"editor.codeActionsOnSave": {
26-
"source.fixAll.eslint": true
29+
"source.fixAll.eslint": "explicit"
2730
},
2831
"css.validate": false,
2932
"less.validate": false,

docs/backend.md

Lines changed: 178 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,194 @@
1-
# Backend Architecture
1+
# CYB local backend(in-browser)
2+
3+
Cyb plays singinficat role in cyber infrastructure. The app reconstruct self-sufficient backend+frontend pattern inside the browser.
4+
In big view app consist from 3 parts:
25

36
```mermaid
47
graph TD;
8+
App["frontend\n(main thread)"]-.proxy.->Backend["backend\n(shared worker)"];
9+
App-.proxy.->Db["graph db\n(shared worker)"];
10+
Backend-.proxy.->Db;
11+
App<-.message\nchannels.->Backend;
12+
```
513

6-
subgraph frontend["frontend(main thread)"]
7-
App["Frontend"]-->Hook["useBackend()"];
8-
Hook-->methods("startSync()\nloadIpfs()\n...\nisReady\nipfsError\n...");
9-
Hook-.broadcast channel\n(any worker).->reducer["redux(state)"]
10-
Hook-.save history from app.->defferedDbApiFront[/"DefferedDbApi(proxy)"/]
11-
Hook--osenseApi["senseApi"];
12-
Hook--oipfsApiFront[/"ipfsApi(proxy)"/];
13-
senseApi--odbApi[/"dbApi(proxy)"/];
14-
end
14+
To reduce overload of main thread we have created 2 separate shared workers, where all the stuff is hosted. Bi-interraction between all layers occurs using proxy(comlink abstraction) or directly using broadcast channels.
1515

16-
dbApi<-.message channel.->dbWorker["dbApi"];
17-
subgraph dbWorkerGraph["cyb~db(worker)"]
18-
dbWorker<-.bindings(webApi).->cozodb{{"CozoDb(wasm)"}}
19-
end
16+
## Db layer
17+
18+
Db worker is pretty simple it it's host only local relational-graph-vector database - [[cozo]]. It's represented with DbApi in frontend and backend layers.
19+
Cozo provide bazing fast access to brain and ipfs data in relational form and also in vector format, processing by [ml]embedder.
2020

21-
defferedDbApiFront-.->defferedDbApi;
22-
ipfsApiFront<-.->ipfsApi;
23-
subgraph backgroundWorker["cyb~backend(worker)"]
24-
subgraph sync["sync service"]
25-
ipfsNode["ipfs node"];
26-
links;
27-
transactions;
21+
```mermaid
22+
graph TD;
23+
dbApi["dbApi"]--odb_meta_orm;
24+
subgraph rune["cozo db"]
25+
db_meta_orm[["meta orm"]]-.->db;
2826
end
29-
sync--oparticleResolver[["Particle resolver"]]
30-
particleResolver--oqueue;
31-
particleResolver--odbProxyWorker;
32-
sync--oipfsApi;
33-
sync--odbProxyWorker[/"dbApi(proxy)"/];
34-
defferedDbApi[["defferedDbApi"]]-->dbProxyWorker;
35-
queue-->defferedDbApi;
36-
ipfsApi--oqueue[["queue"]];
37-
ipfsApi--onode["node"];
38-
queue--balancer-->node;
39-
node--embedded-->helia;
40-
node--rpc-->kubo;
41-
node--embedded-->js-ipfs;
27+
```
28+
29+
### Db entities
30+
31+
- brain:
32+
- particles
33+
- embeddings
34+
- links
35+
- transactions
36+
- community
37+
- sense:
38+
39+
- sync items + update status
40+
41+
- system:
42+
- config
43+
- queue messages
44+
45+
## Backend layer
46+
47+
Backend worker is more complicated it contains significant elements of cyb architecture:
48+
49+
```mermaid
50+
graph TD;
51+
subgraph Backend["backend(shared worker)"]
52+
4253
subgraph ipfs["ipfs implementations"]
4354
helia;
4455
kubo;
4556
js-ipfs;
4657
end
4758
48-
dbProxyWorker<-.message channel.->dbWorker
59+
subgraph queues["message brokers"]
60+
ipfs_queue["ipfs load balancer"];
61+
queue["data processing queue aka bus"];
62+
end
63+
64+
subgraph rune["rune"]
65+
vm["virtual machine"]--ovm_bingen{{"cyb bindings"}};
66+
end
67+
68+
subgraph sense["sense"]
69+
link_sync["link sync"];
70+
msg_sync["message sync"];
71+
swarm_sync["swarm sync"];
72+
end
73+
74+
subgraph ml["ML transformers"]
75+
feature_extractor["embedder"];
76+
end
77+
78+
end
79+
```
80+
81+
### Ipfs module
82+
83+
Represented with IpfsApi at frontend layer, but also have direct access for some edge cases
84+
85+
- Uses module that encapsulate different Ipfs implementations(kubo, helia, js-ipfs(obsolete))
86+
- cache content(local storage & cozo)
87+
- preserve redundancy
88+
- Ipfs queue, process all requests to ipfs, prioritize, cancel non-actual requests and organize content pipeline
89+
- responsible for:
90+
- ipfs load balancing(limit of requests)
91+
- request prioritizing(actual requests first)
92+
- fault processing(switch fetch policy)
93+
- post processing(**inline rune vm** into pipeline)
94+
95+
```mermaid
96+
graph LR
97+
user(ipfsApi\nenqueue particle) --> q[["queue\n(balancer)"]] --> node[/"ipfs"/] -- found --> rune[rune vm] -- mutation | content --> cache["cache"] --> app(app\ncontent)
98+
node -. not found\n(retry | error) .-> q
99+
```
100+
101+
## Bus
102+
103+
Represented with some helpers and used for cases when blaancer is needed, some services not initialized yet(deffered actions), or long calculations is requered(ml inference, ipfs requests):
104+
105+
- particle, request ipfs, save; calc embedding
106+
- link, deffered save
107+
- message persistence is protected by db store
108+
109+
```mermaid
110+
graph TD;
111+
sender{{"enqueue(...)"}} -.message bus.-> bus
112+
subgraph task["task manager"]
113+
bus[["queue listener"]];
114+
115+
bus-.task.->db("store\ndata")--odb1["dbApi"];
116+
bus-.task.->ml("calculate\nembedding")--oml1["mlApi"];
117+
bus-.task.->ipfs("request ipfs\nlow-priority")--oi["ipfsApi"]
118+
end
119+
```
120+
121+
## Sense
122+
123+
Represented by SenseApi + subscription to broadcast channel at fronted layer. Provide continious update of cyberlinks related to my brain and my swarm, recieving on chain messages etc.:
124+
125+
- Particles service (pooling)
126+
- Transactions service (pooling + websocket)
127+
- My friends service (pooling)
128+
- Ipfs service(pooling)
129+
130+
All data and update status is stored into db, when some new data is recieved that triggers notification for frontendю
131+
132+
```mermaid
133+
graph TD;
134+
db[["dbApi"]];
135+
bus[["particle queue"]];
136+
137+
subgraph sense["sync service"]
138+
notification("notification service")
139+
140+
particles[["particle service"]]--onotification;
141+
transactions[["transaction service"]]--onotification;
142+
myfriend[["my friends service"]]--onotification;
143+
144+
particles -.loop.-> particles;
145+
transactions -.loop.-> transactions;
146+
myfriend -.loop.-> myfriend;
147+
end
148+
149+
150+
subgraph blockchain["blockchain"]
151+
lcd[["lcd"]]
152+
websockets("websockets")
153+
indexer[["indexer"]]
154+
end
155+
156+
subgraph app["frontend"]
157+
redux["redux"]
158+
sender{{"senseApi"}};
159+
end
160+
161+
notification -.message.-> redux;
162+
sender -.proxy.-> db;
163+
sense -.proxy.-> db;
164+
sense -.message.-> bus;
165+
bus -.proxy.-> db;
166+
167+
sense <-.request\nsubscriptin.->blockchain;
168+
169+
```
170+
171+
## Rune
172+
173+
Rune VM execution is pipelined thru special abstraction called entrypoints. VM have bindings to all app parts: DB, transformers, signer, blockchain api, ipfs and also includes context of the entrypoint.(see. [[scripting]] for detailed description).
174+
175+
## ML transformers
176+
177+
Represented my mlApi. Uses inference from local ML models hosted inside browser.
178+
179+
- future extractor. BERT-like model to trnsform text-to-embeddings.
180+
181+
```mermaid
182+
graph TD;
183+
subgraph ml["transformers"]
184+
embedder["embedder"];
185+
end
186+
187+
subgraph dbApi["dbApi"]
188+
db[["DB"]];
49189
end
190+
mlApi["mlApi"];
50191
192+
mlApi--odb;
193+
mlApi--oembedder;
51194
```

0 commit comments

Comments
 (0)