File size: 21,939 Bytes
5a81b95
 
e78514a
 
5a81b95
 
 
 
 
 
 
 
 
 
 
 
e78514a
5a81b95
e78514a
 
 
 
 
5a81b95
e78514a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# WidgeTDC - Enterprise AI Platform Architecture

**Last Updated:** 2025-12-13
**Status:** βœ… PRODUCTION LIVE - Cloud Deployment Active

## System Overview

WidgeTDC is an Enterprise-grade Autonomous Intelligence Platform featuring:
- **Semantic Vector Database** with multi-provider embeddings
- **Autonomous Task Engine** with learning loops
- **Distributed Event System** for scalability
- **Production-ready Infrastructure** with monitoring and logging
- **Modern Frontend** with React 19 and Tailwind CSS v4

---

## πŸš€ Production Deployment (2025-12-13)

### Live URLs
| Service | Platform | URL |
|---------|----------|-----|
| **Frontend** | Vercel Edge | `https://matrix-frontend-claus-krafts-projects.vercel.app` |
| **Backend API** | HuggingFace Spaces | `https://kraft102-widgettdc-api.hf.space` |

### Cloud Infrastructure
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     PRODUCTION ARCHITECTURE                              β”‚
β”‚                      "Headless Ghost" Pattern                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

   Browser ──▢ Vercel CDN ──▢ HuggingFace Spaces ──▢ Cloud Databases
                  β”‚                   β”‚                    β”‚
            React 19 PWA        Node.js 20           β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
            185 Widgets         63 MCP Tools         β”‚ Redis   β”‚
            Zustand State       Express API          β”‚ Neo4j   β”‚
                                                     β”‚ Neon PG β”‚
                                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Database Layer
| Database | Provider | Purpose |
|----------|----------|---------|
| **Redis** | Redis Cloud (EU-North-1) | Cache, Sessions, Event Bus |
| **Neo4j** | AuraDB Cloud | Knowledge Graph (4274 nodes, 5252 rels) |
| **PostgreSQL** | Neon Serverless | Vector Store (pgvector), Prisma ORM |
| **SQLite** | sql.js (in-memory) | Fallback for HF Spaces free tier |

### AI/LLM Providers
| Provider | Use Case |
|----------|----------|
| Google Gemini Pro | Primary reasoning |
| OpenAI GPT-4 | Fallback, embeddings |
| Anthropic Claude | Analysis tasks |
| DeepSeek V3 | Code generation |

---

## Recent Updates (2025-12-13)

### βœ… HuggingFace Spaces Deployment Fixed
- **Dockerfile Optimized**: Skip Puppeteer Chromium download
- **Memory Limits**: Reduced to 512MB for free tier compatibility
- **package-lock.json**: Regenerated correct monorepo lockfile
- **Data Directories**: `/app/data/*` created with proper permissions
- **Environment Variables**: `HF_SPACE=true`, `DOCKER=true` set

### βœ… Frontend Widgets Fixed
- **Icon Imports**: Added missing `Target`, `Video` imports
- **DataSources**: Added `threatIntel` to SourceLink.tsx
- **useEffect Fix**: Removed undefined `width/height` from dependency array
- **185 Widgets**: All rendering correctly

### βœ… Previous Updates (2025-11-26)
- CSS Architecture rebuilt for Tailwind v4
- PowerShell scripts standardized (PSScriptAnalyzer compliant)
- Build system fully functional

---

