Skip to content

Built my own LLM token visualization tool using React and shadcn/ui to understand how language models process text

Notifications You must be signed in to change notification settings

chicken-teriyaki-cup-rice/llm-learn

Repository files navigation

Interactive LLM Processing Visualizer

Modern React application for visualizing Large Language Model text processing pipelines. Built with composable frontend architecture using React, Vite, and shadcn/ui components for real-time interactive demonstrations of LLM internals.

llm-learn-demo.mp4

Architecture

flowchart TB
    subgraph internet["Internet"]
        client(("Client Browser"))
    end

    subgraph app["React Application"]
        subgraph ui["UI Layer"]
            input["Text Input Component React + shadcn/ui"]
            viz["Visualization Component WebGL + Framer Motion"]
            controls["Control Panel shadcn/ui"]
        end
        
        subgraph core["Core Processing"]
            subgraph state["State Management"]
                store["Zustand Store"]
            end
            
            subgraph pipeline["LLM Processing Pipeline"]
                token["Tokenization Processor"]
                embed["Embedding Processor"]
                attn["Attention Visualizer"]
                ffn["Feed Forward Network"]
                gen["Output Generator"]
            end
        end

        subgraph services["Service Layer"]
            compute["Computation Service"]
            animate["Animation Service"]
            layout["Layout Engine"]
        end
    end

    client --> input
    input --> store
    store --> pipeline
    pipeline --> viz
    controls --> store
    services --> viz
    viz --> client

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef internet fill:#e9e9e9,stroke:#666
    classDef ui fill:#FFE4B5,stroke:#d49d4f
    classDef core fill:#B0E0E6,stroke:#4682B4
    classDef services fill:#98FB98,stroke:#3CB371
    
    class internet internet
    class input,viz,controls ui
    class store,pipeline core
    class services services
Loading

Key Components

  • User Interface Layer: React components using shadcn/ui
  • State Management: Zustand store with middleware
  • Processing Pipeline: Modular visualization processors
  • Service Layer: Animation and computation services

Technical Stack

  • Frontend Framework: React 18 with Vite
  • UI Components: shadcn/ui with Tailwind CSS
  • State Management: Zustand
  • Animation: Framer Motion
  • Icons: Lucide React
  • Testing: Vitest and Testing Library
  • Performance: React Suspense and lazy loading

Prerequisites

  • Node.js 18.0+
  • npm 8.0+
  • Modern browser with WebGL support

Development Setup

  1. Clone Repository
git clone https://github.com/organization/llm-visualizer
cd llm-visualizer
  1. Install Dependencies
# Install project dependencies
npm install

# Install required shadcn/ui components
npm run shadcn:add button card input slider toast alert dialog

# Setup development environment
cp .env.example .env.local
  1. Configure Environment
VITE_APP_VERSION=1.0.0
VITE_ENABLE_DEBUG=false
VITE_ANIMATION_SPEED=1
VITE_MAX_INPUT_LENGTH=1000
  1. Start Development Server
npm run dev

Project Structure

├── src/
│   ├── components/
│   │   ├── ui/             # shadcn/ui components
│   │   ├── visualization/  # LLM visualization components
│   │   └── layout/        # Layout components
│   ├── hooks/
│   │   ├── useProcessor.ts
│   │   └── useAnimation.ts
│   ├── services/
│   │   ├── tokenizer.ts
│   │   ├── embedding.ts
│   │   └── attention.ts
│   ├── store/
│   │   └── index.ts
│   └── utils/
│       ├── constants.ts
│       └── helpers.ts
├── tests/
│   ├── unit/
│   └── integration/
└── public/

Testing

# Run unit tests
npm run test:unit

# Run integration tests
npm run test:integration

# Run all tests with coverage
npm run test:coverage

Performance Optimization

  • Dynamic imports for visualization modules
  • Memoization of expensive computations
  • WebGL acceleration for matrix operations
  • Debounced user input handling
  • Virtual scrolling for large datasets

Browser Support

  • Chrome/Edge 90+
  • Firefox 90+
  • Safari 14+

Error Handling

The application implements comprehensive error boundaries and fallbacks:

  • Input validation errors
  • Processing pipeline failures
  • Animation engine errors
  • Resource loading issues

Monitoring and Analytics

  • Performance metrics collection
  • User interaction tracking
  • Error reporting
  • Usage analytics

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement changes with tests
  4. Submit pull request

Development Guidelines

  • Follow conventional commits
  • Add tests for new features
  • Update documentation
  • Maintain type safety
  • Follow ESLint configuration

Build and Deployment

# Production build
npm run build

# Preview production build
npm run preview

# Type check
npm run type-check

# Lint
npm run lint

Security

  • Input sanitization
  • XSS prevention
  • CSP configuration
  • Regular dependency audits

License

MIT License


For questions and support, please open an issue in the repository.

About

Built my own LLM token visualization tool using React and shadcn/ui to understand how language models process text

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published