# 05 โ€” Data Flow Diagram (DFD) ## Overview This diagram traces how data flows through the BAYAN system โ€” from user input to final storage, through all NLP processing stages. ## Level 0 โ€” Context Diagram ```mermaid graph LR USER["๐Ÿ‘ค User"] -->|"Arabic Text"| BAYAN["๐Ÿ”ต BAYAN System"] BAYAN -->|"Corrections ยท Summaries ยท Documents"| USER BAYAN <-->|"Auth ยท Data"| SUPABASE["๐Ÿ—„๏ธ Supabase"] BAYAN <-->|"Models"| HUGGINGFACE["๐Ÿค— HuggingFace"] ``` ## Level 1 โ€” System DFD ```mermaid graph TD subgraph "Data Sources" INPUT["๐Ÿ“ User Input Text"] IMPORT["๐Ÿ“ฅ Imported File
(TXT / DOCX / PDF)"] end subgraph "1.0 Text Correction Pipeline" SPELL["1.1 AraSpell
Spelling Correction"] GRAMMAR["1.2 Grammar Check
Bayan Grammar"] PUNCT["1.3 Punctuation
PuncAra-v1"] MERGE["1.4 Merge Results
Offset Mapping"] end subgraph "2.0 Display Pipeline" HIGHLIGHT["2.1 Error Highlighting
renderer.js"] SIDEBAR["2.2 Suggestions Panel
ui.js"] SCORE["2.3 Writing Score
Calculation"] STATS["2.4 Editor Stats
Words ยท Chars ยท Sentences"] end subgraph "3.0 Summarization Pipeline" SUMM_IN["3.1 Extract Clean Text"] SUMM_MODEL["3.2 MBart Summarization"] SUMM_OUT["3.3 Summary Display"] end subgraph "4.0 AutoComplete Pipeline" AC_IN["4.1 Cursor Context"] AC_MODEL["4.2 AutoComplete Model"] AC_OUT["4.3 Dropdown Suggestions"] end subgraph "5.0 Storage" LOCAL["5.1 localStorage
Draft ยท Dismissed Words"] DOCUMENTS_DB["5.2 Supabase: documents"] SUMMARIES_DB["5.3 Supabase: summaries"] SETTINGS_DB["5.4 Supabase: settings"] PROFILES_DB["5.5 Supabase: profiles"] end subgraph "6.0 Export" EXPORT_TXT["6.1 Export TXT"] EXPORT_DOCX["6.2 Export DOCX"] EXPORT_PDF["6.3 Export PDF"] end INPUT --> SPELL IMPORT --> SPELL SPELL -->|"Corrected tokens"| GRAMMAR GRAMMAR -->|"Grammar-checked text"| PUNCT PUNCT -->|"Punctuated text"| MERGE MERGE -->|"All suggestions + offsets"| HIGHLIGHT MERGE --> SIDEBAR MERGE --> SCORE INPUT --> STATS INPUT --> SUMM_IN SUMM_IN --> SUMM_MODEL SUMM_MODEL --> SUMM_OUT SUMM_OUT --> SUMMARIES_DB INPUT --> AC_IN AC_IN --> AC_MODEL AC_MODEL --> AC_OUT INPUT --> LOCAL LOCAL -->|"Sync"| DOCUMENTS_DB INPUT --> EXPORT_TXT INPUT --> EXPORT_DOCX INPUT --> EXPORT_PDF style SPELL fill:#EF4444,color:#fff style GRAMMAR fill:#F59E0B,color:#000 style PUNCT fill:#3B82F6,color:#fff style SUMM_MODEL fill:#8B5CF6,color:#fff style AC_MODEL fill:#10B981,color:#fff ``` ## Data Stores Summary | Store | Type | Data | Access Pattern | |-------|------|------|----------------| | `localStorage` | Client-side | Draft HTML, dismissed words, word goal, theme | Read/write on every input | | `documents` | Supabase | id, user_id, title, content, timestamps | CRUD per user (RLS) | | `summaries` | Supabase | id, document_id, user_id, original, summary | Append-mostly | | `settings` | Supabase | id, user_id, preferences JSON | Read on login, write on change | | `profiles` | Supabase | id, display_name, avatar_url, auth_provider | Auto-created on signup | ## Data Transformation Chain ``` Raw Arabic Text โ”‚ โ”œโ”€โ”€โ†’ AraSpell โ”€โ”€โ†’ Corrected words (with alternatives) โ”‚ โ”‚ โ”‚ โ–ผ โ”‚ Grammar Engine โ”€โ”€โ†’ Grammar errors (with suggestions) โ”‚ โ”‚ โ”‚ โ–ผ โ”‚ Punctuation โ”€โ”€โ†’ Punctuation insertions โ”‚ โ”‚ โ”‚ โ–ผ โ”‚ Offset Mapper โ”€โ”€โ†’ Maps corrected offsets โ†’ original offsets โ”‚ โ”‚ โ”‚ โ–ผ โ”‚ Unified Suggestions Array โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€โ†’ Error Spans (renderer.js) โ”‚ โ”œโ”€โ”€โ†’ Sidebar Cards (ui.js) โ”‚ โ””โ”€โ”€โ†’ Score Calculation โ”‚ โ”œโ”€โ”€โ†’ AutoComplete Model โ”€โ”€โ†’ Top-K word suggestions โ”‚ โ””โ”€โ”€โ†’ MBart Summarizer โ”€โ”€โ†’ Compressed summary text ```