← Back to Portfolio
Case Study — Collaborative Document Editor

Google Docs Mirror
A Collaborative Editor

A small full-stack app inspired by Google Docs, deployed as "Ajaia Docs": rich-text editing with autosave, import of .txt, .md and .docx files, and sharing with owner, editor and viewer roles. Built in a fixed timebox, with the effort put where bugs cost the most: access control and saving.

Next.js 14 / TypeScript Tiptap (ProseMirror) libSQL / Turso Vercel Vitest ▶ Personal Project · 2026
16 Automated Tests
3 Roles: Owner / Editor / Viewer
3 Import Formats
5s Edit-Detection Poll
01 — The Goal

What Needed to Be Right

A document editor has a long feature list. Within a timebox, the question was which parts could not afford to be wrong.

🔒

Access control

Sharing is the part most likely to be subtly wrong, so every permission decision lives in one place and is covered by tests.

💾

A trustworthy editing loop

Autosave with a visible state, retry on failure, and no lost edits matter more than a long toolbar.

🚀

Easy to run and review

A free, zero-config stack: runs locally with no setup and deploys to Vercel with a hosted database.

02 — Architecture

How It Fits Together

Route handlers stay thin. Every rule lives in a small library layer that takes a database client, so it can be tested without HTTP.

Client
Login Dashboard Editor (Tiptap) Share dialog
↓ fetch to /api
API
app/api/** route handlers zod validation Signed-cookie session
↓ calls the domain layer
Domain
lib/access.ts (roles) lib/documents.ts lib/importer.ts lib/export.ts
↓ SQL via one shared client
Data
libSQL: SQLite locally, Turso in production users · documents · shares
03 — Features

What It Does

The parts I built and tested end to end.

✎️

Rich text

Bold, italic, underline, H1 to H3, bulleted and numbered lists, undo and redo, plus working File, Edit and Format menus.

🔄

Autosave

Debounced saves with an "All changes saved" state and a Retry button if a save fails.

📥

File import

.txt, .md and .docx files up to 2 MB become new editable documents. Limits are stated in the UI.

🔗

Sharing

Share by email as Can edit or View only. Change or revoke access. "My documents" and "Shared with me" with role badges.

📤

Export

Download as Markdown or plain text. Save as PDF through the browser print dialog.

👁️

Edit detection

If someone else saves while you have a document open, a banner appears within about 5 seconds with a Reload button.

04 — Technology

Technology Choices

Each choice has a reason tied to the timebox or to deployment.

LayerTechnologyWhy
App framework Next.js 14 + TypeScript One repo and one deploy for UI and API; route handlers keep the backend small.
Editor Tiptap (ProseMirror) A real rich-text engine out of the box. Building on contenteditable would have used the whole timebox.
Database libSQL (@libsql/client) The same code runs on a local SQLite file for development and on hosted Turso in production.
Validation zod Request validation in one declarative place.
Tests Vitest Fast tests against an in-memory libSQL database, with no mocking of the database.
Hosting Vercel + Turso Serverless has no persistent disk, so a hosted database is required.
05 — Decisions

Calls That Mattered

The trade-offs that shaped the final design.

01

Access rules in one tested place

Roles are owner, editor, viewer or none. Read needs any role, edit needs owner or editor, delete and sharing need owner. A user with no access gets 404, not 403, so document ids cannot be probed. Enforcement is on the server for every route; hiding buttons in the UI is only a convenience.

02

Store editor JSON, not HTML

Content is saved as Tiptap/ProseMirror JSON. That keeps structure exact, and imported files use the same schema, so imported and hand-written documents are identical.

03

libSQL and Turso instead of plain SQLite

Plain SQLite on Vercel would lose data on an ephemeral disk. libSQL keeps the same code for local and hosted use.

04

Polling instead of websockets

Serverless hosting cannot hold long-lived connections, so open editors poll a tiny meta endpoint every 5 seconds. It signals conflicts but does not resolve them, and that limit is stated openly.

05

Mocked auth, on purpose

Seeded users and a signed cookie let a reviewer test sharing in seconds. It is clearly labelled as mocked, with real authentication listed as the next step.

06 — Hard Parts

What Needed Care

Problems where a naive version loses data or trust.

💾 Autosave without losing edits

Edits made while a save is in flight must not be dropped. Pending changes are kept in refs so the debounced saver always sends the latest state, and an edit during a save triggers another save.

✓ Retry button and best-effort save on page close

📁 Import without corrupting documents

Imported files go through the same editor schema, so anything that cannot be represented is dropped rather than breaking the document. Guards cover the extension allow-list, the 2 MB cap, empty files, and corrupt files return a friendly 422.

✓ Same schema for import and editing

☁️ Serverless persistence

The app needed a database that survives on a platform with no disk. The test suite includes a concurrent cold-start race and an in-place schema migration for existing databases.

✓ Hosted Turso, tested start-up path

🔑 Permissions that are easy to get wrong

The owner, editor, viewer and no-access matrix is tested directly, including the 404 versus 403 behaviour and cascade on delete.

✓ Pure role rules plus matrix tests
07 — Outcomes

What This Demonstrates

What a reviewer can verify in the repo and the live demo.

16 Tests Access rules, sharing, validation, import, export, last-edited tracking, migration and a cold-start race.
404/403 Deliberate errors No access returns 404; insufficient permission returns 403 with a clear message.
0 Setup to run With no env vars the app creates its SQLite file, schema and seed users on first request.
18 Screenshots The repo documents login, editing, menus, sharing, import errors, shared views and mobile.
2 Docs An architecture note and an AI-workflow note explain the trade-offs and how AI was used.
Live Deployed Running on Vercel with a health endpoint that reports configuration and database status.
08 — Limits

Known Limits and What Is Next

Stated plainly in the repo, and repeated here.

⚠️

No real-time merging

Saves are last-write-wins. The editor detects other people's saves but you must reload to see them. Real merging needs a CRDT such as Yjs and a websocket host.

🔑

Authentication is mocked

Anyone can pick any seeded user. That is deliberate for a review exercise.

📐

What I would build next

Real-time collaboration with Yjs, version history, server-generated PDF export, real authentication, and Playwright end-to-end tests.

Available for work

Want to build something
like this together?

I'm open to full-time roles and project work in AI engineering, full-stack development, and backend systems.