File size: 42,395 Bytes
c6204f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
---
title: HelloFibro
emoji: πŸ’œ
colorFrom: red
colorTo: yellow
sdk: gradio
sdk_version: 6.15.1
app_file: app.py
python_version: "3.12"
startup_duration_timeout: 1h
suggested_hardware: zero-a10g
short_description: Multimodal fibromyalgia support with MedGemma
models:
  - google/medgemma-27b-it
---

<p align="center">
<img width="250" height="250" alt="logo" src="https://github.com/user-attachments/assets/c2ad2088-729e-4257-9793-2f96f49053b0" />
</p>

<p align="center">
  <strong>AI-powered support companion for people living with fibromyalgia</strong>
</p>

<p align="center">
  <a href="#-features">Features</a> β€’
  <a href="#-demo">Demo</a> β€’
  <a href="#-quick-start">Quick Start</a> β€’
  <a href="#-tech-stack">Tech Stack</a> β€’
  <a href="#-architecture">Architecture</a> β€’
  <a href="#-workflows">Workflows</a>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python">
  <img src="https://img.shields.io/badge/Gradio-6.0-FF7C00?style=for-the-badge&logo=gradio&logoColor=white" alt="Gradio">
  <img src="https://img.shields.io/badge/Claude-Sonnet_4-191919?style=for-the-badge&logo=anthropic&logoColor=white" alt="Claude">

</p>

<p align="center">
  <img src="https://img.shields.io/badge/UI-Art_Deco_Inspired-8B0000?style=flat-square" alt="Art Deco">
  <img src="https://img.shields.io/badge/Accessibility-WCAG_AA-D4AF37?style=flat-square" alt="WCAG AA">
  <img src="https://img.shields.io/badge/Languages-21_Supported-white?style=flat-square" alt="21 Languages">
</p>

---

## πŸ“– About

**HelloFibro** is an AI assistant designed specifically for people living with fibromyalgia. It provides emotional support, evidence-based information, practical coping strategies, and medication managementβ€”all through a beautiful, accessible interface optimized for those experiencing chronic pain and fatigue.

### Why HelloFibro?

Living with fibromyalgia means dealing with invisible symptoms that others often don't understand. HelloFibro was built with deep empathy and understanding:

- πŸ’™ **Validation First** β€” Your pain is real. Your experiences matter.
- 🧠 **Brain Fog Friendly** β€” Clear, simple interface designed for cognitive challenges
- πŸŒ™ **Gentle Design** β€” Art Deco-inspired aesthetics that are calming, not overwhelming
- 🌍 **21 Languages** β€” Full internationalization with native language support
- πŸ”’ **Privacy Focused** β€” No data persistence, session-only storage

---

## 🎬 Demo

https://github.com/user-attachments/assets/4f57d250-8355-4167-927e-f14fa78e8a6e