## Architecture Diagram

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         FRONTEND (React 19)                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ Widget Board β”‚  β”‚  MCP Client  β”‚  β”‚  Dashboard   β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚         β”‚                  β”‚                  β”‚                          β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β”‚
β”‚                            β”‚ WebSocket + REST API                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         BACKEND (Node.js + Express)                      β”‚
β”‚                             β–Ό                                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                     API LAYER                                    β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚    β”‚
β”‚  β”‚  β”‚   MCP   β”‚  β”‚  SRAG   β”‚  β”‚   PAL   β”‚  β”‚   AI    β”‚  ...      β”‚    β”‚
β”‚  β”‚  β”‚ Router  β”‚  β”‚   API   β”‚  β”‚   API   β”‚  β”‚  Proxy  β”‚           β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜           β”‚    β”‚
β”‚  β”‚       β”‚            β”‚            β”‚             β”‚                 β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚          β”‚            β”‚            β”‚             β”‚                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                  COGNITIVE LAYER                                 β”‚    β”‚
β”‚  β”‚                                                                   β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚    β”‚
β”‚  β”‚  β”‚ Autonomous Agent β”‚    β”‚ UnifiedGraphRAG  β”‚                  β”‚    β”‚
β”‚  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚    β”‚  Multi-hop RAG   β”‚                  β”‚    β”‚
β”‚  β”‚  β”‚  β”‚ Task Engineβ”‚  β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚    β”‚
β”‚  β”‚  β”‚  β”‚ & Learning β”‚  β”‚             β”‚                            β”‚    β”‚
β”‚  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚             β”‚                            β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚                            β”‚    β”‚
β”‚  β”‚           β”‚                       β”‚                            β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚    β”‚
β”‚  β”‚  β”‚      Unified Memory System                 β”‚                 β”‚    β”‚
β”‚  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚                 β”‚    β”‚
β”‚  β”‚  β”‚  β”‚ Working  β”‚  β”‚ Episodic β”‚  β”‚Proceduralβ”‚β”‚                 β”‚    β”‚
β”‚  β”‚  β”‚  β”‚  Memory  β”‚  β”‚  Memory  β”‚  β”‚  Memory  β”‚β”‚                 β”‚    β”‚
β”‚  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚                 β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚    β”‚
β”‚  β”‚                       β”‚                                         β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                          β”‚                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                  DATA & EMBEDDING LAYER                          β”‚    β”‚
β”‚  β”‚                                                                   β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚    β”‚
β”‚  β”‚  β”‚          Embedding Service (Multi-Provider)               β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β”‚ OpenAI  β”‚  β”‚HuggingFace β”‚  β”‚Transformers.jsβ”‚          β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β”‚ 1536D   β”‚  β”‚   768D     β”‚  β”‚    384D       β”‚          β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚   β”‚    β”‚
β”‚  β”‚  β”‚       └─────────────┴────────────────┴─ Auto-select       β”‚   β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚    β”‚
β”‚  β”‚                          β”‚ Generate embeddings                  β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚    β”‚
β”‚  β”‚  β”‚         PgVectorStoreAdapter (pgvector)                   β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β€’ Auto-embedding generation                              β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β€’ Semantic text search                                   β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β€’ Cosine similarity                                      β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  β€’ Namespace isolation                                    β”‚   β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚    β”‚
β”‚  β”‚                          β”‚                                       β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                             β”‚                                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                  EVENT & INTEGRATION LAYER                       β”‚    β”‚
β”‚  β”‚                                                                   β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚    β”‚
β”‚  β”‚  β”‚  Redis EventBus  │◄────    Ingestion Pipeline            β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  (Production)    β”‚    β”‚  β€’ Data Sources (20+)            β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  OR              β”‚    β”‚  β€’ Browser History               β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  In-Memory       β”‚    β”‚  β€’ Email (Gmail, Outlook)        β”‚   β”‚    β”‚
β”‚  β”‚  β”‚  (Development)   β”‚    β”‚  β€’ Cloud (Drive, OneDrive)       β”‚   β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚  β€’ Social (Twitter, LinkedIn)    β”‚   β”‚    β”‚
β”‚  β”‚                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   PERSISTENCE LAYER                                      β”‚
β”‚                            β–Ό                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚   PostgreSQL     β”‚  β”‚      Redis       β”‚  β”‚     Neo4j        β”‚      β”‚
β”‚  β”‚   + pgvector     β”‚  β”‚   Event Store    β”‚  β”‚  Knowledge Graph β”‚      β”‚
β”‚  β”‚  β€’ Embeddings    β”‚  β”‚  β€’ Pub/Sub       β”‚  β”‚  β€’ Entities       β”‚      β”‚
β”‚  β”‚  β€’ Documents     β”‚  β”‚  β€’ Cache         β”‚  β”‚  β€’ Relations      β”‚      β”‚
β”‚  β”‚  β€’ Metadata      β”‚  β”‚  β€’ Sessions      β”‚  β”‚  β€’ Inference      β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Directory Structure

