Skip to content

HKUDS/Litewrite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Litewrite Logo

✍️ Vibe Writing is Coming β€” Write Faster and Better!

Litewrite: AI-Powered Collaborative LaTeX Writing Platform

Version License CI TypeScript Next.js Python Docker

Demo

News β€’ Features β€’ Screenshots β€’ Architecture β€’ AI Features β€’ nanobot β€’ Quick Start β€’ Contributing


Try Litewrite: (https://litewrite.ai/)

πŸ“° News

  • 2026-02-10 πŸ€– **nanobot Γ— Litewrite β€” nanobot empowers your vibe writing (setup guide)
  • 2026-02-03 πŸŽ‰ Litewrite v1.0.7 β€” Real-time collaboration, LaTeX compilation & AI chat.

✨ Features

πŸš€ TAP Smart Completion β€” Type a few words, AI continues writing for you. Just hit Tab and you're all set!

πŸ’¬ ASK Mode β€” Summon your AI assistant anytime. Grammar issues? Format problems? Just ask!

πŸ€– Agent Mode β€” The ultimate hands-off writing experience! AI automatically edits, polishes, formats!

πŸ” Deep Research β€” AI conducts in-depth research and auto-generates reports. Research while you write!

πŸ“± nanobot β€” Chat with your projects from IM apps. Compile, edit, and manage β€” all from your phone!


nanobot Demo β€” Chat with your projects from Telegram

πŸ’¬ Chat with your projects from IM apps


πŸ“Έ Screenshots

Click to expand screenshots

🏠 Landing Page

Landing Page

AI-integrated vibe writing β€” lite, fast, effortless

πŸ“š Template Gallery

Template Gallery

10+ pre-built templates: NeurIPS, ACM, Beamer, CV, Thesis, and more

πŸ”£ Symbol Panel

Symbol Panel

Quick insert Greek letters, math operators, and LaTeX constructs

πŸ“– Reference Search

Reference Search

Search and insert BibTeX citations with fuzzy matching

πŸ“œ Version History

Version History

Create snapshots, compare diffs, and restore any previous version

πŸ”— Project Sharing

Share Project

Share via link or invite collaborators by email

πŸ’‘ Try it yourself: Visit litewrite.ai for the live demo!


πŸ—οΈ Architecture

Litewrite is a microservices architecture with 6 core services communicating over a Docker network.

Litewrite Architecture

Service Port Technology Role
🌐 Next.js 3000 TypeScript, React Web app, API routes, auth, project management
πŸ”„ WebSocket 1234 Node.js, Yjs Real-time collaboration, document sync, chat rooms
🧠 AI Server 6612 Python, FastAPI TAP completion, Chat Agent, Deep Research
πŸ“„ Compile 3002 Node.js, TeXLive LaTeX compilation (pdfLaTeX/XeLaTeX/LuaLaTeX)
πŸ€– nanobot β€” Python, LiteLLM Telegram/Feishu bot, Litewrite project operations
⚑ Redis 6379 Redis Yjs persistence, rate limiting, caching

πŸ”’ All internal service-to-service communication is authenticated via X-Internal-Secret header.


🧠 AI Features

Litewrite's AI capabilities are powered by a modular Agent system built on Python FastAPI. The architecture follows a MainAgent + SubAgent orchestration pattern with a unified Tool layer.

Litewrite AI Architecture

⚑ TAP Completion (Type-Ahead Prediction)

Ghost-text AI completion as you type, similar to GitHub Copilot.

Stage Description
Input prefix (text before cursor) + suffix (text after cursor)
Processing Boundary extraction β†’ Scenario detection β†’ LLM inference
Output Action type (insert / complete_word / fix / skip) + suggested text
Post-processing Boundary fixups β†’ Diff computation β†’ Frontend rendering

πŸ€– Agent System (Ask & Agent Mode)

The Agent system uses a ReAct-style loop with tool calling for complex writing tasks.

Litewrite Main Agent Architecture

Mode-based Tool Availability:

Tool Ask Mode Agent Mode Description
read_file βœ… βœ… Read file content with line ranges
list_files βœ… βœ… List project files and structure
web_search βœ… βœ… Search the web for information
arxiv_search βœ… βœ… Search arXiv papers with RAG
plan βœ… βœ… Generate step-by-step plan
done βœ… βœ… Signal task completion
edit_file β€” βœ… Edit file with diff preview
task β€” βœ… Delegate to SubAgent

Context Management:

  • πŸ“¦ Session history limit: 64K tokens (configurable)
  • πŸ“¦ Execution context limit: 64K tokens (configurable)
  • πŸ”„ Automatic LLM-based compression when threshold (95%) is exceeded
  • πŸ›‘οΈ Shadow documents for safe edit preview (or direct-apply for trusted callers)

πŸ” Deep Research

Multi-source research with automatic report generation.

Litewrite Deep Research

πŸ”§ Unified Tool Layer

All tools inherit from a base Tool class with standardized interfaces:

class Tool(ABC):
    name: str              # Tool identifier
    description: str       # LLM-readable description
    parameters: dict       # JSON Schema for parameters
    mode: ToolMode         # ask / agent / all

    async def execute(params, context) -> ToolResult

The ToolContext provides:

  • πŸ“‹ Project and user information
  • πŸ“‘ SSE event emitter for real-time frontend updates
  • πŸ”“ direct_apply flag for trusted callers (bypasses shadow documents)
  • πŸ“Š Shared usage accumulator for token tracking

πŸ“± nanobot β€” Chat Platform Integration

nanobot is an AI assistant that connects messaging platforms (Telegram, Feishu/Lark) to Litewrite, enabling users to manage LaTeX projects through natural language conversations.

πŸ“– For detailed setup instructions, see the nanobot Deployment Guide.

Litewrite nanobot Architecture

πŸ› οΈ Key Capabilities

nanobot provides 20 Litewrite tools for comprehensive project management:

Category Tools
🎯 Core List projects, invoke Litewrite AI agent, compile to PDF
πŸ“ File Operations List, read, edit, create, rename, delete, upload files
πŸ“¦ Project Management Create, delete, rename projects
πŸ“œ Version Control List, save, restore versions
πŸ“₯ Import Import from arXiv, GitHub/GitLab, or file upload

βš™οΈ How It Works

  1. πŸ’¬ User sends a message in Telegram or Feishu
  2. 🧠 nanobot's agent processes the message with LLM reasoning
  3. πŸ”§ Agent decides which Litewrite tools to call
  4. πŸ” Tools communicate with Litewrite via Internal API (X-Internal-Secret)
  5. πŸ“€ Results (text, PDF, etc.) are sent back to the chat platform

πŸ’Ύ Session Management

  • πŸ”— Per-project session cache: consecutive calls reuse the same conversation
  • πŸ‘οΈ Sessions appear in the Litewrite web UI as "nanobot" conversations
  • 🀝 The litewrite_agent tool delegates complex tasks to Litewrite's built-in AI agent, combining nanobot's chat interface with Litewrite's full editing capabilities

πŸš€ Quick Start

Prerequisites

  • Docker Desktop (includes Docker Compose)
  • 8GB+ RAM recommended (TeXLive image is ~5GB)

Development Setup

# Clone the repository
git clone https://github.com/hkuds/litewrite.git
cd litewrite

# Start with one command
./scripts/up-dev.sh

This will:

  1. Create .env from env.example.oss if missing
  2. Pull/build all Docker images
  3. Start the full stack (web, ws, ai-server, compile, minio, redis)

πŸ”— Access Points

Service URL Description
🌐 App http://localhost:3000 Main application
πŸ“¦ MinIO http://localhost:9001 Object storage console (minioadmin/minioadmin)
🧠 AI Server http://localhost:6612/health AI services health check
πŸ“„ Compile http://localhost:3002/health LaTeX compile service

🏭 Production Deployment

# With custom env files
./scripts/up-prod.sh --env-file .env.production --env-file .env.secrets
πŸ“‹ Required Environment Variables
Variable Description
NEXTAUTH_SECRET Random string for session encryption
INTERNAL_API_SECRET Internal service authentication
DATABASE_URL PostgreSQL connection string
S3_BUCKET S3 bucket name
S3_REGION S3 region
S3_ACCESS_KEY_ID S3 access key
S3_SECRET_ACCESS_KEY S3 secret key
OPENROUTER_API_KEY AI service API key

See env.example.oss for the complete configuration reference.


πŸ›  Tech Stack

🎨 Frontend

  • Framework: Next.js 14 (App Router)
  • Language: TypeScript 5
  • Editor: CodeMirror 6 + y-codemirror.next
  • UI: Tailwind CSS + Shadcn UI

βš™οΈ Backend

  • API: Next.js API Routes
  • ORM: Prisma
  • Auth: NextAuth.js 5
  • Collaboration: Yjs + y-websocket

🧠 AI Services

  • AI Server: Python FastAPI
  • LLM: OpenRouter (multi-model)
  • nanobot: Python + LiteLLM
  • Channels: Telegram, Feishu/Lark

πŸ—οΈ Infrastructure

  • Database: SQLite (dev) / PostgreSQL (prod)
  • Cache: Redis
  • Storage: S3-compatible (MinIO/AWS)
  • LaTeX: TeXLive (pdfLaTeX, XeLaTeX, LuaLaTeX)
  • Container: Docker + Docker Compose

✏️ Editor Experience

Feature Description
πŸ“ LaTeX Editor Built on CodeMirror 6 with syntax highlighting, smart completion, bracket matching, and folding
πŸ“„ Markdown Editor Full GFM support with code highlighting, math rendering (KaTeX), and live preview
πŸ‘οΈ Visual Editing Typora-like WYSIWYG: renders content while editing, shows source at cursor position
πŸ“‚ Multi-file Projects Organize large documents with \input{}, \include{}, and proper file tree management

πŸ€– AI-Powered Writing

Feature Description
⚑ TAP Completion Ghost-text AI completion as you type (Cursor/Copilot-like experience)
πŸ’¬ Ask AI Select text and ask AI to explain, improve, translate, or rewrite
πŸ€– Agent Mode Full autonomous editing β€” AI reads, plans, and applies multi-file edits
πŸ” Deep Research Multi-iteration research: web + arXiv search, structured report generation with BibTeX
πŸ“Š AI Table Generate LaTeX tables from natural language descriptions
πŸ“± nanobot Manage projects from Telegram/Feishu: edit files, compile PDFs, import papers

πŸ‘₯ Collaboration & Sharing

Feature Description
πŸ”„ Real-time Collaboration Multiple users editing simultaneously with cursor presence indicators
πŸ“œ Version History Create snapshots, compare diffs, and restore any previous version
πŸ”— Sharing Share projects via link with granular view/edit permissions

πŸ“„ Compilation & Preview

Feature Description
πŸ”§ Multiple Engines pdfLaTeX, XeLaTeX, LuaLaTeX with full TeXLive distribution
πŸ‘οΈ Live Preview Auto-compile on save with instant PDF preview
πŸ”€ SyncTeX Bi-directional navigation: click PDF to jump to source, click source to highlight PDF
πŸ“¦ Export Options Download PDF, source ZIP, or individual files

πŸ“ Project Structure

litewrite/
β”œβ”€β”€ app/                      # Next.js App Router pages & API routes
β”‚   β”œβ”€β”€ api/                  # REST API + Internal API endpoints
β”‚   β”œβ”€β”€ editor/               # Editor page
β”‚   └── (home)/               # Dashboard pages
β”œβ”€β”€ components/               # React components
β”‚   β”œβ”€β”€ editor/               # Editor-specific components
β”‚   β”œβ”€β”€ pdf-viewer/           # PDF preview components
β”‚   └── ui/                   # Shadcn UI components
β”œβ”€β”€ lib/                      # Shared utilities
β”œβ”€β”€ prisma/                   # Database schema & migrations
β”‚
β”œβ”€β”€ server/                   # WebSocket collaboration server
β”‚   β”œβ”€β”€ ws-server.ts          # Yjs WebSocket + HTTP endpoints
β”‚   └── yjs-persistence.ts    # Redis-based Yjs persistence
β”‚
β”œβ”€β”€ ai-server/                # AI service (Python FastAPI)
β”‚   β”œβ”€β”€ api/                  # Chat, TAP, Deep Research endpoints
β”‚   β”œβ”€β”€ services/             # Service implementations
β”‚   β”‚   β”œβ”€β”€ chat_1_5/         # Agent system (MainAgent + SubAgents)
β”‚   β”‚   β”œβ”€β”€ tap/              # TAP completion service
β”‚   β”‚   └── deep_research/    # Multi-iteration research
β”‚   β”œβ”€β”€ tools/                # Agent tools (read, edit, search, etc.)
β”‚   └── core/                 # Config, LLM client, caching
β”‚
β”œβ”€β”€ compile-server/           # LaTeX compilation service
β”‚
β”œβ”€β”€ nanobot/                  # Chat platform AI assistant
β”‚   └── nanobot/
β”‚       β”œβ”€β”€ agent/            # LLM agent loop + 20 Litewrite tools
β”‚       β”œβ”€β”€ channels/         # Telegram, Feishu, WhatsApp adapters
β”‚       β”œβ”€β”€ bus/              # Async message bus
β”‚       β”œβ”€β”€ config/           # Environment-based configuration
β”‚       └── skills/           # Extensible skill system
β”‚
β”œβ”€β”€ docker-compose.yml        # Development configuration
β”œβ”€β”€ docker-compose.prod.yml   # Production configuration
└── scripts/                  # Setup & deployment helpers

πŸ”§ Development

Common Commands

# Start development environment
docker compose up

# Start in background
docker compose up -d

# View logs
docker compose logs -f web
docker compose logs -f ai-server
docker compose logs -f nanobot

# Rebuild specific service
docker compose up --build web

# Reset database
docker compose exec web npx prisma migrate reset

# Run TypeScript check
npm run typecheck

πŸ”₯ Hot Reload

Directory Service Auto-reload
app/, components/, lib/ Next.js βœ…
server/ WebSocket βœ…
ai-server/ AI Server βœ…
nanobot/ nanobot βœ…
compile-server/ Compile ❌ (rebuild needed)

βš™οΈ Environment Variables

πŸ“‹ Click to expand full list

Core

Variable Description Default
NEXTAUTH_SECRET NextAuth encryption secret (required)
INTERNAL_API_SECRET Internal service auth (required)
DATABASE_URL Database connection file:./dev.db

AI Providers

Variable Description Default
OPENROUTER_API_KEY LLM API key (required for AI features) β€”
OPENROUTER_API_KEYS Multiple keys for rotation β€”
OPENROUTER_KEY_STRATEGY Key rotation: round_robin, random, least_used round_robin
LLM_MODEL Default LLM model google/gemini-3-flash-preview
EMBEDDING_API_BASE Embedding API URL https://openrouter.ai/api/v1
EMBEDDING_API_KEY Embedding API key β€”
EMBEDDING_MODEL Embedding model text-embedding-3-small
SERPER_API_KEY Web search (for Deep Research) β€”

nanobot

Variable Description Default
TELEGRAM_ENABLED Enable Telegram bot false
TELEGRAM_BOT_TOKEN Telegram bot token from @BotFather β€”
FEISHU_ENABLED Enable Feishu bot false
FEISHU_APP_ID Feishu app ID β€”
FEISHU_APP_SECRET Feishu app secret β€”
NANOBOT_DEFAULT_LITEWRITE_USER_ID Litewrite user UUID for project ownership β€”

Storage

Variable Description Default
STORAGE_PROVIDER s3 or local s3
S3_ENDPOINT S3 endpoint URL http://localhost:9000
S3_BUCKET S3 bucket name litewrite
S3_REGION S3 region us-east-1
S3_ACCESS_KEY_ID S3 access key β€”
S3_SECRET_ACCESS_KEY S3 secret key β€”

Optional

Variable Description Default
REDIS_URL Redis URL (enables Yjs persistence + rate limiting) β€”
NEXT_PUBLIC_WS_URL Public WebSocket URL for clients ws://localhost:1234
TAP_MODEL Override model for TAP completion (uses LLM_MODEL)

πŸ“„ See env.example.oss for the complete template.


🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

# Quick contribution workflow
git clone https://github.com/hkuds/litewrite.git
cd litewrite
git checkout -b feature/your-feature
# Make your changes
git commit -m "feat: add amazing feature"
git push origin feature/your-feature
# Open a Pull Request

Contributors

Contributors

πŸ™ Acknowledgments

Litewrite is built on the shoulders of giants:


⭐ Star History

Thanks for visiting ✨ litewrite!

Views

⭐ Star us on GitHub!

About

"Litewrite: Vibe Writing is Coming - Write Faster and Better! https://litewrite.ai"

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •