This file serves as the primary context source for AI agents (Claude, Gemini, GPT) working on this repository.
Project: node-csfd-api
Description: A TypeScript wrapper and scraper for CSFD.cz (Czecho-Slovak Film Database). It exposes data via a Node.js API and a Model Context Protocol (MCP) server for AI consumption.
Core Stack: TypeScript, Node.js, node-html-parser, Zod, Express.
The project is divided into layers. Do not mix concerns.
-
Core Scraper (
src/):- Fetchers (
src/fetchers): Handles HTTP requests, User-Agents, and cookies. - Helpers (
src/helpers): CRITICAL. Pure functions that take HTML Elements and return raw data strings/objects. - Services (
src/services): Orchestrators. They call Fetchers, then use Helpers to parse data, and return typed DTOs. - DTOs (
src/dto): TypeScript interfaces defining the shape of the data.
- Fetchers (
-
MCP Server (
mcp-server/):- The AI interfacing layer. It wraps
src/servicesinto tools executable by LLMs. - See
.ai/MCP_ARCH.mdfor specific rules.
- The AI interfacing layer. It wraps
-
App Server (
server/):- A classic Express/Node server exposing the scraper as a REST API.
- Never put CSS selectors directly in Service classes. Always wrap them in a Helper function in
src/helpers. - Never assume an element exists. CSFD changes layouts. Use optional chaining
?.ortry/catchinside helpers. - See
.ai/SCRAPING.mdfor the parsing strategy.
- Use standard ES imports.
- When importing local files, use the
.jsextension in imports where necessary for ESM compatibility (e.g.,import { x } from './file.js'), but follow the existing pattern in the file you are editing.
- Use
vitest. - Prefer integration tests against live CSFD for critical paths (or use recorded mocks if available).
- Run
npm run demoto verify basic functionality quickly.
Task: Add a new field to Movie object
- Update Interface in
src/dto/movie.ts. - Create a helper in
src/helpers/movie.helper.ts. - Update logic in
src/services/movie.service.ts. - Verify
mcp-serverexposes it (it usually does automatically via the service).
Task: Add a new MCP Tool
- See
.ai/MCP_ARCH.md.
- Build everything:
yarn build - Build Server:
yarn build:server - Build MCP:
yarn build:mcp - Bundler: The project uses
tsdownandesbuild.