<p align="center">
<img src="public/logo.svg" alt="Litewrite Logo" width="120" />
</p>
<h1 align="center">โ๏ธ Vibe Writing is Coming โ Write Faster and Better!</h1>
<p align="center">
<strong>Litewrite: AI-Powered Collaborative LaTeX Writing Platform</strong><br>
</p>
<p align="center">
<a href="https://github.com/hkuds/litewrite"><img src="https://img.shields.io/badge/version-1.0.7-blue.svg" alt="Version" /></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-AGPL--3.0-blue.svg" alt="License" /></a>
<a href="https://github.com/hkuds/litewrite/actions"><img src="https://img.shields.io/github/actions/workflow/status/hkuds/litewrite/ci.yaml?branch=main&label=CI" alt="CI" /></a>
<img src="https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&logoColor=white" alt="TypeScript" />
<img src="https://img.shields.io/badge/Next.js-14-black?logo=next.js" alt="Next.js" />
<img src="https://img.shields.io/badge/Python-3.12-3776AB?logo=python&logoColor=white" alt="Python" />
<img src="https://img.shields.io/badge/Docker-Ready-2496ED?logo=docker&logoColor=white" alt="Docker" />
</p>
<p align="center">
<a href="https://discord.gg/M88Y27DDEe"><img src="https://img.shields.io/badge/๐ฌDiscord-Community-7289da?style=for-the-badge&logo=discord&logoColor=white&labelColor=1a1a2e"></a>
<a href="https://github.com/HKUDS/Litewrite/issues/4"><img src="https://img.shields.io/badge/๐ฌWeChat-Group-07c160?style=for-the-badge&logo=wechat&logoColor=white&labelColor=1a1a2e"></a>
</p>
<p align="center">
<a href="https://litewrite.ai"><img src="https://img.shields.io/badge/๐_Live_Demo-litewrite.ai-ff6b6b?style=for-the-badge" alt="Demo" /></a>
</p>
<p align="center">
<a href="#-news">News</a> •
<a href="#-features">Features</a> •
<a href="#-screenshots">Screenshots</a> •
<a href="#%EF%B8%8F-architecture">Architecture</a> •
<a href="#-ai-features">AI Features</a> •
<a href="#-nanobot--chat-platform-integration">nanobot</a> •
<a href="#-quick-start">Quick Start</a> •
<a href="#-contributing">Contributing</a>
</p>
---
<div align="center">
Try Litewrite: (https://litewrite.ai/)
</div>
## ๐ฐ News
- **2026-02-10** ๐ค **[nanobot ร Litewrite](https://github.com/HKUDS/nanobot) โ nanobot empowers your vibe writing ([setup guide](nanobot/DEPLOYMENT.md))
- **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](https://github.com/HKUDS/nanobot)** โ Chat with your projects from IM apps. Compile, edit, and manage โ all from your phone!
---
<p align="center">
<img src="public/screenshots/nanobot-demo.gif" alt="nanobot Demo โ Chat with your projects from Telegram" width="720" />
</p>
<p align="center"><em>๐ฌ Chat with your projects from IM apps</em></p>
---
## ๐ธ Screenshots
<details>
<summary><b>Click to expand screenshots</b></summary>
<br>
#### ๐ Landing Page
<p align="center">
<img src="public/screenshots/landing.png" alt="Landing Page" width="800" />
</p>
<p align="center"><em>AI-integrated vibe writing โ lite, fast, effortless</em></p>
#### ๐ Template Gallery
<p align="center">
<img src="public/screenshots/templates.png" alt="Template Gallery" width="800" />
</p>
<p align="center"><em>10+ pre-built templates: NeurIPS, ACM, Beamer, CV, Thesis, and more</em></p>
#### ๐ฃ Symbol Panel
<p align="center">
<img src="public/screenshots/symbols.png" alt="Symbol Panel" width="500" />
</p>
<p align="center"><em>Quick insert Greek letters, math operators, and LaTeX constructs</em></p>
#### ๐ Reference Search
<p align="center">
<img src="public/screenshots/references.png" alt="Reference Search" width="600" />
</p>
<p align="center"><em>Search and insert BibTeX citations with fuzzy matching</em></p>
#### ๐ Version History
<p align="center">
<img src="public/screenshots/history.png" alt="Version History" width="800" />
</p>
<p align="center"><em>Create snapshots, compare diffs, and restore any previous version</em></p>
#### ๐ Project Sharing
<p align="center">
<img src="public/screenshots/share.png" alt="Share Project" width="400" />
</p>
<p align="center"><em>Share via link or invite collaborators by email</em></p>
</details>
> ๐ก **Try it yourself:** Visit [litewrite.ai](https://litewrite.ai) for the live demo!
---
## ๐๏ธ Architecture
Litewrite is a microservices architecture with 6 core services communicating over a Docker network.
<p align="center">
<img src="public/Architecture.png" alt="Litewrite Architecture" width="800" />
</p>
| 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.
<p align="center">
<img src="public/AIServer.png" alt="Litewrite AI Architecture" width="800" />
</p>
### โก 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.
<p align="center">
<img src="public/MainAgent.png" alt="Litewrite Main Agent Architecture" width="800" />
</p>
**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.
<p align="center">
<img src="public/DeepResearch.png" alt="Litewrite Deep Research" width="800" />
</p>
### ๐ง Unified Tool Layer
All tools inherit from a base `Tool` class with standardized interfaces:
```python
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](https://github.com/HKUDS/nanobot) โ Chat Platform Integration
[nanobot](https://github.com/HKUDS/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](nanobot/DEPLOYMENT.md).
<!-- TODO: Replace with nanobot architecture image -->
<p align="center">
<img src="public/nanobot.png" alt="Litewrite nanobot Architecture" width="800" />
</p>
### ๐ ๏ธ 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](https://www.docker.com/products/docker-desktop/) (includes Docker Compose)
- 8GB+ RAM recommended (TeXLive image is ~5GB)
### Development Setup
```bash
# 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
```bash
# With custom env files
./scripts/up-prod.sh --env-file .env.production --env-file .env.secrets
```
<details>
<summary><b>๐ Required Environment Variables</b></summary>
| 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.
</details>
---
## ๐ Tech Stack
<table>
<tr>
<td>
### ๐จ Frontend
- **Framework:** Next.js 14 (App Router)
- **Language:** TypeScript 5
- **Editor:** CodeMirror 6 + y-codemirror.next
- **UI:** Tailwind CSS + Shadcn UI
</td>
<td>
### โ๏ธ Backend
- **API:** Next.js API Routes
- **ORM:** Prisma
- **Auth:** NextAuth.js 5
- **Collaboration:** Yjs + y-websocket
</td>
</tr>
<tr>
<td>
### ๐ง AI Services
- **AI Server:** Python FastAPI
- **LLM:** OpenRouter (multi-model)
- **[nanobot](https://github.com/HKUDS/nanobot):** Python + LiteLLM
- **Channels:** Telegram, Feishu/Lark
</td>
<td>
### ๐๏ธ Infrastructure
- **Database:** SQLite (dev) / PostgreSQL (prod)
- **Cache:** Redis
- **Storage:** S3-compatible (MinIO/AWS)
- **LaTeX:** TeXLive (pdfLaTeX, XeLaTeX, LuaLaTeX)
- **Container:** Docker + Docker Compose
</td>
</tr>
</table>
---
### โ๏ธ 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](https://github.com/HKUDS/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
```bash
# 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
<details>
<summary><b>๐ Click to expand full list</b></summary>
### 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.
</details>
---
## ๐ค Contributing
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
```bash
# 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
<a href="https://github.com/HKUDS/litewrite/graphs/contributors">
<img src="https://contrib.rocks/image?repo=HKUDS/litewrite&max=100&columns=12&updated=20260210" alt="Contributors" />
</a>
---
## ๐ Acknowledgments
Litewrite is built on the shoulders of giants:
- [Next.js](https://nextjs.org/) โ React framework
- [CodeMirror](https://codemirror.net/) โ Code editor
- [Yjs](https://yjs.dev/) โ CRDT for collaboration
- [Prisma](https://www.prisma.io/) โ Database ORM
- [TeXLive](https://tug.org/texlive/) โ TeX distribution
- [Shadcn UI](https://ui.shadcn.com/) โ UI components
- [OpenRouter](https://openrouter.ai/) โ LLM routing
- [LiteLLM](https://github.com/BerriAI/litellm) โ LLM provider abstraction
- [nanobot](https://github.com/HKUDS/nanobot) โ Ultra-lightweight AI assistant
---
## โญ Star History
<div align="center">
<a href="https://star-history.com/#HKUDS/litewrite&Date">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=HKUDS/litewrite&type=Date&theme=dark" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=HKUDS/litewrite&type=Date" />
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=HKUDS/litewrite&type=Date" style="border-radius: 15px; box-shadow: 0 0 30px rgba(0, 217, 255, 0.3);" />
</picture>
</a>
</div>
<p align="center">
<em> Thanks for visiting โจ litewrite!</em><br><br>
<img src="https://visitor-badge.laobi.icu/badge?page_id=HKUDS.litewrite&style=for-the-badge&color=00d4ff" alt="Views">
</p>
<p align="center">
<a href="https://github.com/hkuds/litewrite/stargazers">โญ Star us on GitHub!</a>
</p>