# aossie-org/neurotrack architecture

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

- Interactive diagram: https://gitdiagram.com/aossie-org/neurotrack
- Repository: https://github.com/aossie-org/neurotrack

## Overview

##### Project Type & Purpose
- Neurotrack is a full-stack, multi-platform Flutter solution comprising two client apps (“patient” and “therapist”) and a Supabase back end.
- The patient app automates screening assessments, connects clients to therapists, tracks daily activities, and displays progress.
- The therapist app manages consultations, therapy plans, session outcomes, and assigns daily activities.
- Supabase provides authentication (including Google OAuth), a Postgres database, edge functions for AI-driven assessment evaluation, and helper scripts for schema management and seeding.

##### File Structure Highlights
- Top-level folders:
- patient/ – Flutter project for end-users
- therapist/ – Flutter project for professionals
- supabase/ – Database schema, cloud functions, seed scripts
- scripts/ – Automation helpers (e.g., assigning GitHub issues)
- Each Flutter project follows a layered pattern under lib/:
- core/ (entities, repositories, utils, result types, theming)
- model/ (data models + mappers)
- repository/ (Supabase client wrappers)
- provider/ (state management)
- presentation/ (UI screens, widgets)
- Supabase/ contains:
- schemas/schema.sql – table definitions
- functions/evaluate-assessments – Deno-based function for AI scoring
- scripts/seed_assessments.js – Node script to populate assessment templates

a. Main Components
1. Patient Flutter App (mobile/web/desktop)
2. Therapist Flutter App (mobile/web/desktop)
3. Supabase Auth Service (Postgres + Auth)
4. Supabase Database (tables: users, assessments, consultations, therapy_plans, activities, etc.)
5. Supabase Edge Function: Evaluate-Assessments (Deno)
6. Google OAuth (external identity provider)
7. Seed & Maintenance Scripts (optional)
b. Relationships & Data Flow
- Both Flutter apps use the Supabase Dart SDK to:
- Authenticate users via Supabase Auth ←→ Google OAuth
- Read/write data to Postgres tables
- Invoke the Evaluate-Assessments edge function for AI scoring
- Evaluate-Assessments function:
- Triggered by patient app after assessment submission
- Reads raw responses, runs AI logic, writes result back to a result table
- Therapist app queries assessment results, creates consultations, therapy plans, daily activities
- Daily activities updates (completion, notes) flow back to DB and surface on both apps
c. Architectural Patterns & Principles
- Layered (core/model/repository/provider/presentation) within each client
- Client-Driven state management using Provider
- Backend as a Service (BaaS) using Supabase for Auth, DB, and serverless functions
- Separation of concerns: UI, business logic, data access
d. Key Technologies & Libraries
- Flutter & Dart (UI + business logic)
- Provider (state management)
- Supabase Dart client (auth & data access)
- Deno / TypeScript (edge function)
- Postgres (database)
- Google OAuth via Supabase

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Applications
    subgraph "Patient App" 
        direction TB
        PatientUI["Presentation Layer"]:::client
        PatientState["State Management (Provider)"]:::client
        PatientRepo["Data Access (Repository)"]:::client
    end
    subgraph "Therapist App"
        direction TB
        TherapistUI["Presentation Layer"]:::client
        TherapistState["State Management (Provider)"]:::client
        TherapistRepo["Data Access (Repository)"]:::client
    end

    %% Supabase Backend
    subgraph "Supabase Back End"
        direction TB
        Auth["Auth Service"]:::backend
        DB[(Database)]:::database
        EvalFunc["Edge Function: evaluate-assessments"]:::backend
    end

    %% External Services and Scripts
    GoogleOAuth["Google OAuth"]:::external
    SeedScript["Seed & Maintenance Script"]:::script
    AssignScript["Automation Helper Script"]:::script
    EnvExample["Env Config Example"]:::script
    Gitignore["Supabase .gitignore"]:::script

    %% Connections: Patient App
    PatientUI -->|uses| PatientState
    PatientState -->|calls| PatientRepo
    PatientRepo -->|auth & data| Auth
    PatientRepo -->|read/write| DB
    PatientRepo -->|invoke| EvalFunc
    PatientRepo -->|"trigger after assessment"| EvalFunc

    %% Connections: Therapist App
    TherapistUI -->|uses| TherapistState
    TherapistState -->|calls| TherapistRepo
    TherapistRepo -->|auth & data| Auth
    TherapistRepo -->|read/write| DB

    %% Backend interactions
    Auth <-->|OAuth| GoogleOAuth
    EvalFunc -->|writes results| DB

    %% Scripts
    SeedScript -->|populates| DB
    AssignScript -->|automation| DB
    EnvExample --> Auth
    Gitignore --> Auth

    %% Click Events
    click PatientApp "https://github.com/aossie-org/neurotrack/tree/main/patient/"
    click TherapistApp "https://github.com/aossie-org/neurotrack/tree/main/therapist/"
    click Auth "https://github.com/aossie-org/neurotrack/blob/main/supabase/config.toml"
    click DB "https://github.com/aossie-org/neurotrack/blob/main/supabase/schemas/schema.sql"
    click EvalFunc "https://github.com/aossie-org/neurotrack/blob/main/supabase/functions/evaluate-assessments/index.ts"
    click SeedScript "https://github.com/aossie-org/neurotrack/blob/main/supabase/scripts/seed_assessments.js"
    click AssignScript "https://github.com/aossie-org/neurotrack/blob/main/scripts/assign.py"
    click EnvExample "https://github.com/aossie-org/neurotrack/blob/main/supabase/scripts/.env.example"
    click Gitignore "https://github.com/aossie-org/neurotrack/blob/main/supabase/.gitignore"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6,stroke-width:1px;
    classDef backend fill:#DFFFE0,stroke:#228B22,color:#228B22,stroke-width:1px;
    classDef database fill:#F0FFF0,stroke:#228B22,color:#228B22,stroke-width:1px,shape:cylinder;
    classDef external fill:#FFEFD5,stroke:#FF8C00,color:#FF8C00,stroke-width:1px;
    classDef script fill:#FFF8DC,stroke:#DAA520,color:#DAA520,stroke-width:1px;
```
