# ap4549/parkisense architecture

> Architecture diagram of the GitHub repository ap4549/parkisense, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ap4549/parkisense
- Repository: https://github.com/ap4549/parkisense

## Overview

##### Project Type & Purpose
- ParkiSense is a Python-based ML application with an interactive UI (Gradio) that provides three core services:
– Keystroke-dynamics prediction
– Voice-analysis prediction
– AI chatbot (Gemini AI)
- It’s primarily a full-stack “one-service” app (UI + inference) with optional offline pipelines for data prep and model training.

##### High-Level Architecture Components
a. Presentation Layer (Frontend/UI)
– Gradio-based Web UI (Code/app/app.py + home.py)
– PWA shell (service-worker, manifest) in assets/
b. Inference Services (Business Logic)
– Keystroke module (type.py + Pynput)
– Voice module (voice.py + Librosa/Parselmouth)
– Chatbot module (chatbot.py + Gemini AI API)
c. Model & Data Layer
– Pre-trained model files (model/sgd_model.pkl, model/voicemodel.pkl)
– Static data (data/full_set.csv, data/parkinsons.data)
– User recordings & feature CSVs
d. External Services
– Gemini AI API for chatbot responses
e. Offline Pipelines (for reference)
– Jupyter notebooks under Code/ (tappydata_prep.ipynb, tappymodel_train.ipynb, voicetrain.ipynb)

##### Relationships & Data Flows
- User → Gradio UI:
– Text input → Keystroke module → feature extraction → sgd_model.pkl → prediction → UI
– Audio upload/record → Voice module → feature extraction → voicemodel.pkl → prediction → UI
– Chat query → chatbot module → Gemini AI API → response → UI
- Gradio UI loads models from disk at startup
- Offline pipelines consume raw data from data/Archived-Data → produce models in model/

##### Architectural Patterns & Principles
- Layered separation:
– Presentation (Gradio)
– Processing (feature-extraction functions)
– Inference (model prediction)
– External integration (Gemini AI)
- Single process with modular Python packages, rather than microservices
- Clear demarcation of online (inference) vs offline (training)

- Keystroke Service (type.py + sgd_model.pkl)
- Voice Service (voice.py + voicemodel.pkl)
- Chatbot Service (chatbot.py → Gemini AI API)
- Data Archive (data/Archived-Data) → Notebooks → model/*.pkl

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["App (app.py)\nGradio, Python"]:::ui
        Home["Home Page (home.py)\nGradio UI"]:::ui
        PWA["PWA Assets\n(service-worker, manifest)"]:::ui
    end

    %% Inference Services
    subgraph "Inference Services"
        KEP["Keystroke Service\n(type.py)"]:::inference
        VO["Voice Service\n(voice.py)"]:::inference
        CB["Chatbot Service\n(chatbot.py)"]:::inference
    end

    %% Model & Data Store
    subgraph "Model & Data Store"
        SGD["sgd_model.pkl"]:::data
        VOICE_MODEL["voicemodel.pkl"]:::data
        CSV1["full_set.csv"]:::data
        CSV2["parkinsons.data"]:::data
        Archive["Archived Data\n(data/Archived-Data)"]:::data
    end

    %% External Services
    EX["Gemini AI API"]:::external

    %% Offline Pipelines
    subgraph "Offline Pipelines"
        NB1["Data Prep\n(tappydata_prep.ipynb)"]:::offline
        NB2["Model Train\n(tappymodel_train.ipynb)"]:::offline
        NB3["Voice Train\n(voicetrain.ipynb)"]:::offline
    end

    %% Data Flows
    User -->|"text input"| UI
    User -->|"audio upload/record"| UI
    User -->|"chat query"| UI

    UI -->|"keystroke input"| KEP
    UI -->|"voice input"| VO
    UI -->|"chat query"| CB

    KEP -->|"loads model"| SGD
    VO -->|"loads model"| VOICE_MODEL
    CB -->|"queries"| EX

    Archive --> NB1
    Archive --> NB3
    NB1 --> NB2
    NB2 --> SGD
    NB3 --> VOICE_MODEL

    %% Click Events
    click UI "https://github.com/ap4549/parkisense/blob/main/Code/app/app.py"
    click Home "https://github.com/ap4549/parkisense/blob/main/Code/app/home.py"
    click PWA "https://github.com/ap4549/parkisense/tree/main/assets/"
    click KEP "https://github.com/ap4549/parkisense/blob/main/Code/app/type.py"
    click VO "https://github.com/ap4549/parkisense/blob/main/Code/app/voice.py"
    click CB "https://github.com/ap4549/parkisense/blob/main/Code/app/chatbot.py"
    click SGD "https://github.com/ap4549/parkisense/blob/main/model/sgd_model.pkl"
    click VOICE_MODEL "https://github.com/ap4549/parkisense/blob/main/model/voicemodel.pkl"
    click CSV1 "https://github.com/ap4549/parkisense/blob/main/data/full_set.csv"
    click CSV2 "https://github.com/ap4549/parkisense/blob/main/data/parkinsons.data"
    click NB1 "https://github.com/ap4549/parkisense/blob/main/Code/tappydata_prep.ipynb"
    click NB2 "https://github.com/ap4549/parkisense/blob/main/Code/tappymodel_train.ipynb"
    click NB3 "https://github.com/ap4549/parkisense/blob/main/Code/voicetrain.ipynb"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef inference fill:#D4F1BE,stroke:#333,stroke-width:1px
    classDef data fill:#FFE5B4,stroke:#333,stroke-width:1px
    classDef external fill:#E2D4F0,stroke:#333,stroke-width:1px
    classDef offline fill:#F0E68C,stroke:#333,stroke-width:1px

    class UI,Home,PWA ui
    class KEP,VO,CB inference
    class SGD,VOICE_MODEL,CSV1,CSV2,Archive data
    class EX external
    class NB1,NB2,NB3 offline
```
