# yorkeccak/bio architecture

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

- Interactive diagram: https://gitdiagram.com/yorkeccak/bio
- Repository: https://github.com/yorkeccak/bio

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js 15 (App Router) that serves as a biomedical research assistant.
- The frontend delivers a chat interface and data-driven views; the “backend” consists of Next.js API routes that orchestrate calls to external services (Valyu API, OpenAI/Vercel AI SDK, Daytona code execution sandboxes, Ollama local models, Supabase for auth/storage, webhooks for polar integration, etc.).

##### File structure
- Top level:
- package.json, pnpm-lock.json, tsconfig.json, next.config.ts, tailwind.config.ts, postcss.config.mjs, eslint.config.mjs
- docs/ for design notes, public/ for static assets
- src/app/ contains React Server Components and API route folders (chat, checkout, collections, customer-portal, env-status, ollama-status, rate-limit, uploads, usage, webhooks, auth).
- src/components/ holds UI components (ChatInterface, BottomBar, modals, charts, shadcn/ui wrappers).
- src/lib/ provides shared utilities (citation, env validation, hooks, LLM context, rate-limit, polar events, stores).
- src/utils/supabase/ has client and server Supabase helpers for auth or persistence.
- src/types/ and root-level config files define typing, linting, and build pipelines.

##### README for additional insights
- Architecture callout at bottom:
- Frontend: Next.js 15 App Router, Tailwind CSS, shadcn/ui
- AI: OpenAI GPT-4 (with function calling) + optional Ollama local models
- Data: Valyu API (clinical trials, drug labels, PubMed)
- Code Execution: Daytona sandboxes (Python)
- Visualizations: Recharts
- Real-time streaming via Vercel AI SDK
- Security: sandboxing, HIPAA-compliant, HTTPS, API key management

##### Detail
- Context/state providers (React Context) as sub-components of the frontend.
- Important middleware (middleware.ts for auth/rate-limit) and route interceptors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Browser["User Browser/Mobile"]:::external
    end

    subgraph "Frontend Layer"
        NFrontend["Next.js Frontend (RSC + CSS)"]:::frontend
        Context["Context Providers"]:::frontend
        UI["UI Components"]:::frontend
    end

    subgraph "API Layer"
        ChatAPI["Chat API"]:::api
        CollAPI["Collections API"]:::api
        CheckoutAPI["Checkout API"]:::api
        CustomerAPI["Customer Portal API"]:::api
        EnvAPI["Environment Status API"]:::api
        OllamaStatAPI["Ollama Status API"]:::api
        RateLimAPI["Rate Limiting API"]:::api
        UploadsAPI["Uploads API"]:::api
        UsageAPI["Usage Tracking API"]:::api
        WebhookAPI["Polar Webhook Receiver"]:::api
        AuthCB["Auth Callback API"]:::api
    end

    subgraph "External Services"
        Valyu["Valyu Data API"]:::external
        OpenAI["OpenAI / Vercel AI SDK"]:::external
        Daytona["Daytona Sandbox"]:::external
        Ollama["Ollama Local Model Server"]:::external
    end

    subgraph "Data Stores"
        Supabase["Supabase (Auth/Storage)"]:::db
        KV["Vercel KV"]:::db
    end

    Browser --> NFrontend
    NFrontend --> ChatAPI
    NFrontend --> CollAPI
    NFrontend --> CheckoutAPI
    NFrontend --> CustomerAPI
    NFrontend --> EnvAPI
    NFrontend --> OllamaStatAPI
    NFrontend --> RateLimAPI
    NFrontend --> UploadsAPI
    NFrontend --> UsageAPI
    NFrontend --> WebhookAPI
    NFrontend --> AuthCB

    ChatAPI --> Valyu
    ChatAPI --> OpenAI
    ChatAPI --> Daytona
    ChatAPI --> Ollama
    ChatAPI --> Supabase

    CollAPI --> Supabase
    CheckoutAPI --> Supabase
    CustomerAPI --> Supabase
    UsageAPI --> KV
    WebhookAPI --> Supabase

    UI -->|uses| NFrontend
    Context -->|provides to| UI

    click NFrontend "https://github.com/yorkeccak/bio/tree/main/src/app"
    click ChatAPI "https://github.com/yorkeccak/bio/tree/main/src/app/api/chat"
    click CollAPI "https://github.com/yorkeccak/bio/tree/main/src/app/api/collections"
    click CheckoutAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/checkout/route.ts"
    click CustomerAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/customer-portal/route.ts"
    click EnvAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/env-status/route.ts"
    click OllamaStatAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/ollama-status/route.ts"
    click RateLimAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/rate-limit/route.ts"
    click UploadsAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/uploads/route.ts"
    click UsageAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/usage/dark-mode/route.ts"
    click WebhookAPI "https://github.com/yorkeccak/bio/blob/main/src/app/api/webhooks/polar/route.ts"
    click AuthCB "https://github.com/yorkeccak/bio/blob/main/src/app/auth/callback/route.ts"
    click Context "https://github.com/yorkeccak/bio/tree/main/src/lib/hooks"
    click UI "https://github.com/yorkeccak/bio/tree/main/src/components"
    click Supabase "https://github.com/yorkeccak/bio/tree/main/src/utils/supabase"

    classDef frontend fill:#d0e7ff,stroke:#0366d6,color:#0366d6
    classDef api fill:#d0ffd8,stroke:#28a745,color:#28a745
    classDef external fill:#ffe7ba,stroke:#ea4a0f,color:#ea4a0f
    classDef db fill:#e3d3ff,stroke:#6f42c1,color:#6f42c1
```
