Skip to content

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
Asked at
Practice this question

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

AskWhy it mattersA 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.

The requirements menu

RequirementScopeWhy

Show a folder tree that opens folders as the person expands them

Core

The tree is how people move around. Opening on expand, rather than loading the whole tree, keeps the first paint small.

List the files in the open folder, with name, size and date

Core

The main view. Its row count is what grows past the page, so most of the performance work lands here.

Open a file and show it in a way that fits its type

Core

Text, images and data files each need a different view, and a file from a stranger needs a trust decision.

Upload new files into the open folder, with progress

Core

A progress bar is what the person has to go on during a long upload, and a large file on a slow connection needs resumability behind it.

Move through folders with links and the back button

Core

It forces the path into the address, which also makes reload and shared links work.

Drag a whole folder in to upload it

Optional

Take it if the interviewer raises it: it needs the directory entries API and a walk through folder readers that return entries in batches. Leave it until single-file upload is solid.

Sort the list by name, size or date

Optional

Take it if the list is paged by the server, since a sort of a partly loaded folder has to happen on the server. Leave it if time is short: it's a parameter on the children request.

Rename, move or delete files from the list

Optional

Take it for a drive product, where it's expected. It brings optimistic updates and rollback, which can crowd out the core in a short round.

Work offline from a local copy of folders

Out of scope

A sync engine on the device is a product of its own. Keeping loaded pages in memory for this visit gets most of the benefit here.

Sharing and permissions

Out of scope

Who may see a folder is decided on the server; the client shows what it is given.

Search across all files

Out of scope

A search index is a backend question. A filter box over the loaded names is a small client feature you can mention.

Editing files in the browser

Out of scope

An editor and a save path are a separate design; this round stops at viewing.

Version history of a file

Out of scope

History is a different view with its own data; the viewer here shows the current file.

Non-functional requirements

RequirementWhat 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

EntityWhat 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

EndpointNotes

GET /folders/{path}/children?cursor&limit&fields → { entries, next_cursor }

One page of a folder. cursor is opaque and comes from the previous answer; limit sizes the page; fields names the columns the list shows, so a row doesn't carry columns the list won't draw. A null next_cursor means the folder is complete.

GET /files/{path} → { name, size, type, content or raw_url }

Metadata plus either the content inline, for files the viewer draws whole, or a raw_url on the file origin for images, downloads and anything too large.

POST /uploads { folder, name, size } → { upload_url }

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.

PUT {upload_url} with Content-Range: bytes {start}-{end}/{total} → 308 { range } or 201 { file }

One chunk. A 308 means the server took it and wants more, with the range it now holds; a 201 means the file is complete and returns its entry.

PUT {upload_url} with Content-Range: bytes */{total} → 308 with the bytes the server has

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

openlistingFolder treeServerFile list

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.

open folder,pushStatepathmissing page,cursorpage of entriesrows near theviewportopen file, typeand sizestranger's HTMLchunks with byterange308 with rangeFolder treeAddress andhistoryEntries by pathServerFile listViewer by typeSandboxed frameDrop or pickerUpload queue
The whole design

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?

A concept that helps here: List virtualizationA concept that helps here: Pagination and infinite scrollA concept that helps here: Client caching and normalized stores

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?

A concept that helps here: Where state livesA concept that helps here: Accessible widgetsA concept that helps here: Client caching and normalized stores

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.

A concept that helps here: Chunked and resumable uploadsA concept that helps here: Reconnect and resume

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?

A concept that helps here: Sandboxing untrusted codeA concept that helps here: List virtualization

Concepts this guide uses

Sources

  1. GitHub Docs: REST API endpoints for repository contents
  2. GitHub Changelog: Increased file size limit when retrieving file contents via REST API
  3. GitHub Docs: Working with non-code files
  4. Google Drive API: Upload file data
  5. Fast.io: Google Drive resumable upload, architecture, limits and workspace solutions
  6. MDN: Working with the History API
  7. WAI-ARIA Authoring Practices Guide: Tree View pattern
  8. WAI-ARIA Authoring Practices: File directory treeview example
  9. accessibility.build: Accessible tree view guide
  10. MDN: DataTransferItem webkitGetAsEntry()
  11. MDN source: FileSystemDirectoryReader readEntries()
  12. MDN: XMLHttpRequest upload property
  13. MDN: Blob slice()
  14. MDN: The iframe element
  15. web.dev: Interaction to Next Paint (INP)
  16. web.dev: Web Vitals
  17. techinterview.org: Frontend system design, build the GitHub repository UI
Sign in to report a mistake