MechaCat02 1883356d7d feat: pg_trgm search, sort options, populated total count
Backend:
- Migration 0005_search.sql enables pg_trgm and adds GIN indexes
  (gin_trgm_ops) on mangas.title and on mangas.author (partial, WHERE
  author IS NOT NULL).
- repo::manga::list keeps the existing substring (ILIKE) clause and
  adds the `%` operator on title + author so the search tolerates typos
  ('narto' → 'Naruto'). Both branches share the trgm index. A second
  count(*) query (same WHERE clause, indexed) yields the total without
  scanning twice in any meaningful sense.
- New ListSort enum (Recent / Title) interpolated into ORDER BY from a
  hard-coded match — never from request input, so the format!() is not
  a SQL-injection seam. Default stays Recent (created_at DESC).
- api::mangas accepts `?sort=recent|title` (snake_case) via serde and
  returns `page.total` as a number instead of null.
- api::pagination::PagedResponse gains a `with_total` constructor.

Backend coverage in tests/api_mangas.rs (4 new cases plus the existing
list_is_empty_initially updated to assert total: 0):
- list_returns_total_count_independent_of_pagination — limit=2 with 3
  rows returns 2 items and total=3.
- search_via_trigram_tolerates_typos — `?search=narto` finds Naruto.
- list_sort_title_orders_alphabetically — three out-of-order inserts
  come back A→Z.
- search_reflects_filtered_total — search narrows total to 1.

Frontend:
- lib/api/mangas.ts gains a `MangaSort` type and threads `sort` through
  listMangas's query-string builder.
- Home page renders a "Sort" select (Recent / Title A→Z) that re-runs
  the list query, and shows "Showing N of M" when total is present.

Lockstep version bump to 0.8.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 22:46:16 +02:00
2026-05-16 21:05:16 +02:00
2026-05-16 21:05:16 +02:00
2026-05-16 21:05:16 +02:00
2026-05-16 21:05:16 +02:00
2026-05-16 21:05:16 +02:00

Mangalord

A self-hosted manga and comics reader. Browse, search, read, bookmark, and upload manga and chapters. The HTTP API is consumed by both the SvelteKit web UI and external bots/scripts that perform the same actions programmatically.

Stack

  • Backend: Rust, axum, sqlx
  • Database: Postgres 16
  • Frontend: SvelteKit 2 (Svelte 5 runes), TypeScript, Vite
  • File storage: pluggable Storage trait — local FS today, S3 (and friends) as future impls
  • Deploy: Docker Compose on a single server

Quick start

cp .env.example .env
docker compose up --build

Local development

Run only Postgres in Docker; run backend and frontend natively for fast iteration:

docker compose -f docker-compose.dev.yml up -d

# backend
cd backend
export DATABASE_URL=postgres://mangalord:mangalord@localhost:5432/mangalord
cargo run

# frontend (separate shell)
cd frontend
npm install
npm run dev

The Vite dev server proxies /api to http://localhost:8080.

Tests

This project is developed test-first. Tests live at three levels:

# Backend: unit (in-module) + integration (tests/, per-test DB via #[sqlx::test])
cd backend && cargo test

# Frontend: unit / module tests (Vitest)
cd frontend && npm test

# Frontend: end-to-end (Playwright; spins up dev server, mocks API by default)
cd frontend && npm run test:e2e

API surface

Method Path Purpose
GET /api/health Liveness
GET /api/mangas List / search mangas
POST /api/mangas Create a manga
GET /api/mangas/{id} Get a manga
GET /api/files/{key} Stream a blob (cover, chapter page)

Chapters, uploads, and bookmarks are next — the patterns to extend are documented in CLAUDE.md.

Description
No description provided
Readme 702 KiB
Languages
Rust 59.1%
Svelte 21.9%
TypeScript 18.1%
CSS 0.6%
Dockerfile 0.2%
Other 0.1%