FrontendPro

144Implement a browser IDE with syntax highlighting, files, tabs, and isolated code execution

hardAbout 90 minutesCodingidetokenizerweb-workersfile-systemarchitecture

Problem

Build the core of a CodeSandbox-style IDE: the parts behind the UI.

  1. File system createFileSystem(): writeFile(path, content) (creating parent folders), readFile(path), mkdir(path), rename(from, to) (moving a folder moves everything inside), remove(path) (recursive), exists(path), list(dir) (entry names, folders first, then alphabetical), and files() (every file path). Paths are absolute (/src/app.js); throw an Error for missing paths.
  2. Tabs createTabs(): open(path) (no duplicates; activates it), close(path) (activates the tab to the right, else the left), setDirty(path, dirty), closeOthers(path), reopenClosed() (the most recently closed), and state() returning { tabs: [{ path, dirty }], active }.
  3. Syntax highlighting tokenize(code): an array of { type, value } with types keyword, string (single, double and template quotes), number, comment (line and block), identifier, punctuation and whitespace. Joining all values must give back the exact input.
  4. Isolated execution runProject(fs, entry, { timeout = 1000 }): run the project's JavaScript in a fresh Web Worker with a CommonJS require that resolves relative paths between project files (require("./utils") → /src/utils.js), capturing console.log lines. Resolve { logs }, or { logs, error } if the code throws, or reject with an error named "TimeoutError" (terminating the worker) after timeout ms.

Try it yourself

Write your solution, run it, then submit to check it against the tests.

App.jsxReact + DOM

Step-by-step

Store a root folder { type: "dir", children: Map }. Resolving a path splits it on / and walks the maps. writeFile walks while creating missing folders; remove deletes the entry from its parent's map; rename detaches the node from the old parent and attaches it under the new name, so a folder's whole subtree moves in O(depth).

Unlock the full solution

What's inside

  • Step-by-step
  • Approach
  • Solution
  • Complexity
  • Edge cases
  • Follow-up questions
  • Tests

Includes 2 code listings, 5 edge cases, 4 follow-up questions.

One-time payment by UPI, card or net banking. Launch price.

All 150 answersOne payment, yours forever