```
WidgeTDC/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/              # Express.js backend
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ mcp/         # MCP protocol implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ cognitive/   # AI agents & RAG
β”‚   β”‚   β”‚   β”œβ”€β”€ memory/      # Memory systems
β”‚   β”‚   β”‚   β”œβ”€β”€ ingestion/   # Data ingestion
β”‚   β”‚   β”‚   └── api/         # REST endpoints
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── matrix-frontend/         # React 19 frontend βœ… BUILD FIXED
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ components/  # React components
β”‚       β”‚   β”œβ”€β”€ widgets/     # Widget implementations
β”‚       β”‚   └── mcp/         # MCP client
β”‚       β”œβ”€β”€ App.css          # βœ… REBUILT - All keyframes fixed
β”‚       β”œβ”€β”€ App.tsx
β”‚       └── package.json
β”‚
β”œβ”€β”€ packages/
β”‚   └── shared/              # Shared types & utilities
β”‚       β”œβ”€β”€ types/
β”‚       └── utils/
β”‚
β”œβ”€β”€ scripts/                 # βœ… UPDATED - PowerShell scripts
β”‚   β”œβ”€β”€ update_agent.ps1            # βœ… NEW - Agent updater
β”‚   β”œβ”€β”€ update_agent_github.ps1     # βœ… NEW - GitHub workflow updater
β”‚   β”œβ”€β”€ update_agent_readme.ps1     # βœ… NEW - README updater
β”‚   β”œβ”€β”€ build-shared.ps1
β”‚   β”œβ”€β”€ install-deepseek.ps1
β”‚   β”œβ”€β”€ setup-enterprise.ps1
β”‚   └── test_rag_flow.ps1
β”‚
β”œβ”€β”€ database/
β”‚   β”œβ”€β”€ migrations/          # SQL migrations
β”‚   └── schema.sql
β”‚
β”œβ”€β”€ .github/
β”‚   └── workflows/           # GitHub Actions
β”‚       β”œβ”€β”€ agent-*.yml      # Agent workflows
β”‚       └── ci.yml
β”‚
β”œβ”€β”€ docs/                    # Documentation
β”œβ”€β”€ tests/                   # Test suites
└── dist/                    # βœ… Build output (created successfully)
```

---

## Technology Stack

### Frontend
- **Framework**: React 19 (latest)
- **Build Tool**: Vite 6.4.1
- **Styling**: Tailwind CSS v4 (PostCSS)
- **State Management**: Zustand
- **Real-time**: WebSocket client
- **Testing**: Vitest + React Testing Library

### Backend
- **Runtime**: Node.js 20+
- **Framework**: Express.js
- **Language**: TypeScript (strict mode)
- **Real-time**: WebSocket (`ws` library)
- **MCP**: Custom implementation

### Database
- **Primary**: PostgreSQL 15+ with pgvector
- **Cache/Events**: Redis 7+
- **Graph**: Neo4j 5+ (optional)
- **Development**: SQLite (fallback)

### DevOps
- **Containerization**: Docker + Docker Compose
- **CI/CD**: GitHub Actions
- **Deployment**: Railway (configured)
- **Monitoring**: PM2 ecosystem

---

## Key Components

### 1. MCP (Model Context Protocol)
- **Location**: `apps/backend/src/mcp/`
- **Purpose**: Standardized AI agent communication
- **Features**:
  - Tool registration and execution
  - Resource management
  - Event broadcasting
  - WebSocket transport

