Design Cursor (AI Code Editor with Agent Edits)
Problem statement
Design a Cursor-style AI code editor — context chips (@file / selection), a BFF-backed agent stream, pending diffs with Accept/Reject, and a stability rule: the model never silently owns the buffer. Mentor-tone walkthrough with placement + agent-pipeline wireframes.
Asked In
Key Challenges
- ·Context chips (@file, selection, open tabs) that budget the prompt window without pasting whole repos
- ·Agent timelines that propose multi-file edits as reviewable events — not silent buffer writes
- ·Pending diffs with Accept / Reject so the model never owns the editor buffer
- ·Streaming patches that can be stopped mid-flight without corrupting committed code
- ·Keeping API keys and tool orchestration behind a BFF while the IDE stays snappy in the browser
2-Minute Answer — High-Level TL;DR
Read this before your interview
HLD Interview Focus
I would design Cursor as three systems sharing one editor buffer. First, context chips — @file, the current selection, open tabs — are first-class UI state that budgets what goes into the prompt, not a giant paste. Second, the composer talks to a BFF that owns keys, tools, and model routing; the browser never calls the LLM API directly. Third, agent output arrives as SSE events: tokens for chat, and patch_proposed for edits. Patches land in a pending-diff queue. Accept merges into the buffer with an undo entry; Reject discards. The sticky rule: proposed edits are a review queue — the model never silently owns the file.
My Approach: Building the Solution
How to think about this problem
Start from the user moment: they highlight a buggy auth helper, @-mention auth.ts, and ask the agent to refactor. Juniors draw a chat panel and a Monaco editor. Seniors draw context chips, an agent timeline, and a pending-diff queue that gates every write into the buffer.
Why This Approach?
Most weak answers treat this as 'ChatGPT + CodeMirror.' That collapses when the interviewer asks what happens if the model rewrites the wrong file mid-stream, or how Stop interacts with a half-applied patch. Once you separate committed buffer from pending patches, Accept/Reject, multi-file tabs, and Abort become natural — the same way regenerate forced a message tree in ChatGPT.
Think of agent edits like a pull request, not autocomplete. Autocomplete inserts as you type. A PR opens a reviewable diff; merge is an explicit human action. Cursor's Accept button is merge. Streaming tokens into the file without review is force-pushing to main.
Requirements: What Makes a Great Solution?
Clarify scope before designing anything
Requirements Exploration Questions
Ask your interviewer these questions to refine requirements
What product modes are in scope?
- ·Ask mode (answer questions, no file writes) vs Agent mode (propose multi-file patches)
- ·Inline edit (Cmd-K style) vs chat sidebar agent
- ·Single-file vs workspace-wide edits
- ·Local / on-device models vs cloud API behind a BFF
What context can the user attach?
- ·@file, @folder, current selection, open tabs, git diff, docs links
- ·Hard token budget — which chips get truncated first?
- ·Privacy: can context leave the machine for cloud models?
What are the latency and safety expectations?
- ·Time-to-first-token for chat; time-to-first-patch for agent edits
- ·Stop must cancel server work and freeze pending patches
- ·Accept/Reject required, or auto-apply with undo?
- ·Conflict if the user typed into the buffer while a patch was pending
Functional Requirements
Must Have — MVP
- ✓Composer with context chips that attach/detach files and selections
- ✓Streaming assistant replies (SSE) with Stop via AbortController
- ✓Agent mode that proposes unified diffs as pending patches
- ✓Accept / Reject per patch (or per hunk) before mutating the buffer
- ✓Multi-file tabs reflecting which files have pending edits
- ✓Agent step timeline (planning, tool call, patch proposed)
- ✓Model / mode picker that gates capabilities (e.g. Agent disabled on tiny models)
Advanced (If Time Permits)
- +Inline ghost-text speculative completions reconciled against the real stream
- +Multi-tab sync of draft composer + pending patches
- +Checkpoint / restore of buffer before a batch of agent edits
- +MCP / tool cards embedded in the agent timeline
Non-Functional Requirements
Performance
- ·TTFT <800ms p50 for Ask; first patch_proposed <2s p50 for small refactors
- ·Editor remains responsive while streaming — never block the main thread on huge diffs
- ·Virtualize long agent timelines and large unified diffs
Reliability
- ·Stop aborts fetch + freezes pending patches mid-stream
- ·If the user edits a file with a pending patch, mark conflict and require re-base or Reject
- ·Network drop keeps partial chat; pending patches stay reviewable
Security & privacy
- ·No provider API keys in the browser — BFF / AI gateway only
- ·Sanitize rendered Markdown / code from the model (XSS)
- ·Respect workspace ignore rules for context gathering
Accessibility
- ·Keyboard Accept / Reject / Stop
- ·aria-live for agent status without shouting every token
- ·Diff view usable with screen readers (line-level announcements on focus)
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Full RADIO-framework walkthrough with architecture diagrams
- Data model, API design, and rendering strategy trade-offs
- Performance, accessibility, and offline sections plus a model answer
Already a member? Log in to open the workspace.