This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
DiceBear API is a Fastify-based HTTP API for generating avatars. It serves multiple versions of the DiceBear library (5.x through 9.x) simultaneously, enabling backwards compatibility for consumers.
# Development (builds fonts, then runs with hot reload)
npm run dev
# Build for production
npm run build
# Start production server (requires build first)
npm start
# Run tests (requires build first)
npm test
# Run a single test file
node --test tests/http.test.jsThe API uses npm workspaces to maintain multiple DiceBear library versions side-by-side:
versions/5.x/throughversions/9.x/- Each contains a package.json that pins specific@dicebear/coreand@dicebear/collectionversions- Versions are loaded dynamically via
src/utils/versions.tsbased on theVERSIONSenv var - Routes are prefixed by version:
/:version/:style/:format(e.g.,/9.x/avataaars/svg)
src/routes/version.ts → Registers routes for each enabled version
src/routes/collection.ts → Registers routes for each avatar style in a version
src/routes/style.ts → Defines the actual endpoints (/:format, /:format/:options, /schema.json)
- Request hits
/:version/:style/:formator/:version/:style/:format/:options - Query string parsing via
src/utils/query-string.ts(supports both?key=valueand path-based/key=value) - Options validated against combined JSON Schema from core + style
src/handler/avatar.tscreates avatar using the appropriate DiceBear version- Format conversion (PNG, JPEG, WebP, AVIF) via
@dicebear/converter
scripts/build-fonts.ts- Pre-build script that extracts TTF fonts from @fontsource packages- Fonts are used for rendering text in raster formats (initials style, etc.)
- Font selection based on Unicode ranges in
fonts/fonts.json
All configuration is via environment variables (see src/config.ts):
PORT,HOST,WORKERS- Server settingsVERSIONS- Comma-separated list of versions to enable (default: 5,6,7,8,9)PNG,JPEG,WEBP,AVIF,JSON- Enable/disable output formats (0/1)*_SIZE_MIN,*_SIZE_MAX,*_SIZE_DEFAULT- Size constraints per format*_EXIF- Include EXIF metadata in raster formats