### 2. UnifiedGraphRAG
- **Location**: `apps/backend/src/cognitive/UnifiedGraphRAG.ts`
- **Purpose**: Multi-hop semantic retrieval
- **Features**:
  - Entity extraction
  - Relation mapping
  - Context-aware search
  - Hybrid retrieval (vector + graph)

### 3. Autonomous Task Engine
- **Location**: `apps/backend/src/cognitive/AutonomousAgent.ts`
- **Purpose**: Self-directed task execution
- **Features**:
  - Goal decomposition
  - Learning from outcomes
  - Dynamic replanning
  - Memory integration

### 4. Widget System
- **Location**: `apps/matrix-frontend/src/widgets/`
- **Purpose**: Modular UI components
- **Features**:
  - Dynamic loading
  - MCP integration
  - Drag-and-drop layout
  - Settings persistence

---

## Build & Deployment Status

### βœ… Frontend Build
```bash
npm run build --prefix apps/matrix-frontend
# Status: βœ… SUCCESS (6.40s)
# Output: dist/ directory created
# Issues: None
```

### βœ… CSS Architecture
- **File**: `apps/matrix-frontend/App.css`
- **Status**: Completely rebuilt
- **Keyframes**: All properly structured
- **Tailwind**: v4 compatible (no @apply)
- **Animations**: All functional

### βœ… PowerShell Scripts
- **Location**: `scripts/`
- **Status**: PSScriptAnalyzer compliant
- **Issues**: None

---

## Configuration Files

### Build Configuration
- `vite.config.ts` - Vite build settings
- `tsconfig.json` - TypeScript compiler options
- `tailwind.config.js` - Tailwind CSS v4 config
- `postcss.config.js` - PostCSS plugins

### Runtime Configuration
- `ecosystem.config.js` - PM2 process management
- `docker-compose.yml` - Container orchestration
- `railway.json` - Railway deployment config

---

## Development Workflow

### Local Development
```bash
# Install dependencies
npm install

# Start backend
npm run dev:backend

# Start frontend (separate terminal)
npm run dev:frontend

# Run tests
npm test
```

### Production Build
```bash
# Build frontend
npm run build --prefix apps/matrix-frontend

# Build backend
npm run build --prefix apps/backend

# Start production server
npm start
```

---

## Security & Compliance

### Authentication
- JWT-based authentication
- Session management via Redis
- CORS configured for production

### Data Protection
- Encryption at rest (PostgreSQL)
- TLS for all network traffic
- Environment variable isolation

### Compliance
- GDPR-ready data handling
- Audit logging
- Data retention policies

---

## Monitoring & Observability

### Logging
- Structured JSON logs
- Log levels: ERROR, WARN, INFO, DEBUG
- Persistent storage in `logs/`

### Metrics
- PM2 monitoring
- Database connection pooling
- WebSocket connection tracking

### Health Checks
- `/health` endpoint
- Database connectivity
- Redis availability
- Memory usage

---

## Known Issues & Limitations

### βœ… Resolved
- ~~CSS build errors in App.css~~ **FIXED 2025-11-26**
- ~~PowerShell script warnings~~ **FIXED 2025-11-26**
- ~~Tailwind @apply compatibility~~ **FIXED 2025-11-26**

### Active
- None currently blocking

---

## Future Enhancements

### Planned Features
1. **Multi-tenant Support**: Workspace isolation
2. **Advanced Analytics**: Usage dashboards
3. **Plugin System**: Third-party widget support
4. **Mobile App**: React Native client

### Infrastructure
1. **Kubernetes**: Container orchestration
2. **Prometheus**: Metrics collection
3. **Grafana**: Visualization
4. **ELK Stack**: Log aggregation

---

## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md) for development guidelines.

## License

See [LICENSE](./LICENSE) for details.

---

**Architecture maintained by**: WidgeTDC Development Team  
**Last reviewed**: 2025-11-26  
**Next review**: 2025-12-26