How to design a file browser (frontend)
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- A folder with thousands of files
- Moving through the tree and back
- Uploading a large file on a slow connection
- Showing a file of any type
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
- Lyft
- Adobe
The problem
A web client for browsing files: a folder tree down one side, the open folder's files beside it, a viewer for the file someone clicks and a way to upload new ones with progress. The answer turns on two sizes that outgrow the page. A folder can hold far more entries than a screen can show, so the list fetches in pages and keeps in the document just the rows near the viewport. A large file on a slow connection should go to a resumable session in chunks, so a drop costs the bytes in flight rather than the whole file. Around those two sit the address bar as the record of where the person is, and a strict rule that keeps someone else's file from running in your page.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
Is this a code hosting product or a cloud drive? | A code host leans on a text viewer for source files. A drive has photos, videos, documents and other people's uploads, which pulls the viewer and the trust question forward. | Treat it as either: the tree, the list, the viewer and uploads are the same shape. Assume files of any type, including an HTML page that a stranger uploaded. |
How many files can one folder hold? | A small folder is a simple list. Thousands of rows decide whether the list needs pages and windowing, which is one of the two big topics. | Say a folder can reach 1,000 files and beyond. As a reference point, GitHub's contents API lists at most 1,000 files for a directory. |
How large are the files people open, and which types? | It sets the size you fetch whole and whether you need a viewer per type or a plain text view. | Show files up to 1 MB whole, and hand out anything bigger as a raw download. Types include text, images, data files and HTML. |
How large are uploads, and on what kind of connection? | A small file on an office network is one request. A large file on a train needs a session that survives a drop, which is most of the upload design. | Uploads over 5 MB arrive on slow connections, and a dropped connection must not send the person back to the first byte. |
Should back, reload and a shared link open the same folder? | It decides whether the open folder is page state or lives in the address, with one history entry for each folder opened. | Yes. Someone three folders deep can press back twice, reload, and send the link to a teammate, and each should land where expected. |
Who uses it, and does it need to work by keyboard and with a screen reader? | A tree is one of the harder widgets to make accessible, and the choice of roles and keys changes the markup from the start. | Yes to both. The tree should follow the standard tree pattern, and a click should answer within 200 milliseconds. |
Can I shape the server API, or is it fixed? | Cursor pages, a fields parameter and a resumable upload endpoint are easier to design for than to work around. | You can shape it. Assume a cursor-paged children endpoint, a file endpoint that returns content or a raw address, and a resumable upload session. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
A click on a folder or file answers within 200 milliseconds | Whatever is already known has to paint at once, and whatever is not gets a placeholder. The budget is for the response to the click, measured as Interaction to Next Paint, and a round trip to the server is not something you can count on fitting inside it. So folders are kept by path after the first load, and a folder click shows the stored rows or a skeleton before any request returns. |
A folder of 1,000 files or more scrolls smoothly | The list is fetched in pages with a cursor and windowed, so the document holds rows near the viewport inside a spacer that keeps the scrollbar honest. Row components stay light because they redraw as the person scrolls. |
An upload survives a dropped connection without starting over | Files above the single-request size go to a resumable session: the file is cut into chunks, each sent with a byte range, and after a drop the client asks the server which bytes it has before sending more. |
The tree works by keyboard and with a screen reader | The tree uses the tree and treeitem roles with expanded state on parent nodes, a roving tab stop so Tab enters the tree once and arrow keys move inside it, and loading and error states that are announced, not just drawn. |
A file from someone else never runs code in the page | A stranger's HTML is shown as source text by default. If a rendered preview is wanted, it goes in a sandboxed frame whose document comes from a different origin, and the raw file endpoint lives on that origin too, so nothing from an upload shares the app's origin. |
Core entities
| Entity | What it holds |
|---|---|
Folder | A node in the tree. Its children are fetched the first time it opens and kept under its path. |
File entry | One row of the list: enough to draw the row and pick a viewer, without the file's bytes. |
Folder page | One response from the children endpoint, stored under the folder path in the order it arrived. |
Upload | One file on its way to the server, with the session address the client keeps so it can continue after a drop, or offer to continue after a reload once the file is picked again. |
Client state | Everything the page knows right now, with the address as the record of which folder or file is open. |
The API
| Endpoint | Notes |
|---|---|
| One page of a folder. |
| Metadata plus either the content inline, for files the viewer draws whole, or a |
| Opens a resumable session and returns its address. The client stores the address with the upload so it can continue after a drop, and so a reloaded page can offer to continue once the person picks the same file again. |
| One chunk. A |
| The question the client asks after a drop: no body, just the total. The answer's range says where to continue, and the client resends from there rather than trusting its own count. |
The high-level design
Step 1 of 4
Tree, list and server
Start with the shortest path that works. The tree asks the server for a folder when someone clicks it, the server returns the whole listing, and the list draws a row for each entry. Clicking a file fetches it and prints it. It shows the data flow end to end, and it has the problems the rest of the design answers: a big folder is fetched and drawn whole, a stranger's file is handled like any other, and the open folder lives in the component, so back leaves the site and reload forgets where the person was.
What breaks first
The deep dives
A folder with thousands of files. Someone opens a folder holding several thousand files, each row with an icon, name, size and date, and drags the scrollbar straight to the bottom. What does your page fetch, what does it hold in the document, and what happens when one page of entries fails to arrive?
Moving through the tree and back. Someone opens three folders deep, clicks a file, presses back twice, reloads the page and then sends the link to a teammate. What does the page show at each step, and what in your design decides it?
Uploading a large file on a slow connection. Someone starts uploading a large video from a train. The connection drops halfway and comes back a few minutes later. Follow the bytes: what was sent, what the server kept, and what the client does next.
Showing a file of any type. Someone opens, in turn, a short text file, a photo, a log file of many megabytes and an HTML page a stranger uploaded. What does your page show for each, and what decides it before any bytes are fetched?
Concepts this guide uses
Sources
- GitHub Docs: REST API endpoints for repository contents
- GitHub Changelog: Increased file size limit when retrieving file contents via REST API
- GitHub Docs: Working with non-code files
- Google Drive API: Upload file data
- Fast.io: Google Drive resumable upload, architecture, limits and workspace solutions
- MDN: Working with the History API
- WAI-ARIA Authoring Practices Guide: Tree View pattern
- WAI-ARIA Authoring Practices: File directory treeview example
- accessibility.build: Accessible tree view guide
- MDN: DataTransferItem webkitGetAsEntry()
- MDN source: FileSystemDirectoryReader readEntries()
- MDN: XMLHttpRequest upload property
- MDN: Blob slice()
- MDN: The iframe element
- web.dev: Interaction to Next Paint (INP)
- web.dev: Web Vitals
- techinterview.org: Frontend system design, build the GitHub repository UI