# BrainWaves User Flow This document describes the user flow through the BrainWaves application โ€” an Electron desktop app for conducting EEG neuroscience experiments. ## Flow Diagram ```mermaid flowchart TD HOME["๐Ÿ  HOME"] HOME --> MY_EXP["MY EXPERIMENTS\n(saved workspaces)"] HOME --> EXP_BANK["EXPERIMENT BANK\n(built-in cards)"] HOME --> EXPLORE["EXPLORE EEG DATA\n(raw streaming)"] MY_EXP -->|"Open Experiment"| DESIGN EXP_BANK -->|"Pick card โ†’ Overview โ†’ Start"| DESIGN EXPLORE --> CONNECT_MODAL_EXP["ConnectModal\n(find & connect device)"] CONNECT_MODAL_EXP --> EEG_EXPLORE["Live EEG Viewer\n(signal quality + waveform)"] subgraph DESIGN ["๐Ÿ“‹ DESIGN /design"] direction TB D_OV["OVERVIEW\n(title, description)"] D_BG["BACKGROUND\n(framing questions, resources)"] D_PR["PROTOCOL\n(step-by-step, condition images)"] D_PV["PREVIEW\n(live experiment iframe)"] D_OV --> D_BG --> D_PR --> D_PV EEG_TOGGLE["Enable/Disable EEG toggle"] end DESIGN -->|"Top nav: Collect"| COLLECT subgraph COLLECT ["๐ŸŽง COLLECT /collect"] direction TB PRE_TEST["PRE-TEST\n(signal quality + EEG viewer)"] CONNECT_MODAL["ConnectModal\nโ‘  power on headset\nโ‘ก plug in USB receiver\nโ‘ข select device โ†’ connect"] PRE_TEST -->|"EEG enabled & not connected"| CONNECT_MODAL CONNECT_MODAL -->|"Connected"| PRE_TEST PRE_TEST -->|"Run & Record"| RUN RUN["RUN\n(subject ID / group / session)"] EXP_WINDOW["ExperimentWindow\n(full-screen lab.js iframe\n+ EEG timing markers)"] RUN -->|"Run Experiment"| EXP_WINDOW EXP_WINDOW -->|"Experiment complete\n(behavioral CSV saved)"| DONE_COLLECT["Recording saved โœ“"] end DONE_COLLECT -->|"EEG enabled\nTop nav: Clean"| CLEAN DONE_COLLECT -->|"Behavior only\nTop nav: Analyze"| ANALYZE subgraph CLEAN ["๐Ÿงน CLEAN /clean\n(EEG only)"] direction TB CL_SEL["Select subject\n+ select recording(s)"] CL_LOAD["Load Dataset\n(Pyodide โ†’ epoch stats)"] CL_CLEAN["Clean Data\n(artifact rejection in Pyodide)"] CL_SEL --> CL_LOAD --> CL_CLEAN end CLEAN -->|"Analyze Dataset โ†’"| ANALYZE subgraph ANALYZE ["๐Ÿ“Š ANALYZE /analyze"] direction TB AN_OV["OVERVIEW\n(topoplot โ€” scalp map)"] AN_ERP["ERP\n(waveform by electrode)"] AN_BEH["BEHAVIOR\n(RT / Accuracy charts\nbar ยท box ยท scatter)"] AN_EXP["Export aggregated data"] AN_OV --> AN_ERP AN_ERP --> AN_BEH AN_BEH --> AN_EXP end DESIGN -->|"Home button"| HOME COLLECT -->|"Home button"| HOME CLEAN -->|"Home button"| HOME ANALYZE -->|"Home button"| HOME style HOME fill:#4A90D9,color:#fff style DESIGN fill:#7B68EE,color:#fff style COLLECT fill:#E8763A,color:#fff style CLEAN fill:#3BAF7A,color:#fff style ANALYZE fill:#D95B5B,color:#fff ``` ## Stage Descriptions ### 1. Home (`/` and `/home`) Entry point with three tabs: - **My Experiments** โ€” table of previously saved workspaces; each row has Delete, Go to Folder, and Open Experiment actions. - **Experiment Bank** โ€” card grid of four built-in EEG paradigms: Faces/Houses (N170), Stroop Task, Multi-tasking, and Visual Search. Clicking a card opens an Overview panel before starting. - **Explore EEG Data** โ€” connects directly to a headset and streams live EEG without running a formal experiment. ### 2. Design (`/design`) Four review tabs walk the researcher through the experiment before data collection: | Tab | Content | |---|---| | **Overview** | Title and experiment description | | **Background** | Framing questions and external reading resources | | **Protocol** | Step-by-step instructions with condition images | | **Preview** | Live experiment iframe (lab.js) | An **Enable EEG** toggle controls whether the Clean step appears downstream. Custom experiments have additional tabs for configuring conditions, trials, timing parameters, and instructions. ### 3. Collect (`/collect`) Two sub-views: - **Pre-Test** โ€” walks the user through `ConnectModal` (power on headset โ†’ plug in USB receiver โ†’ select device โ†’ connect), then shows live signal quality and a real-time EEG waveform. - **Run** โ€” collects subject ID, group name, and session number, then launches the experiment in a full-screen iframe. EEG timing markers are injected during the task. On completion, the behavioral CSV is saved automatically. ### 4. Clean (`/clean`) โ€” EEG only Shown only when EEG is enabled. 1. Select a subject and one or more recordings. 2. **Load Dataset** โ€” loads epochs into Pyodide (Python-in-browser) and returns epoch statistics. 3. **Clean Data** โ€” runs artifact rejection via Pyodide. Once the drop percentage reaches a threshold, the *Analyze Dataset* button becomes available. ### 5. Analyze (`/analyze`) - **EEG mode** โ€” three tabs: topoplot (scalp map overview), ERP waveforms per electrode, and behavioral analysis. - **Behavior-only mode** โ€” one tab: interactive bar, box, or scatter plots for response time or accuracy, with an outlier-removal option and an export button.