The hosted MedGemma version is a research/portfolio demonstration, not a
medical device or healthcare service. Chat access is gated by acceptance of the
[HelloFibro HAI-DEF Demo Use Terms](docs/HAI_DEF_DEMO_TERMS.md), which
incorporate Google's
[HAI-DEF Terms of Use](https://developers.google.com/health-ai-developer-foundations/terms)
and
[Prohibited Use Policy](https://developers.google.com/health-ai-developer-foundations/prohibited-use-policy).

---

## ✨ Features

### πŸ’¬ Empathetic AI Chat

The heart of HelloFibroβ€”intelligent, understanding conversations powered by Claude Sonnet 4.

| Feature | Description |
|---------|-------------|
| **Streaming Responses** | Real-time typing effect for natural conversation flow |
| **Fibromyalgia Expertise** | Specialized knowledge about symptoms, triggers, and management |
| **Session Memory** | Remembers context within your conversation |
| **Markdown Support** | Rich formatting for clear, readable responses |
| **Brain Fog Consideration** | Short paragraphs, clear language, patient pacing |
| **Medical Context Awareness** | Automatically detects worsening factors in your messages |
| **EULAR 2016 Compliance** | Recommendations align with EU clinical guidelines |

```
User: Mam dziś bardzo silny ból i nie wiem co robić

HelloFibro: πŸ’™ Bardzo mi przykro, ΕΌe mierzysz siΔ™ dziΕ› z takim silnym bΓ³lem. 
To musi być naprawdę trudne.

Kilka rzeczy, ktΓ³re mogΔ… pomΓ³c w tej chwili:
β€’ ZnajdΕΊ wygodnΔ… pozycjΔ™ i pozwΓ³l sobie odpoczΔ…Δ‡
β€’ CiepΕ‚y okΕ‚ad moΕΌe przynieΕ›Δ‡ ulgΔ™
β€’ Spokojne, gΕ‚Δ™bokie oddychanie...
```

### πŸ’Š Medication Management

Comprehensive medication tracking designed for chronic illness management.

| Feature | Description |
|---------|-------------|
| **Quick Add** | Add medications via chat or form interface |
| **Visual Tracking** | See all medications with taken/pending status |
| **One-Tap Logging** | Mark medications as taken with a single click |
| **Missed Dose Alerts** | Smart notifications for missed doses after 4 AM |
| **Reminder Toggle** | Enable/disable reminders per medication |
| **Adherence Stats** | Track your medication compliance |

#### ⚠️ Missed Dose Notification

When you miss a medication dose, HelloFibro will remind you the next morning (after 4:00 AM) with a gentle notification:

| Action | Description |
|--------|-------------|
| **βœ“ WziΔ™ty** | Mark as taken late (still counts for adherence) |
| **βœ— PominiΔ™ty** | Register as missed dose |
| **Odrzuć** | Dismiss notification without logging |

The notification uses calming amber colors (not aggressive red) following healthcare UX best practices for reduced alert fatigue.

**Supported medication categories:**
- Fibromyalgia/Neuropathic (Pregabalin, Duloxetine, Gabapentin...)
- NSAIDs (Ibuprofen, Ketoprofen, Naproxen...)
- Stronger painkillers (Tramadol, Tapentadol...)
- Muscle relaxants (Tizanidine, Baclofen...)
- Sleep aids (Melatonin, Trazodone...)
- Supplements (Magnesium, Vitamin D3, CBD oil...)

### πŸ“… Appointment Management

Track and manage your doctor appointments with smart reminders.

| Feature | Description |
|---------|-------------|
| **Add Appointments** | Schedule visits with doctor name, specialty, date/time, location |
| **Specialty Types** | Pre-defined medical specialties (Rheumatologist, Neurologist, etc.) |
| **Visual Tracking** | See upcoming appointments with status indicators |
| **Smart Reminders** | Optional day-before reminder notifications |
| **Notes** | Add questions and notes for each appointment |
| **Status Indicators** | Today, Soon, Upcoming, Past appointment badges |

**Medical use cases:**
- Schedule rheumatologist follow-ups
- Track physiotherapy sessions
- Prepare questions for specialist visits
- Never miss important appointments

### πŸ“Ž File Analysis

Upload and discuss medical documents with AI assistance.

| File Type | Supported Formats | Capabilities |
|-----------|-------------------|--------------|
| **Documents** | PDF, DOCX, DOC | Extract text, find key health info |
| **Spreadsheets** | XLSX, XLS, CSV | Analyze symptoms, patterns, statistics |
| **Text Files** | TXT, MD, JSON, XML, LOG | Parse and explain content |
| **Images** | PNG, JPG, GIF, WEBP | Describe and discuss |
| **Code** | PY, JS, HTML, CSS | Explain and analyze |

**Medical use cases:**
- πŸ“‹ Prescription analysis
- πŸ“Š Symptom diary review
- 🩺 Lab results discussion
- πŸ“ Doctor visit preparation

### 🧠 Medical Intelligence Layer

Advanced AI-powered medical reasoning system for evidence-based fibromyalgia support.

| Component | Description |
|-----------|-------------|
| **Adaptive Reasoning Router** | Routes queries to appropriate reasoning depth based on complexity |
| **Medical Knowledge Service** | Queries 15+ worsening factors, EULAR guidelines, differential diagnosis |
| **EU Guidelines Validator** | Validates recommendations against EULAR 2016, German S3, UK NICE |
| **FHIR Patient Profile** | HL7 FHIR R4-compliant patient model with ACR 2016 criteria |
| **Agent Council** | Multi-agent system with backtracking exploration for complex cases |

#### Reasoning Modes

| Mode | Complexity | Use Case |
|------|------------|----------|
| **Parallel Short** | < 0.3 | Simple symptom questions, medication lookup |
| **Sequential Medium** | 0.3-0.7 | Symptom pattern analysis, treatment comparison |
| **Deep Sequential** | > 0.7 | Differential diagnosis, treatment-resistant cases |

#### Medical Knowledge Base

- **15 Worsening Factors** with severity scores, mechanisms, and neurotransmitter impacts
- **EULAR 2016 Recommendations** β€” Strong FOR, Weak FOR, Strong AGAINST
- **German S3 & UK NICE Guidelines** β€” First-line treatments, contraindications
- **Differential Diagnosis** β€” Lyme, hypothyroidism, vitamin D deficiency, ACR 2016 criteria
- **Medication Database** β€” EU/FDA approval status, response rates, contraindications

#### Automatic Factor Detection

The system detects worsening factors mentioned in your messages:

```
User: "I can't sleep and I'm very stressed lately"

Detected Factors:
- sleep_deprivation (sleep, insomnia keywords)
- hpa_axis_dysregulation (stress, anxiety keywords)

β†’ Enhanced response with relevant coping strategies
```

### 🌍 Multi-Language Support

Full internationalization with 21 supported languages.

| Region | Languages |
|--------|-----------|
| **Europe** | English (US/UK), Polish, German, Spanish, French, Italian, Dutch, Portuguese, Swedish, Norwegian, Danish |
| **Asia** | Japanese, Korean, Chinese, Thai, Indonesian, Hindi |
| **Middle East** | Arabic, Hebrew, Turkish |

**Features:**
- Language selector in the UI sidebar
- All UI elements fully translated
- Automatic fallback to English for missing translations
- Easy to add new languages via JSON translation files

### 🎨 Premium Design

Art Deco-inspired healthcare aesthetic that's both beautiful and functional.

| Design Element | Details |
|----------------|---------|
| **Primary Color** | Deep Crimson `#8B0000` β€” trust, medical seriousness |
| **Accent Color** | Warm Gold `#D4AF37` β€” premium, hopeful |
| **Background** | Ivory/Pearl `#FEFEFE` β€” clean, calming |
| **Typography** | Playfair Display (headings) + DM Sans (body) |
| **Accessibility** | WCAG AA compliant, high contrast for tired eyes |

---

## πŸ› οΈ Tech Stack

### Core Technologies

| Component | Technology | Version | Purpose |
|-----------|------------|---------|---------|
| **Runtime** | Python | 3.10+ | Core programming language |
| **Web Framework** | Gradio | 6.0+ | Modern UI with messages format |
| **AI Provider** | OpenRouter | - | LLM API gateway |
| **AI Model** | Claude Sonnet 4 | Latest | Empathetic, intelligent responses |
| **Validation** | Pydantic | 2.11+ | Type-safe data models |
| **Configuration** | pydantic-settings | 2.7+ | Environment management |
| **Medical Standards** | HL7 FHIR R4 | - | Interoperable patient data |

### Document Processing

| Library | Purpose |
|---------|---------|
| **PyMuPDF (fitz)** | PDF text extraction |
| **python-docx** | Word document parsing |
| **pandas** | CSV/Excel data analysis |
| **openpyxl** | Excel XLSX support |
| **xlrd** | Legacy XLS support |

### Development Tools

| Tool | Purpose |
|------|---------|
| **pytest** | Testing framework |
| **pytest-asyncio** | Async test support |
| **black** | Code formatting |
| **ruff** | Fast Python linter |
| **mypy** | Static type checking |
| **loguru** | Beautiful logging |

### Dependencies Overview

```txt
# Core Framework
gradio>=6.0.0
openai>=1.54.0
pydantic>=2.11.0
pydantic-settings>=2.7.0

# Document Processing
PyMuPDF>=1.24.0
python-docx>=1.1.0
pandas>=2.2.0

# Development
pytest>=8.3.0
black>=24.10.0
ruff>=0.8.0
```

---

## πŸ—οΈ Architecture

### System Overview

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         USER INTERFACE                          β”‚
β”‚                     (Gradio 6.0 Web App)                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Chat UI   β”‚  Medication UI   β”‚  File Upload   β”‚  Quick Actionsβ”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚               β”‚                 β”‚                β”‚
       β–Ό               β–Ό                 β–Ό                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      APPLICATION LAYER                          β”‚
β”‚                         (app/main.py)                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ ChatHandler β”‚ MedicationReminderβ”‚     FileProcessor             β”‚
β”‚ (chat.py)   β”‚  (reminders.py)  β”‚     (main.py)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚               β”‚
       β–Ό               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        CORE SERVICES                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       LLMAgent        β”‚           Data Models                   β”‚
β”‚      (agents.py)      β”‚         (schemas.py)                    β”‚
β”‚                       β”‚                                         β”‚
β”‚  β€’ Async OpenAI SDK   β”‚  β€’ Medication / MedicationLog          β”‚
β”‚  β€’ Streaming support  β”‚  β€’ ConversationSession                 β”‚
β”‚  β€’ Error handling     β”‚  β€’ MedicationState                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      EXTERNAL SERVICES                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    OpenRouter API                               β”‚
β”‚              (anthropic/claude-sonnet-4)                        β”‚
β”‚                                                                 β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚         β”‚  HTTP/HTTPS + Streaming SSE      β”‚                   β”‚
β”‚         β”‚  β€’ Max 4096 tokens               β”‚                   β”‚
β”‚         β”‚  β€’ Temperature 0.7               β”‚                   β”‚
β”‚         β”‚  β€’ Async with httpx              β”‚                   β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Component Details

#### 1. Main Interface (`app/main.py`)
- Creates Gradio 6 Blocks interface
- Handles file upload and processing
- Coordinates chat and medication features
- Injects custom CSS styling

#### 2. Chat Handler (`app/chat.py`)
- Manages conversation sessions
- Converts between Gradio 6 messages format and OpenAI API
- Handles streaming and non-streaming responses
- **Detects worsening factors** in user messages
- **Enhances system prompts** with medical context
- **Caches medical context** for performance (60s TTL)

#### 3. LLM Agent (`app/llm_agent.py`)
- Async OpenAI SDK client for OpenRouter
- Loads system prompt from file
- Implements retry logic and error handling
- Supports both streaming and batch responses

#### 4. Medical Intelligence Services (`app/services/`)

| Service | Purpose |
|---------|---------|
| **AdaptiveReasoningRouter** | Routes queries to parallel/sequential/deep modes based on complexity |
| **MedicalKnowledgeService** | 8 query methods for features, guidelines, differential diagnosis |
| **EUGuidelinesValidator** | Validates against EULAR 2016, German S3, UK NICE guidelines |

#### 5. Multi-Agent System (`app/agents/`)

| Agent | Role |
|-------|------|
| **FibroAgentCouncil** | Orchestrates specialized agents with consensus synthesis |
| **SymptomAnalyzer** | Analyzes symptom patterns and severity |
| **TherapyExpert** | Recommends evidence-based treatments |
| **LifestyleCoach** | Provides pacing and lifestyle strategies |
| **RiskAssessor** | Evaluates safety and recommends escalation |

**Exploration Strategies:**
- **Parallel Consensus** β€” All agents run simultaneously for routine queries
- **Deep Sequential with Backtracking** β€” DFS-style hypothesis exploration for complex cases

#### 6. FHIR Patient Profile (`app/schemas/patient.py`)
- HL7 FHIR R4 compliant patient resource
- **WPI** (Widespread Pain Index) 0-19
- **SSS** (Symptom Severity Score) 0-12
- **ACR 2016 criteria** automatic calculation
- **PHI masking** for privacy protection

#### 7. Medication Reminder (`app/reminders.py`)
- In-memory medication state management
- LLM command parsing (`[MEDICATION_CMD: ...]`)
- Adherence tracking and statistics
- Pending reminder detection
- **Missed dose detection** (after 4 AM daily check)
- Actions: mark taken late, register missed, dismiss

#### 8. Appointment Reminder (`app/appointments.py`)
- Doctor appointment scheduling and tracking
- Specialty-based categorization
- Day-before reminder system
- Status indicators (Today, Soon, Upcoming, Past)
- LLM command parsing (`[APPOINTMENT_CMD: ...]`)

#### 9. Internationalization (`app/i18n.py`)
- 21 supported languages with JSON translation files
- Dynamic language switching at runtime
- Nested key access with dot notation
- Automatic fallback to English
- `UIStrings` class for type-safe UI text access

#### 10. Configuration (`app/config.py`)
- Pydantic Settings with validation
- Environment variable loading
- Type-safe configuration access
- Default language setting

#### 11. Data Models (`models/schemas.py`)
- Pydantic 2.11 models
- Gradio 6 messages format support
- Medication and logging schemas

### Directory Structure

```
hellofibro/
β”œβ”€β”€ app/                          # Application code
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py                   # Gradio interface + file processing
β”‚   β”œβ”€β”€ config.py                 # Pydantic settings
β”‚   β”œβ”€β”€ llm_agent.py              # LLM agent (OpenRouter)
β”‚   β”œβ”€β”€ chat.py                   # Chat session management + medical context
β”‚   β”œβ”€β”€ prompts.py                # LLM prompts and file hints
β”‚   β”œβ”€β”€ i18n.py                   # Internationalization service (21 languages)
β”‚   β”œβ”€β”€ security.py               # Input sanitization + HIPAA audit
β”‚   β”œβ”€β”€ reminders.py              # Medication system
β”‚   β”œβ”€β”€ appointments.py           # Appointment management
β”‚   β”‚
β”‚   β”œβ”€β”€ agents/                   # πŸ†• Multi-agent system
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── council.py            # FibroAgentCouncil with backtracking
β”‚   β”‚
β”‚   β”œβ”€β”€ schemas/                  # πŸ†• Medical data schemas
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── patient.py            # FHIR R4 patient profile + ACR 2016
β”‚   β”‚
β”‚   └── services/                 # πŸ†• Medical intelligence services
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ reasoning_router.py   # Adaptive chain-of-thought scaling
β”‚       β”œβ”€β”€ medical_knowledge.py  # Knowledge base queries
β”‚       └── eu_guidelines_validator.py  # EULAR/S3/NICE compliance
β”‚
β”œβ”€β”€ models/                       # Data models
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── schemas.py                # Pydantic schemas
β”‚
β”œβ”€β”€ data/                         # Static data
β”‚   β”œβ”€β”€ prompts/
β”‚   β”‚   └── system_prompt.txt     # AI personality definition
β”‚   β”œβ”€β”€ translations/             # UI translations (21 languages)
β”‚   β”‚   β”œβ”€β”€ en-US.json            # English (US)
β”‚   β”‚   β”œβ”€β”€ pl.json               # Polish
β”‚   β”‚   β”œβ”€β”€ de.json               # German
β”‚   β”‚   └── ...                   # 18 more languages
β”‚   β”œβ”€β”€ features.json             # 15 worsening factors
β”‚   β”œβ”€β”€ metrics.json              # 8 evaluation metrics
β”‚   β”œβ”€β”€ guidelines.json           # EU clinical guidelines
β”‚   └── reasoning_config.json     # Reasoning mode configuration
β”‚
β”œβ”€β”€ static/                       # Web assets
β”‚   β”œβ”€β”€ logo.png                  # App logo
β”‚   └── custom.css                # Premium styling (1100+ lines)
β”‚
β”œβ”€β”€ resources/                    # Design resources
β”‚   β”œβ”€β”€ hellofibro_logo.png       # Original logo
β”‚   β”œβ”€β”€ style.css                 # Reference styles
β”‚   └── hellofibro-gradio6-modern.md
β”‚
β”œβ”€β”€ tests/                        # Test suite
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ conftest.py               # Pytest fixtures (incl. medical)
β”‚   β”œβ”€β”€ test_chat.py              # Chat tests
β”‚   β”œβ”€β”€ test_agents.py            # Agent tests
β”‚   β”œβ”€β”€ test_reminders.py         # Medication tests
β”‚   β”œβ”€β”€ test_missed_doses.py      # Missed dose notification tests
β”‚   β”œβ”€β”€ test_config.py            # Config tests
β”‚   β”œβ”€β”€ test_e2e.py               # End-to-end tests
β”‚   β”œβ”€β”€ test_medical_layer.py     # πŸ†• Medical services unit tests
β”‚   └── test_medical_integration.py  # πŸ†• Medical integration tests
β”‚
β”œβ”€β”€ .env                          # Environment config (create this)
β”œβ”€β”€ .env.example                  # Example environment file
β”œβ”€β”€ requirements.txt              # Python dependencies
β”œβ”€β”€ Makefile                      # Development commands
β”œβ”€β”€ Dockerfile                    # Container definition
β”œβ”€β”€ docker-compose.yml            # Container orchestration
β”œβ”€β”€ pyproject.toml                # Project metadata
β”œβ”€β”€ BRANDING_GUIDE.md             # Design system documentation
β”œβ”€β”€ IMPLEMENTATION_PLAN.md        # Development roadmap
└── README.md                     # This file
```

---

## πŸ”„ Workflows

### Chat Conversation Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User     β”‚      β”‚  Gradio UI  β”‚      β”‚ ChatHandler β”‚
β”‚   Input     │─────▢│  (main.py)  │─────▢│  (chat.py)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                                                  β”‚
                                                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Streaming  │◀─────│   LLMAgent  │◀─────│   Session   β”‚
β”‚  Response   β”‚      β”‚ (agents.py) β”‚      β”‚   History   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  OpenRouter   β”‚
                    β”‚  Claude API   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Step-by-step:**

1. **User Input** β†’ User types message + optional file upload
2. **File Processing** β†’ Extract text from PDF/DOCX/CSV/images
3. **Context Building** β†’ Add medication/appointment context + file hints
4. **Session Management** β†’ Retrieve/create conversation session
5. **LLM Request** β†’ Send to Claude via OpenRouter with streaming
6. **Response Processing** β†’ Extract medication commands, clean response
7. **UI Update** β†’ Stream response to chat interface

### Medication Management Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    USER ACTIONS                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ "Dodaj lek  β”‚ Click "Add   β”‚ Click "Take"  β”‚ "WziΔ…Ε‚em     β”‚
β”‚  X 100mg"   β”‚  Medication" β”‚    Button     β”‚  pregabalinΔ™" β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚              β”‚               β”‚               β”‚
       β–Ό              β–Ό               β–Ό               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   PROCESSING LAYER                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  LLM generates:     β”‚  Direct UI Handler:                   β”‚
β”‚  [MEDICATION_CMD:   β”‚  add_medication_ui()                  β”‚
β”‚   ADD: X|100mg|...] β”‚  mark_taken_ui()                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                          β”‚
           β–Ό                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              MedicationReminder (reminders.py)              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ add_medication()     β€’ mark_taken()                      β”‚
β”‚  β€’ remove_medication()  β€’ get_medications_for_display()     β”‚
β”‚  β€’ get_today_status()   β€’ process_llm_medication_command()  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MedicationState                          β”‚
β”‚        (In-memory storage with Pydantic models)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**LLM Command Format:**

```python
# Adding medication via chat
[MEDICATION_CMD: ADD: Pregabalina|150mg|21:00|wieczorem|na bΓ³l neuropatyczny]

# Removing medication
[MEDICATION_CMD: REMOVE: Pregabalina]

# Marking as taken
[MEDICATION_CMD: TAKEN: Pregabalina]

# Listing all medications
[MEDICATION_CMD: LIST:]
```

### Appointment Management Flow

```
+---------------+      +------------------+      +-------------------+
| USER ACTIONS  |      | PROCESSING LAYER |      | AppointmentReminder|
+---------------+      +------------------+      +-------------------+
       |                       |                         |
       v                       v                         v
  "Add visit"            LLM generates:          add_appointment()
  Click Form       [APPOINTMENT_CMD: ADD: ...]   get_appointments()
  Click Card              OR                     remove_appointment()
       |           Direct UI Handler                     |
       +--------->----------------------->---------------+
                                                         |
                                                         v
                                              +-------------------+
                                              | AppointmentState  |
                                              | (In-memory)       |
                                              +-------------------+
```

**LLM Command Format:**

```python
# Adding appointment via chat
[APPOINTMENT_CMD: ADD: Dr. Smith|Rheumatologist|2025-01-15|10:00|ABC Clinic|bring test results]

# Removing appointment
[APPOINTMENT_CMD: REMOVE: Dr. Smith]

# Listing all appointments
[APPOINTMENT_CMD: LIST:]
```

### File Processing Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ File Upload │─────▢│ process_uploaded │─────▢│ Type Check  β”‚
β”‚   (User)    β”‚      β”‚     _file()      β”‚      β”‚ & Validate  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                                                       β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚                                 β”‚                 β”‚
                     β–Ό                                 β–Ό                 β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ PDF (fitz)  β”‚                 β”‚ DOCX/DOC    β”‚    β”‚ CSV/XLSX    β”‚
              β”‚ extract_pdf β”‚                 β”‚ extract_docxβ”‚    β”‚ pandas read β”‚
              β”‚   _text()   β”‚                 β”‚   _text()   β”‚    β”‚             β”‚
              β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                 β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                     β”‚                               β”‚                  β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                                     β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚ Content + Hint  β”‚
                            β”‚ for LLM Context β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                                     β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚ Enhanced Chat   β”‚
                            β”‚   Message       β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Supported File Processing:**

| Type | Library | Max Size | Features |
|------|---------|----------|----------|
| PDF | PyMuPDF | 15MB | Multi-page, page markers |
| DOCX | python-docx | 15MB | Paragraphs + tables |
| XLSX/XLS | pandas + openpyxl | 15MB | Multi-sheet, statistics |
| CSV | pandas | 15MB | Headers, stats preview |
| TXT/MD/JSON | Built-in | 50KB | UTF-8 with fallback |
| Images | Base64 | 15MB | Vision model support |

---

## πŸš€ Quick Start

### Prerequisites

- **Python 3.10+** installed
- **OpenRouter API key** ([Get one here](https://openrouter.ai))

### Installation

```bash
# 1. Clone the repository
git clone https://github.com/hellofibro/hellofibro.git
cd hellofibro

# 2. Create virtual environment
python -m venv venv

# Windows
.\venv\Scripts\activate

# macOS/Linux
source venv/bin/activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Create environment file
cp .env.example .env
# Edit .env and add your OPENROUTER_API_KEY

# 5. Run the application
python -m app.main
```

### Using Docker

```bash
# Build and run with Docker Compose
docker-compose up --build -d

# View logs
docker-compose logs -f

# Stop the container
docker-compose down
```

**Container Status:**
```
NAME         IMAGE                   STATUS              PORTS
hellofibro   hellofibro-hellofibro   Up (running)        0.0.0.0:7860->7860/tcp
```

**With API Key (Production):**

```bash
# Windows PowerShell
$env:OPENROUTER_API_KEY="sk-or-v1-your-key-here"
docker-compose up -d

# Linux/macOS
export OPENROUTER_API_KEY="sk-or-v1-your-key-here"
docker-compose up -d

# Or create .env file first
echo "OPENROUTER_API_KEY=sk-or-v1-your-key-here" > .env
docker-compose up -d
```

**Demo Mode (No API Key):**

Without an API key, the app runs in demo mode with pre-defined responses:

```bash
docker-compose up -d
# Logs will show: "Running in DEMO MODE - API calls disabled"
```

**Manual Docker Build:**

```bash
# Build image
docker build -t hellofibro .

# Run with environment variable
docker run -p 7860:7860 -e OPENROUTER_API_KEY=sk-or-v1-xxx hellofibro

# Or with .env file
docker run -p 7860:7860 --env-file .env hellofibro
```

**Docker Compose Configuration:**

The `docker-compose.yml` includes:
- Health checks (every 30s)
- Resource limits (2 CPU, 2GB RAM)
- Automatic restart policy
- Environment variable passthrough

### Using Make (Recommended)

```bash
make setup    # Create venv + install dependencies
make run      # Start the application
make test     # Run all tests
make lint     # Check code quality
make format   # Format code with black
make clean    # Remove cache files
```

### Access the App

```
🌐 Open http://localhost:7860 in your browser
```

---

## βš™οΈ Configuration

Create a `.env` file in the project root:

```env
# Required - Your OpenRouter API key
OPENROUTER_API_KEY=sk-or-v1-your-api-key-here

# Optional - Model selection (defaults shown)
OPENROUTER_MODEL=anthropic/claude-sonnet-4
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1

# Optional - Model parameters
MODEL_MAX_TOKENS=4096
MODEL_TEMPERATURE=0.7

# Optional - Application settings
APP_TITLE=HelloFibro
APP_HOST=0.0.0.0
APP_PORT=7860

# Optional - Feature flags
DEBUG_MODE=false           # Set to true to test missed dose notifications anytime
STREAM_RESPONSES=true
LOG_LEVEL=INFO

# Optional - Internationalization
DEFAULT_LANGUAGE=pl        # Default UI language (pl, en-US, de, es, fr, etc.)
```

### Supported Languages

| Code | Language | Native Name |
|------|----------|-------------|
| `en-US` | English (US) | English (US) |
| `en-GB` | English (UK) | English (UK) |
| `pl` | Polish | Polski |
| `de` | German | Deutsch |
| `es` | Spanish | Espanol |
| `fr` | French | Francais |
| `it` | Italian | Italiano |
| `nl` | Dutch | Nederlands |
| `pt` | Portuguese | Portugues |
| `sv` | Swedish | Svenska |
| `no` | Norwegian | Norsk |
| `da` | Danish | Dansk |
| `ja` | Japanese | Nihongo |
| `ko` | Korean | Hangugeo |
| `zh` | Chinese | Zhongwen |
| `ar` | Arabic | Al-Arabiyyah |
| `he` | Hebrew | Ivrit |
| `hi` | Hindi | Hindi |
| `th` | Thai | Phasa Thai |
| `tr` | Turkish | Turkce |
| `id` | Indonesian | Bahasa Indonesia |

### Supported Models

Any OpenRouter-compatible model works. Recommended options:

| Model | ID | Best For |
|-------|-----|----------|
| **Claude Sonnet 4** | `anthropic/claude-sonnet-4` | Best quality (default) |
| **Claude 3.5 Sonnet** | `anthropic/claude-3.5-sonnet` | Fast, excellent |
| **GPT-4o** | `openai/gpt-4o` | Alternative |
| **Claude 3 Haiku** | `anthropic/claude-3-haiku` | Budget-friendly |

---

## πŸ§ͺ Testing

```bash
# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=app --cov=models

# Run specific test file
pytest tests/test_chat.py -v

# Run async tests only
pytest tests/ -v -k "async"
```

### Test Categories

| File | Tests |
|------|-------|
| `test_config.py` | Settings validation, API key format |
| `test_agents.py` | LLM agent, streaming, error handling |
| `test_chat.py` | Session management, message processing |
| `test_reminders.py` | Medication CRUD, logging, commands |
| `test_missed_doses.py` | Missed dose detection, actions |
| `test_language_selection.py` | i18n service, language switching |
| `test_e2e.py` | End-to-end integration tests |
| `test_medical_layer.py` | Medical services unit tests |
| `test_medical_integration.py` | End-to-end medical integration |

### Medical Intelligence Tests

```bash
# Run medical layer tests specifically
pytest tests/test_medical_layer.py -v
pytest tests/test_medical_integration.py -v

# Run all tests including medical
pytest tests/ -v --tb=short
```

**Tested Components:**
- MedicalKnowledgeService queries (features, guidelines, differential)
- EUGuidelinesValidator (therapy validation, contraindications)
- AdaptiveReasoningRouter (complexity assessment, mode routing)
- FibroPatientProfile (ACR 2016, PHI masking, FHIR export)
- ChatHandler medical context integration
- FibroAgentCouncil parallel/deep modes

---

## πŸ”’ Security & Privacy

HelloFibro is designed with privacy as a core principle:

| Aspect | Implementation |
|--------|----------------|
| **Data Storage** | Session-only, in-memory (no persistence) |
| **API Keys** | Stored in `.env`, never logged or transmitted |
| **User Data** | Not stored, not tracked, not shared |
| **Conversations** | Cleared on session end |
| **Medications** | In-memory only (MVP) |
| **File Uploads** | Processed in memory, not stored |
| **PHI Protection** | πŸ†• FHIR patient profiles support PHI masking |
| **Medical Data** | πŸ†• No patient data persisted, session-only |

### Important Notes

- βœ… HTTPS recommended for production
- βœ… API key validation at startup
- βœ… No PII collection or storage
- ⚠️ Future versions may add optional persistence with encryption

---

## ⚠️ Medical Disclaimer

> **HelloFibro is NOT a substitute for professional medical advice.**

This AI assistant provides general support and information only:

| ❌ HelloFibro Does NOT | βœ… HelloFibro Does |
|------------------------|-------------------|
| Diagnose conditions | Provide emotional support |
| Prescribe medications | Track prescribed medications |
| Replace healthcare providers | Help prepare for doctor visits |
| Provide emergency advice | Offer coping strategies |
| Make treatment decisions | Share general fibromyalgia info |
| Provide dosage advice | Reference EULAR/S3/NICE guidelines |

### Clinical Guidelines Compliance

HelloFibro references established clinical guidelines for informational purposes:

| Guideline | Year | Scope |
|-----------|------|-------|
| **EULAR 2016** | 2016 | European League Against Rheumatism |
| **German S3** | 2017 | German Association of Scientific Medical Societies |
| **UK NICE** | 2021 | UK National Institute for Health and Care Excellence |
| **ACR 2016** | 2016 | American College of Rheumatology diagnostic criteria |

**Always consult qualified healthcare professionals for medical decisions.**

---

## 🀝 Contributing

Contributions are welcome! Please follow these guidelines:

### Development Setup

```bash
# 1. Fork and clone
git clone https://github.com/YOUR_USERNAME/hellofibro.git
cd hellofibro

# 2. Create branch
git checkout -b feature/your-feature

# 3. Install dev dependencies
pip install -r requirements.txt

# 4. Make changes and test
make test
make lint

# 5. Format code
make format

# 6. Commit and push
git commit -m "feat: add amazing feature"
git push origin feature/your-feature

# 7. Open Pull Request
```

### Code Style

- **Formatting**: Black (line length 88)
- **Linting**: Ruff
- **Type Hints**: Required for all functions
- **Docstrings**: Required for public APIs

### Commit Messages

Follow [Conventional Commits](https://www.conventionalcommits.org/):

```
feat: add new medication reminder feature
fix: resolve chat history persistence issue
docs: update README with architecture diagram
style: format code with black
refactor: extract file processing to separate module
test: add tests for medication commands
```

---

## πŸ“œ License

This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

---

## πŸ’œ Acknowledgments

- Built with love for the fibromyalgia community πŸ’œ
- AI powered by [Anthropic Claude](https://anthropic.com) via [OpenRouter](https://openrouter.ai)
- UI framework by [Gradio](https://gradio.app)
- Inspired by the strength and resilience of fibromyalgia warriors

---


<div align="center">

### πŸ’œ Made with empathy for warriors living with fibromyalgia

*Your experience is valid. You are not alone. Your strength inspires us.*

---

**[⬆ Back to Top](#-hellofibro)**

</div>