Skip to content

Repository files navigation

📚 Public Domain Library API (NestJS)

Backend API for searching public domain books with pagination, full-text filtering, and production-ready deployment using Docker + CI/CD.


🚀 Live Demo


🧱 Tech Stack

  • NestJS (TypeScript)
  • Prisma ORM
  • PostgreSQL (Aiven)
  • Swagger (OpenAPI)
  • Docker
  • GitHub Actions (CI/CD)
  • Docker Hub (image registry)
  • Render (deployment)

⚙️ Environment Variables

These are required in production:

DATABASE_URL=your_postgres_connection  
APP_URL=https://your-render-url.onrender.com  
FRONTEND_URL=https://your-frontend.vercel.app  
PORT=3000

📡 API Endpoints

Health Check

GET /health

Response:

{
  "status": "up"
}

Get Books

GET /books

Query Params

  • search (string): Search in title + authors
  • page (number, default=1)
  • size (number, default=20)

Example Request

GET /books?search=tolstoy&page=1&size=20

Example Response

{
  "items": [
    {
      "id": 2487,
      "title": "War and Peace",
      "authors": "Tolstoy, Leo, graf; Maude, Aylmer; Maude, Louise",
      "subjects": "Historical fiction; War stories..."
    }
  ],
  "total": 4,
  "page": 1,
  "size": 20,
  "pages": 1
}

🔍 Search Behavior

  • Case-insensitive
  • Tokenized search ("fairy tales" → ["fairy", "tales"])
  • Matches title and authors
  • Uses AND across tokens

📊 Logging (Production)

Example:

GET /books search="fairy tales" page=5 size=20 results=20 total=103

Visible in Render logs.


🔁 Self-Ping (Render Keep-Alive)

  • Runs every 10 minutes
  • Calls /health
  • Requires APP_URL

🐳 Docker

Image:

carlosm1/public-domain-library-nestjs-api:latest

⚙️ CI/CD Pipeline

On push to main:

  • Build Docker image
  • Push to Docker Hub
  • Trigger Render deploy

🧪 Local Development

npm install  
npm run start:dev

http://localhost:3000  
http://localhost:3000/api

📁 Project Structure

src/
  modules/
    books/
    health/
  prisma/
  self-ping.service.ts
  app.module.ts
  main.ts

About

NestJS backend API for searching and browsing English-language public domain books

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages