Skip to content

Repository files navigation

FlyRank BE Task 2 - CRUD with SQLite3

FlyRank BE Task 2 is a production-styled Express.js REST API built for the FlyRank Backend AI Engineering internship (BE-02). It continues directly from BE-01/Task 1's in-memory CRUD by replacing the storage layer with a persistent SQLite-compatible database, while keeping the API contract identical — proving persistence is an implementation detail behind the API, not a change to the API itself.


Architecture

FlyRank BE Task 2 follows a Layered MVC-style Architecture, separating routing, business logic, middleware, and data access for clarity and maintainability.

LayerResponsibility
RoutesDefines and maps API endpoints to controllers
ControllersHandles request logic, validation, and shapes responses
MiddlewareLogging, rate limiting, error handling, security
DataPersistent SQLite-compatible database (Turso / libSQL)
UtilsResponse formatting

API Design

The API follows REST conventions with consistent JSON envelopes for every response and standard HTTP status codes for success and failure states. Data is persisted in a real database instead of memory, so it survives restarts and redeploys.


Features

Core Endpoints

MethodEndpointDescription
GET/tasksList tasks — filterable by search, done, sortable by title
GET/tasks/:idFetch a single task by id
POST/tasksCreate a new task
PUT/tasks/:idUpdate a task's title and/or completion status
DELETE/tasks/:idDelete a task
GET/statsTotal, completed, and pending task counts

Engineering & Reliability

CapabilityDescription
Persistent StorageSQLite-compatible database (Turso/libSQL) — data survives restarts and redeploys
Search & Filter?search= (title match) and ?done=true/false
Sorting?sort=title for alphabetical ordering
Stats EndpointAggregate counts computed via SQL COUNT()
Timestampscreated_at and updated_at tracked per row
Auto-SeedExample tasks inserted only on first run
Security HeadersHelmet-based HTTP header hardening
CORS ControlCross-origin requests enabled
Rate LimitingIP-based request throttling with custom JSON error responses
Centralized Error HandlingSingle source of truth for error formatting and logging
Structured LoggingPer-request method, path, status, and latency logging
Graceful ShutdownClean process termination on SIGINT/SIGTERM with forced timeout
Automated TestingJest + Supertest coverage for all endpoints and edge cases (13 passing tests)
ContainerizedDockerfile included for portable deployment
Live Demo UIClick-to-run endpoint cards rendering real JSON

Workflow

Client Request
↓
Security & CORS Middleware
↓
Request Logger
↓
Rate Limiter
↓
Route → Controller
↓
Database Query (Turso / libSQL)
↓
Structured JSON Response
↓
Centralized Error Handler (on failure)

Tech Stack

LayerTechnology
RuntimeNode.js
FrameworkExpress.js 5
DatabaseSQLite-compatible, hosted via Turso (libSQL)
SecurityHelmet, CORS
PerformanceCompression
Reliabilityexpress-rate-limit
TestingJest, Supertest
ContainerizationDocker

Testing

npm test

All 13 tests run against an in-memory database and pass independently of the hosted Turso instance.


A Note on Persistence

Data is stored in a hosted, SQLite-compatible database (Turso/libSQL) rather than a local .db file. This choice was made specifically to support deployment on serverless platforms (like Vercel), whose functions run on a read-only, ephemeral filesystem and cannot persist a local SQLite file across invocations. The schema, SQL, and API contract remain fully SQLite-compatible.


Live Demo

https://fly-rank-be-task2.vercel.app/


Creator & Developer

Muhammad Ashhadullah Zaheer

LinkedIn: https://www.linkedin.com/in/muhammad-ashhadullah-zaheer-41194a340/

About

Production-grade Express.js REST API built for the FlyRank Backend AI Engineering internship (BE-02). CRUD task API backed by SQLite-compatible Turso (libSQL), with search/filter/sort, a stats endpoint, timestamps, Helmet security, CORS, rate limiting, Jest/Supertest tests, Docker support, and a live-demo UI.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages