Muhammad Saad Ahsan

Muhammad Saad Ahsan / All projects

Notely API

Backend API · 2026

A note-taking API, built like production.

A REST API for a note-taking app, built as a practice project to production standards: NestJS, Prisma and MySQL, with rotating refresh tokens, owner-scoped notes and CI that runs every test against a real database.

Role
Sole developer
Type
Practice project
Stack
NestJS 12 · Prisma 7
Tests
Unit + e2e on MySQL

Notely is the backend for a Flutter note-taking app, built to practise what a production API needs beyond working endpoints: authentication that stays safe on a phone signed in for weeks, data that only its owner can reach, and a codebase checked on every push. Users register and sign in, then create, search, pin, archive and delete their notes through a versioned REST API.

The challenge

A mobile app keeps people signed in for weeks, so one long-lived token would be convenient and dangerous at once. And the most common serious API flaw is an endpoint that checks you are signed in, but not that the note you asked for is yours.

The approach

Short-lived access tokens with rotating refresh tokens that detect reuse, notes that can only ever be queried together with their owner, and every decision written down as an architecture decision record and proven by tests against a real MySQL database.

Architecture

  1. Layered NestJS modules, with a controller, service and repository per feature, and configuration validated by Zod at startup, so a misconfigured server refuses to start
  2. Secure by default: a global JWT guard that routes opt out of with @Public, validation that rejects unknown fields, one error format with request IDs, plus helmet, CORS and rate limits
  3. Prisma 7 on MySQL 8 with versioned migrations and UUIDv7 keys, and a CI check that the schema still matches the migrations

Key features

Rotating refresh tokens

Opaque tokens stored only as hashes and replaced on every refresh; reusing an old one revokes every session of that user.

Logout that works

Sign out of one device or all of them, effective immediately, because every request checks its session is still active.

Owner-scoped notes

Create, search, filter, pin, archive and soft-delete, with every query bound to the owner, so another user's note is simply not found.

Tested on a real database

Unit and end-to-end tests, type-aware linting and a type check run in CI against MySQL 8.4 on every push.

Built with

  • NestJS
  • TypeScript
  • Prisma
  • MySQL
  • Vitest

View the code on GitHub