File size: 49,091 Bytes
41db8ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# ContextFlow Architecture: Complete System Overview

## Table of Contents
1. [System Vision](#1-system-vision)
2. [High-Level Architecture](#2-high-level-architecture)
3. [Frontend Layer](#3-frontend-layer)
4. [Backend Layer](#4-backend-layer)
5. [Agent Network](#5-agent-network)
6. [Reinforcement Learning Pipeline](#6-reinforcement-learning-pipeline)
7. [Data Flow](#7-data-flow)
8. [API Design](#8-api-design)
9. [Multi-Modal Detection](#9-multi-modal-detection)
10. [Privacy & Security](#10-privacy--security)
11. [Deployment Architecture](#11-deployment-architecture)

---

## 1. System Vision

**ContextFlow** is an AI-powered learning intelligence engine that predicts when learners will get confused BEFORE it happens, enabling proactive intervention in educational settings.

### Core Problem Solved
- Traditional learning systems are **reactive** - they respond after confusion occurs
- ContextFlow is **proactive** - it predicts confusion and intervenes before disengagement

### Key Innovations
1. **Predictive AI** - RL-based doubt prediction
2. **Gesture Control** - Hands-free learning assistance
3. **Multi-Agent Orchestration** - 9 specialized agents working in concert
4. **Privacy-First** - Face blur for classroom deployment

---

## 2. High-Level Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          USERS                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚  Students   β”‚  β”‚  Teachers   β”‚  β”‚  Researchers β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                 β”‚                 β”‚
          β–Ό                 β–Ό                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     PRESENTATION LAYER                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚                    React Frontend (Vite)                       β”‚   β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚   β”‚
β”‚  β”‚  β”‚  Learn  β”‚ β”‚ LLMFlow β”‚ β”‚Gestures β”‚ β”‚ Predict β”‚ ...     β”‚   β”‚
β”‚  β”‚  β”‚   Tab    β”‚ β”‚  Tab    β”‚ β”‚   Tab   β”‚ β”‚   Tab   β”‚         β”‚   β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚   β”‚
β”‚  β”‚                                                              β”‚   β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚   β”‚
β”‚  β”‚  β”‚         MediaPipe Camera Feed (Gesture + Face)       β”‚    β”‚   β”‚
β”‚  β”‚  β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚    β”‚   β”‚
β”‚  β”‚  β”‚    β”‚ Hand     β”‚              β”‚ Face     β”‚          β”‚    β”‚   β”‚
β”‚  β”‚  β”‚    β”‚ Detection β”‚              β”‚ Blur     β”‚          β”‚    β”‚   β”‚
β”‚  β”‚  β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚    β”‚   β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                                    β”‚ REST API (JSON)
                                    β”‚ WebSocket (Optional)
                                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       BACKEND LAYER (Flask)                          β”‚
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚                    API Gateway (Flask Blueprints)               β”‚   β”‚
β”‚  β”‚   /api/session/*  /api/predict/*  /api/gesture/*  /api/*     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                    β”‚                                  β”‚
β”‚                                    β–Ό                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              STUDY ORCHESTRATOR (Central Coordinator)           β”‚   β”‚
β”‚  β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚   β”‚
β”‚  β”‚   β”‚                   Agent Registry                    β”‚      β”‚   β”‚
β”‚  β”‚   β”‚  DoubtPredictor β”‚ Behavioral β”‚ Gesture β”‚ Recall  β”‚      β”‚   β”‚
β”‚  β”‚   β”‚  KnowledgeGraph β”‚ PeerLearn β”‚ LLMOrch β”‚ Prompt β”‚      β”‚   β”‚
β”‚  β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                    β”‚                                  β”‚
β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚    β–Ό               β–Ό             β–Ό             β–Ό               β–Ό      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Q-  β”‚       β”‚Behavioralβ”‚   β”‚Gestureβ”‚    β”‚Recallβ”‚     β”‚LLM  β”‚   β”‚
β”‚  β”‚Networkβ”‚     β”‚Agent   β”‚    β”‚Agent β”‚     β”‚Agent β”‚     β”‚Orch β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         DATA LAYER                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Checkpoint β”‚  β”‚  Session   β”‚  β”‚  Knowledge β”‚  β”‚   Real     β”‚ β”‚
β”‚  β”‚  (RL Model) β”‚  β”‚  State     β”‚  β”‚  Graph     β”‚  β”‚   Data     β”‚ β”‚
β”‚  β”‚   .pkl      β”‚  β”‚  JSON      β”‚  β”‚  NetworkX  β”‚  β”‚  Collectionβ”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## 3. Frontend Layer

### 3.1 Technology Stack

| Component | Technology | Purpose |
|-----------|------------|---------|
| Framework | React 18 | UI Components |
| Build Tool | Vite | Fast development |
| Styling | Tailwind CSS | Responsive design |
| Icons | Lucide React | Consistent icons |
| Camera | MediaPipe | Hand/Face detection |

### 3.2 Application Structure

```
frontend/src/
β”œβ”€β”€ App.jsx              # Main application (9 tabs)
β”œβ”€β”€ main.jsx             # Entry point
β”œβ”€β”€ index.css            # Global styles
β”œβ”€β”€ BrowserLLMLauncher.js  # AI chat launcher
└── MediaPipeProcessor.js # Camera + gesture processing
```

### 3.3 Tab Interface

| Tab | Purpose |
|-----|---------|
| **Learn** | Dashboard with predictions, reviews, gamification |
| **LLM Flow** | Browser-based AI launcher (no API keys) |
| **Gestures** | Train custom hand gestures |
| **Predict** | RL doubt prediction visualization |
| **Behavior** | Behavioral signal tracking |
| **Peer** | Social learning insights |
| **Stats** | Learning statistics |
| **Gamify** | Fish/XP rewards system |
| **Settings** | AI provider configuration |

### 3.4 BrowserLLMLauncher.js

Opens AI chats directly in browser without API keys:

```javascript
// Opens chat.openai.com with pre-filled context
openAIChat(context, model = 'gpt-4') {
  const url = `https://chat.openai.com/?q=${encodeURIComponent(context)}`;
  window.open(url, '_blank');
}
```

### 3.5 MediaPipeProcessor.js

Handles real-time camera processing:

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Camera Feed   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Hand Landmark  β”‚    β”‚   Face Mesh     β”‚
β”‚   Detection     β”‚    β”‚   Detection     β”‚
β”‚  (21 points)   β”‚    β”‚  (468 points)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚
         β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Gesture         β”‚    β”‚ Face Blur       β”‚
β”‚ Recognition     │───▢│ (Privacy)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Backend API    β”‚
β”‚  /api/gesture/  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## 4. Backend Layer

### 4.1 Technology Stack

| Component | Technology | Purpose |
|-----------|------------|---------|
| Framework | Flask | REST API |
| Async | asyncio | Non-blocking I/O |
| ML | PyTorch | RL model |
| Data | NumPy | Feature extraction |
| Graphs | NetworkX | Knowledge graphs |
| Storage | JSON/SQLite | Session persistence |

### 4.2 Flask Application Structure

```
backend/
β”œβ”€β”€ run.py                    # Application entry point
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py          # Flask app factory
β”‚   β”œβ”€β”€ config.py            # Configuration
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── main.py          # All API routes (889 lines)
β”‚   └── agents/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ study_orchestrator.py    # Central coordinator
β”‚       β”œβ”€β”€ doubt_predictor.py       # RL prediction
β”‚       β”œβ”€β”€ behavioral_agent.py      # Signal processing
β”‚       β”œβ”€β”€ hand_gesture_agent.py    # MediaPipe integration
β”‚       β”œβ”€β”€ recall_agent.py          # Spaced repetition
β”‚       β”œβ”€β”€ knowledge_graph_agent.py # Concept mapping
β”‚       β”œβ”€β”€ peer_learning_agent.py    # Social learning
β”‚       β”œβ”€β”€ llm_orchestrator_agent.py # Multi-AI
β”‚       β”œβ”€β”€ gesture_action_agent.py  # Gestureβ†’Action
β”‚       └── prompt_agent.py          # Prompt templates
```

### 4.3 Flask App Factory

```python
def create_app():
    app = Flask(__name__)
    
    # Load config
    app.config.from_object('app.config.Config')
    
    # Register blueprints
    from app.api.main import api
    app.register_blueprint(api, url_prefix='/api')
    
    # Initialize agents
    init_agents()
    
    return app
```

---

## 5. Agent Network

### 5.1 Agent Overview

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  STUDY ORCHESTRATOR                          β”‚
β”‚              (Central Coordinator)                             β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚   Doubt     β”‚  β”‚ Behavioral  β”‚  β”‚   Hand     β”‚        β”‚
β”‚  β”‚  Predictor  │◀─│   Agent     │─▢│  Gesture   β”‚        β”‚
β”‚  β”‚   Agent    β”‚  β”‚             β”‚  β”‚   Agent    β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚         β”‚                                  β”‚                β”‚
β”‚         β–Ό                                  β–Ό                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚ Knowledge  β”‚  β”‚   Recall    β”‚  β”‚    LLM      β”‚        β”‚
β”‚  β”‚   Graph    │◀─│   Agent     │─▢│ Orchestratorβ”‚        β”‚
β”‚  β”‚   Agent    β”‚  β”‚             β”‚  β”‚             β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                           β”‚
β”‚  β”‚    Peer    β”‚  β”‚   Gesture  β”‚                           β”‚
β”‚  β”‚  Learning  β”‚  β”‚   Action    β”‚                           β”‚
β”‚  β”‚   Agent    β”‚  β”‚   Mapper    β”‚                           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 5.2 StudyOrchestrator (Central Coordinator)

The orchestrator manages the learning lifecycle:

```python
class StudyOrchestrator:
    def __init__(self, user_id: str):
        self.user_id = user_id
        
        # Initialize all agents
        self.doubt_predictor = DoubtPredictorAgent(user_id)
        self.behavioral_agent = BehavioralAgent(user_id)
        self.gesture_agent = HandGestureAgent(user_id)
        self.recall_agent = RecallAgent(user_id)
        self.knowledge_graph = KnowledgeGraphAgent(user_id)
        self.peer_agent = PeerLearningAgent(user_id)
        
        # State management
        self.state = OrchestratorState()
```

**Session Lifecycle:**
1. **PRE_LEARNING** - Load predictions, check recalls, get peer insights
2. **ACTIVE_LEARNING** - Monitor signals, update predictions, capture doubts
3. **REVIEW** - Trigger spaced repetition, update knowledge graph
4. **POST_LEARNING** - Sync data, update gamification, generate summary

### 5.3 DoubtPredictorAgent (RL Core)

Predicts confusion before it happens:

```python
class DoubtPredictorAgent:
    def __init__(self, user_id: str, config: dict = None):
        self.user_id = user_id
        self.model = self._load_checkpoint()
        self.feature_extractor = FeatureExtractor()
    
    def predict_doubts(self, context: dict, top_k: int = 5):
        # 1. Extract 64-dim state vector
        state = self.feature_extractor.extract_state(context)
        
        # 2. Get Q-values from RL model
        q_values = self.model.predict(state)
        
        # 3. Return top-k predictions
        return self._format_predictions(q_values, top_k)
```

### 5.4 BehavioralAgent

Processes raw behavioral signals:

```python
class BehavioralSignal:
    mouse_hesitation: float      # Pause frequency
    scroll_reversals: int       # Back-and-forth
    time_on_page: float         # Seconds
    eye_tracking: Tuple[float, float]
    click_frequency: int
        
    def calculate_confusion_score(self) -> float:
        # Weighted average of signals
        weights = {
            'hesitation': 0.3,
            'reversals': 0.25,
            'time_on_page': 0.2,
            'tab_switches': 0.15,
            'back_button': 0.1
        }
        return weighted_sum(signals, weights)
```

### 5.5 HandGestureAgent

MediaPipe integration for gesture recognition:

```
Camera Frame
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ MediaPipe Hands β”‚
β”‚  (21 landmarks) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Gesture Templateβ”‚
β”‚   Matching      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Confidence    │──▢ Recognized Gesture
β”‚   Score (0-1)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Pre-built Gestures:**
| Gesture | Description |
|---------|-------------|
| pinch | Thumb + Index |
| swipe_up | 2-finger up |
| swipe_down | 2-finger down |
| swipe_right | 2-finger right |
| swipe_left | 2-finger left |
| point | Index extended |
| wave | Open palm wave |
| thumbs_up | πŸ‘ confirmation |
| thumbs_down | πŸ‘Ž rejection |
| fist | Closed hand |

### 5.6 RecallAgent

SM-2 based spaced repetition:

```python
class RecallCard:
    front: str          # Question
    back: str           # Answer
    interval: int       # Days until review
    ease_factor: float  # Difficulty (default 2.5)
    repetitions: int   # Successful reviews

def schedule_review(card: RecallCard, quality: int):
    if quality >= 3:  # Correct
        if card.repetitions == 0:
            card.interval = 1
        elif card.repetitions == 1:
            card.interval = 6
        else:
            card.interval *= card.ease_factor
        card.repetitions += 1
    else:  # Incorrect
        card.repetitions = 0
        card.interval = 1
    
    # Update ease factor
    card.ease_factor += (0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02))
    card.ease_factor = max(1.3, card.ease_factor)
```

### 5.7 KnowledgeGraphAgent

Concept mapping with NetworkX:

```python
class KnowledgeGraphAgent:
    def __init__(self, user_id: str):
        self.graph = nx.MultiDiGraph()
    
    def add_doubt_to_graph(self, doubt: dict):
        # Create node
        self.graph.add_node(
            doubt['concept'],
            type='concept',
            topic=doubt['topic'],
            timestamp=datetime.now()
        )
        
        # Connect to prerequisites
        for prereq in doubt.get('prerequisites', []):
            self.graph.add_edge(prereq, doubt['concept'], type='prerequisite')
        
        # Connect to related concepts
        for related in doubt.get('related', []):
            self.graph.add_edge(doubt['concept'], related, type='related')
    
    def find_learning_path(self, from_topic: str, to_topic: str):
        try:
            return nx.shortest_path(self.graph, from_topic, to_topic)
        except nx.NetworkXNoPath:
            return []
```

### 5.8 LLMOrchestrator

Multi-provider AI integration:

```python
class LLMOrchestrator:
    SUPPORTED_PROVIDERS = {
        'chatgpt': LLMProvider.CHATGPT,
        'gemini': LLMProvider.GEMINI,
        'claude': LLMProvider.CLAUDE,
        'deepseek': LLMProvider.DEEPSEEK,
        'ollama': LLMProvider.OLLAMA,
        'groq': LLMProvider.GROQ
    }
    
    async def query_parallel(self, request: LLMRequest):
        tasks = []
        for provider in request.providers:
            task = self._query_provider(provider, request)
            tasks.append(task)
        
        # Execute all queries concurrently
        responses = await asyncio.gather(*tasks, return_exceptions=True)
        return [r for r in responses if not isinstance(r, Exception)]
```

### 5.9 GestureActionMapper

Maps gestures to system actions:

```python
class GestureAction(Enum):
    QUERY_MULTI_LLM = "query_multi_llm"
    QUERY_CHATGPT = "query_chatgpt"
    QUERY_GEMINI = "query_gemini"
    TRIGGER_RL_LOOP = "trigger_rl_loop"
    CAPTURE_CONTENT = "capture_content"
    PAUSE_SESSION = "pause_session"
    RESUME_SESSION = "resume_session"

class GestureActionMapper:
    def __init__(self):
        self.action_rules = {
            GestureAction.QUERY_MULTI_LLM: {
                "trigger": {"finger_count": 2, "swipe": "right"}
            },
            GestureAction.PAUSE_SESSION: {
                "trigger": {"gesture": "open_palm"}
            },
            GestureAction.RESUME_SESSION: {
                "trigger": {"gesture": "thumbs_up"}
            }
        }
```

### 5.10 PeerLearningAgent

Social learning insights:

```python
class PeerLearningAgent:
    def get_peer_insights(self, topic: str):
        # Aggregate insights from "similar" students
        insights = []
        
        # Find students who learned this topic
        similar_students = self._find_similar_students(topic)
        
        for student in similar_students:
            # What confused them?
            insights.extend(student.difficult_concepts)
        
        # Return aggregated insights
        return self._aggregate_insights(insights)
```

---

## 6. Reinforcement Learning Pipeline

### 6.1 Problem Formulation

**State Space (64 dimensions):**
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Topic Embedding (32)  β”‚ Progress β”‚ Confusion (16) β”‚ Gesture (14) β”‚ Time β”‚
β”‚  TF-IDF of topic       β”‚ 0.0-1.0 β”‚ Behavioral    β”‚ Hand        β”‚ 0-1 β”‚
β”‚                        β”‚          β”‚ signals       β”‚ signals     β”‚      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Action Space (10 doubt types):**
1. `what_is_backpropagation`
2. `why_gradient_descent`
3. `how_overfitting_works`
4. `explain_regularization`
5. `what_loss_function`
6. `how_optimization_works`
7. `explain_learning_rate`
8. `what_regularization`
9. `how_batch_norm_works`
10. `explain_softmax`

**Reward Function:**
| Event | Reward |
|-------|--------|
| Correct prediction | +1.0 |
| Helpful explanation | +0.5 |
| Engagement maintained | +0.3 |
| False positive | -0.5 |
| Missed confusion | -1.0 |

### 6.2 Q-Network Architecture

```python
class QNetwork(nn.Module):
    def __init__(self, state_dim=64, action_dim=10, hidden_dim=128):
        super().__init__()
        self.fc1 = nn.Linear(state_dim, hidden_dim)  # 64 β†’ 128
        self.fc2 = nn.Linear(hidden_dim, hidden_dim) # 128 β†’ 128
        self.fc3 = nn.Linear(hidden_dim, action_dim) # 128 β†’ 10
    
    def forward(self, x):
        x = F.relu(self.fc1(x))  # ReLU activation
        x = F.relu(self.fc2(x))
        return self.fc3(x)  # Q-values for each action
```

### 6.3 Training Algorithm (GRPO)

```python
class DoubtPredictionRL:
    def train(self, epochs=10, batch_size=32):
        for epoch in range(epochs):
            for batch in self.dataloader:
                # 1. Get current Q-values
                q_values = self.q_network(batch.states)
                
                # 2. Compute targets (GRPO-style)
                with torch.no_grad():
                    next_q = self.target_network(batch.next_states).max(1)[0]
                    targets = batch.rewards + self.gamma * next_q * (~batch.dones)
                
                # 3. Compute loss and update
                loss = self.loss_fn(q_values.gather(1, batch.actions), targets)
                loss.backward()
                self.optimizer.step()
            
            # 4. Update target network
            self.update_target_network()
            
            # 5. Decay epsilon (exploration)
            self.epsilon *= self.epsilon_decay
```

### 6.4 Feature Extraction

```python
class FeatureExtractor:
    STATE_DIM = 64
    
    def extract_state(self, context: dict) -> np.ndarray:
        # Topic embedding (32 dims)
        topic_emb = self._extract_topic_embedding(context['topic'])
        
        # Progress (1 dim)
        progress = np.array([context['progress']])
        
        # Confusion signals (16 dims)
        confusion = self._extract_confusion_signals(context['confusion_signals'])
        
        # Gesture signals (14 dims)
        gestures = self._extract_gesture_signals(context['gesture_signals'])
        
        # Time spent (1 dim)
        time_spent = np.array([context['time_spent'] / 1800])
        
        # Concatenate
        return np.concatenate([topic_emb, progress, confusion, gestures, time_spent])
```

---

## 7. Data Flow

### 7.1 Learning Session Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        USER STARTS SESSION                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     ORCHESTRATOR.START_SESSION()                   β”‚
β”‚  1. Create new LearningSession                                    β”‚
β”‚  2. Load RL model checkpoint                                      β”‚
β”‚  3. Build learning context                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β–Ό               β–Ό               β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   Doubt   β”‚   β”‚ Behavioralβ”‚   β”‚   Peer    β”‚
        β”‚ Predictor β”‚   β”‚   Agent   β”‚   β”‚  Learning β”‚
        β”‚           β”‚   β”‚           β”‚   β”‚   Agent   β”‚
        β”‚  Predict  β”‚   β”‚  Analyze  β”‚   β”‚   Get     β”‚
        β”‚  doubts   β”‚   β”‚  signals  β”‚   β”‚  insights β”‚
        β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
              β”‚               β”‚               β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  RETURN INITIAL PREDICTIONS                        β”‚
β”‚  - Top 5 predicted doubts                                         β”‚
β”‚  - Pending reviews                                               β”‚
β”‚  - Peer insights                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 7.2 Behavioral Signal Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      REAL-TIME SIGNALS                           β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚  β”‚  Mouse  β”‚  β”‚ Scroll  β”‚  β”‚Gesture  β”‚  β”‚  Time   β”‚             β”‚
β”‚  β”‚Movement β”‚  β”‚ Pattern β”‚  β”‚Camera   β”‚  β”‚  On     β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚           β”‚           β”‚           β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   BEHAVIORAL AGENT     β”‚
              β”‚                       β”‚
              β”‚ calculate_confusion_   β”‚
              β”‚ score(signals)        β”‚
              β”‚                       β”‚
              β”‚ Returns: 0.0 - 1.0   β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   DOUBT PREDICTOR     β”‚
              β”‚                       β”‚
              β”‚ If score > 0.5:       β”‚
              β”‚   Re-predict doubts    β”‚
              β”‚   Trigger interventionβ”‚
              β”‚                       β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 7.3 Gesture-to-Action Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         CAMERA FRAME                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      MEDIAPIPE PROCESSING                         β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚   Hand Landmark      β”‚     β”‚    Face Mesh         β”‚          β”‚
β”‚  β”‚   Detection         β”‚     β”‚    (468 points)      β”‚          β”‚
β”‚  β”‚   (21 points)       β”‚     β”‚                       β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                           β”‚
              β–Ό                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GESTURE TEMPLATE   β”‚     β”‚    FACE BLUR         β”‚
β”‚  MATCHING           β”‚     β”‚    (Privacy)          β”‚
β”‚                     β”‚     β”‚                       β”‚
β”‚  Compare landmarks  β”‚     β”‚  Blur regions with    β”‚
β”‚  to known gestures  β”‚     β”‚  facial keypoints     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GESTURE RECOGNIZED  │──▢ Backend /api/gesture/recognize
β”‚                      β”‚
β”‚  {                   β”‚
β”‚    "gesture": "pinch",β”‚
β”‚    "confidence": 0.92β”‚
β”‚  }                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ GESTURE ACTION MAPPER β”‚
β”‚                      β”‚
β”‚ pinch ──────────────▢│ TRIGGER_AI_HELP
β”‚ swipe_right ────────▢│ LAUNCH_BROWSER_CHAT
β”‚ open_palm ──────────▢│ PAUSE_SESSION
β”‚ thumbs_up ──────────▢│ MARK_UNDERSTOOD
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## 8. API Design

### 8.1 API Structure

| Category | Endpoints |
|----------|-----------|
| Session | `/session/start`, `/session/update`, `/session/end`, `/session/insights` |
| Prediction | `/predict/doubts`, `/recommendations` |
| Behavior | `/behavior/track`, `/behavior/heatmap` |
| Graph | `/graph/add`, `/graph/query`, `/graph/path` |
| Review | `/review/due`, `/review/complete`, `/review/stats` |
| Peer | `/peer/insights`, `/peer/doubts`, `/peer/trending` |
| Gesture | `/gesture/list`, `/gesture/recognize`, `/gesture/training/*` |
| LLM | `/llm/query`, `/llm/gesture-action`, `/llm/rl/*` |

### 8.2 Session API

```python
# POST /api/session/start
{
    "user_id": "student123",
    "topic": "Machine Learning",
    "subtopic": "Neural Networks"
}

# Response
{
    "session_id": "session_1699999999.123",
    "topic": "Machine Learning",
    "predictions": [
        {
            "doubt": "how_overfitting_works",
            "confidence": 0.85,
            "explanation": "Student showing signs of confusion...",
            "priority": 1
        }
    ],
    "pending_reviews": 5,
    "peer_insights_count": 3
}
```

### 8.3 Doubt Prediction API

```python
# POST /api/predict/doubts
{
    "context": {
        "topic": "Neural Networks",
        "progress": 0.5,
        "confusion_signals": 0.7
    }
}

# Response
{
    "predictions": [
        {
            "doubt": "how_overfitting_works",
            "confidence": 0.85,
            "explanation": "...",
            "priority": 1,
            "estimated_time": "10 min",
            "prerequisites": ["regularization", "bias-variance"]
        }
    ]
}
```

---

## 9. Multi-Modal Detection

### 9.1 Supported Modalities

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MULTI-MODAL FUSION                             β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚  β”‚   Audio     β”‚  β”‚  Biometric  β”‚  β”‚ Behavioral  β”‚             β”‚
β”‚  β”‚             β”‚  β”‚             β”‚  β”‚             β”‚             β”‚
β”‚  β”‚ Speech rate β”‚  β”‚ Heart rate  β”‚  β”‚ Mouse moves β”‚             β”‚
β”‚  β”‚ Hesitations β”‚  β”‚ GSR         β”‚  β”‚ Scroll      β”‚             β”‚
β”‚  β”‚ Pauses      β”‚  β”‚ Eye trackingβ”‚  β”‚ Key presses β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜             β”‚
β”‚         β”‚                β”‚                β”‚                     β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                          β–Ό                                      β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”‚
β”‚              β”‚   WEIGHTED FUSION       β”‚                       β”‚
β”‚              β”‚                         β”‚                       β”‚
β”‚              β”‚ audio_weight:    0.2    β”‚                       β”‚
β”‚              β”‚ biometric_weight: 0.3   β”‚                       β”‚
β”‚              β”‚ behavioral_weight: 0.5  β”‚                       β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β”‚                          β”‚                                      β”‚
β”‚                          β–Ό                                      β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”‚
β”‚              β”‚  UNIFIED CONFUSION     β”‚                       β”‚
β”‚              β”‚       SCORE            β”‚                       β”‚
β”‚              β”‚       0.0 - 1.0       β”‚                       β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 9.2 Feature Extraction by Modality

**Audio (7 features):**
- Speech rate (WPM)
- Pause frequency
- Pause duration
- Pitch variation
- Volume level
- Hesitation count
- Question markers

**Biometric (6 features):**
- Heart rate (BPM)
- Heart rate variability
- Skin conductance (GSR)
- Skin temperature
- Eye blink rate
- Eye open duration

**Behavioral (8 features):**
- Mouse hesitation
- Scroll reversals
- Time on page
- Click frequency
- Back button usage
- Tab switches
- Copy attempts
- Search usage

---

## 10. Privacy & Security

### 10.1 Face Blur Implementation

```python
class FaceBlurProcessor:
    def __init__(self):
        self.face_mesh = mp_face_mesh.FaceMesh(
            static_image_mode=False,
            max_num_faces=1,
            refine_landmarks=True
        )
    
    def blur_face(self, frame):
        # Detect face landmarks
        results = self.face_mesh.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
        
        if results.multi_face_landmarks:
            # Get face region
            face_region = self._get_face_region(frame, results)
            
            # Apply Gaussian blur
            blurred = cv2.GaussianBlur(face_region, (51, 51), 0)
            
            # Replace face region
            frame = self._replace_region(frame, blurred, results)
        
        return frame
```

### 10.2 Data Privacy

| Data Type | Storage | Privacy |
|-----------|---------|---------|
| Video frames | None | Processed in-memory only |
| Face images | None | Auto-blurred |
| Hand landmarks | Optional | Anonymized |
| Session data | Local JSON | User-owned |
| Model weights | HuggingFace | Open |

---

## 11. Deployment Architecture

### 11.1 Development Setup

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      DEVELOPMENT                                  β”‚
β”‚                                                                  β”‚
β”‚  Terminal 1:                 Terminal 2:                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚ cd backend      β”‚         β”‚ cd frontend     β”‚               β”‚
β”‚  β”‚ python run.py   β”‚         β”‚ npm run dev     β”‚               β”‚
β”‚  β”‚                 β”‚         β”‚                 β”‚               β”‚
β”‚  β”‚ Flask :5001     β”‚         β”‚ Vite    :5173   β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚                           β”‚
            β”‚           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚           β”‚
            β–Ό           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    BROWSER (localhost)                            β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Frontend (:5173) <─────── Proxy ───────> Backend (:5001)β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 11.2 Production Setup

```
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β”‚   Load Balancer  β”‚
                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                    β”‚                    β”‚
              β–Ό                    β–Ό                    β–Ό
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚  Flask Worker β”‚    β”‚  Flask Worker β”‚    β”‚  Flask Worker β”‚
      β”‚    (:5001)    β”‚    β”‚    (:5001)    β”‚    β”‚    (:5001)    β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                    β”‚                    β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                                   β–Ό
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β”‚   Redis Cache   β”‚
                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                                   β–Ό
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β”‚   PostgreSQL    β”‚
                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 11.3 HuggingFace Model Hosting

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     HuggingFace Hub                              β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              namish10/contextflow-rl                     β”‚   β”‚
β”‚  β”‚                                                          β”‚   β”‚
β”‚  β”‚  checkpoint.pkl        ← Trained RL model            β”‚   β”‚
β”‚  β”‚  train_rl.py            ← Training script            β”‚   β”‚
β”‚  β”‚  feature_extractor.py    ← State extraction           β”‚   β”‚
β”‚  β”‚  online_learning.py      ← Continuous learning        β”‚   β”‚
β”‚  β”‚  data_collector.py      ← Real data collection        β”‚   β”‚
β”‚  β”‚  multimodal_detection.py ← Audio/biometric fusion      β”‚   β”‚
β”‚  β”‚  demo.ipynb             ← Interactive demo            β”‚   β”‚
β”‚  β”‚  RESEARCH_PAPER.md      ← Full documentation          β”‚   β”‚
β”‚  β”‚                                                          β”‚   β”‚
β”‚  β”‚  app/ (9 agents + API)                                β”‚   β”‚
β”‚  β”‚  frontend/ (React UI)                                  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Summary

ContextFlow is a comprehensive system combining:

1. **Predictive AI** - RL-based doubt prediction before confusion occurs
2. **Multi-Agent Architecture** - 9 specialized agents coordinated by orchestrator
3. **Gesture Recognition** - Privacy-first MediaPipe hand detection
4. **Multi-Modal Sensing** - Audio + Biometric + Behavioral fusion
5. **Browser-Based AI** - Direct AI chat launching without API keys
6. **Continuous Learning** - Online learning from user feedback

The system is production-ready with all 9 API endpoints working, complete agent network, and trained RL model available on HuggingFace.