This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Node.js IP geolocation service that provides offline IP lookups using MaxMind's GeoLite2 database. The service prioritizes Cloudflare geolocation headers when available and falls back to local database queries.
npm run dev- Start development server with ts-node (port 7755)npm run build- Compile TypeScript to JavaScriptnpm start- Build and start production server (port 7755)npm run typecheck- Run TypeScript type checking without compilationnpm run download-db- Download/update MaxMind GeoLite2 databasenpm run setup- Full setup (install dependencies + download database)npm run clean- Remove compiled JavaScript files
./start.sh- Startup script with dependency checking./start-prod.sh- Production startup (assumes dependencies installed)
docker-compose up -d- Start containerized servicedocker-compose logs -f- View container logsdocker-compose down- Stop service
-
src/server.ts - Main TypeScript application with three key subsystems:
- Database initialization: Auto-downloads GeoLite2 database on first run
- IP detection: Multi-source client IP extraction (Cloudflare, X-Forwarded-For, etc.)
- Geolocation resolution: Cloudflare headers take priority over local MaxMind lookups
-
src/download-db.ts - Standalone database downloader with redirect handling
-
TypeScript Configuration:
- tsconfig.json: Strict TypeScript configuration with ES2020 target
- dist/: Compiled JavaScript output directory (excluded from git)
- Type safety: Full type coverage for MaxMind API and Express routes
- Node.js: Requires Node.js 22+ (latest LTS)
- Fallback hierarchy: Cloudflare headers → MaxMind database → error
- Auto-provisioning: Database downloads automatically if missing
- EU detection: Hardcoded EU country list for GDPR compliance flag
- Error boundaries: Graceful degradation with meaningful error messages
GET /ip- Client IP geolocation (uses request headers for IP detection)GET /ip/:address- Specific IP lookup with IPv4 validationGET /health- Health check endpoint
- PORT: Server port (default: 7755)
- NODE_ENV: Environment mode (affects Docker behavior)
- Path:
./data/GeoLite2-City.mmdb - Source: GitHub mirror (P3TERX/GeoLite.mmdb)
- Auto-download: Triggered on server startup if missing
- Size: ~58MB
The service is containerized with:
- Health checks via
/healthendpoint - Volume mounting for database persistence
- Production-optimized Alpine Node.js base image