| title | description | version | last_updated | author | tags | audience | project | status | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
OSM Notes API |
REST API for OSM Notes Analytics and Ingestion |
0.1.0 |
2026-01-25 |
AngocA |
|
|
OSM-Notes-API |
active |
REST API for OSM Notes Analytics and Ingestion. Unified programmatic access to user profiles, country analytics, advanced search capabilities, rankings, comparisons, and real-time metrics. Extends OSM API 0.6 with specialized analytics features.
OSM Notes API provides programmatic access to OpenStreetMap notes analytics data, including:
- User Profiles: Detailed statistics of contributors
- Country Analytics: Aggregated metrics by country
- Advanced Search: Complex filters and dynamic queries
- Rankings: User and country classifications
- Comparisons: Comparative analysis between entities
- Trends: Temporal data analysis
- Notes and Comments: Access to OSM notes and their comments
This API is COMPLEMENTARY to the static JSON system, NOT a replacement.
- β JSON system maintained: The Viewer and other consumers continue using static JSON files
- β API is additional: For use cases requiring dynamic queries or integrations
- β Both coexist: Each system is used according to the specific use case
For complete installation instructions, see Installation and Dependencies Guide.
- Node.js >= 18.0.0
- npm >= 9.0.0
- PostgreSQL 15+ (with access to
osm_notes_dwhdatabase) - Redis 7+ (optional but recommended for caching and rate limiting)
- OSM-Notes-Analytics
β οΈ REQUIRED- This API reads from the Analytics data warehouse (
osm_notes_dwhdatabase) - Required schemas:
dwh(data warehouse with datamarts) - Install Analytics FIRST before installing API
- This API reads from the Analytics data warehouse (
# Clone repository
git clone https://github.com/OSM-Notes/OSM-Notes-API.git
cd OSM-Notes-API
# Install dependencies
npm install
# Configure environment variables
cp .env.example .env
# Edit .env with your configurations
# Build TypeScript
npm run build
# Load mock data (optional, for testing)
# Requires OSM-Notes-Ingestion repository cloned
./scripts/load_mock_data.sh
# Start application
npm start# Start services
docker compose -f docker/docker-compose.yml up -d
# View logs
docker compose -f docker/docker-compose.yml logs -f apiSee docs/INSTALLATION.md for detailed instructions.
Health Check:
curl -H "User-Agent: MyApp/1.0 ([email protected])" \
http://localhost:3000/healthGet a Note:
curl -H "User-Agent: MyApp/1.0 ([email protected])" \
http://localhost:3000/api/v1/notes/12345Search Notes:
curl -H "User-Agent: MyApp/1.0 ([email protected])" \
"http://localhost:3000/api/v1/notes?status=open&country=42&limit=10"Get User Profile:
curl -H "User-Agent: MyApp/1.0 ([email protected])" \
http://localhost:3000/api/v1/users/12345Get Country Profile:
curl -H "User-Agent: MyApp/1.0 ([email protected])" \
http://localhost:3000/api/v1/countries/42Get Global Analytics:
curl -H "User-Agent: MyApp/1.0 ([email protected])" \
http://localhost:3000/api/v1/analytics/globalInteractive API Documentation:
- Swagger UI:
http://localhost:3000/docs - OpenAPI JSON:
http://localhost:3000/docs/json
See docs/USAGE.md for complete usage guide.
New to this project? Follow this reading path to understand the API (~1-2 hours):
-
Start Here (15 min)
- Read this README.md (you're here!)
- Understand the project purpose and main features
- Review the Quick Start guide above
-
API Usage (30 min)
- Read docs/USAGE.md - Complete usage manual with examples
- Review docs/API.md - Complete API reference documentation
- Try the Quick Usage Examples above
-
API Documentation (15 min)
- Visit Swagger UI:
http://localhost:3000/docs(when running locally) - Review OpenAPI specification: docs/api/
- Understand authentication and rate limiting
- Visit Swagger UI:
Total time: ~1 hour for basic API usage.
-
Foundation (45 min)
- docs/ARCHITECTURE.md - System architecture (30 min)
- docs/DEVELOPMENT.md - Development guidelines (15 min)
-
Setup and Configuration (30 min)
- docs/INSTALLATION.md - Installation guide (15 min)
- docs/DATABASE_SCHEMA.md - Database requirements (15 min)
-
Testing and Quality (30 min)
- docs/TESTING.md - Testing documentation (20 min)
- CONTRIBUTING.md - Contribution guidelines (10 min)
-
Deep Dive (as needed)
- docs/PERFORMANCE.md - Performance optimization
- docs/MONITORING.md - Monitoring setup
- docs/adr/ - Architecture Decision Records
Total time: ~2 hours for complete developer overview.
-
Deployment (1 hour)
- docs/INSTALLATION.md - Installation guide (20 min)
- docs/DEPLOYMENT.md - Production deployment (20 min)
- docs/DEPLOYMENT_PRODUCTION.md - Specific production guide (20 min)
-
Operations (45 min)
- docs/RUNBOOK.md - Operations runbook (20 min)
- docs/MONITORING.md - Monitoring setup (15 min)
- docs/TROUBLESHOOTING.md - Common issues (10 min)
-
Compliance and Operations (30 min)
- docs/operations/DISASTER_RECOVERY.md - Disaster recovery
- docs/operations/BACKUP_STRATEGY.md - Backup procedures
- docs/SLA.md - Service Level Agreements
Total time: ~2.5 hours for complete operations overview.
Main entry points for using and operating the API:
-
Start the API Server
npm start # Production mode (requires build first) npm run dev # Development mode with hot reload
-
Docker Entry Points
# Start all services (API + PostgreSQL + Redis) docker compose -f docker/docker-compose.yml up -d # Start with monitoring (Prometheus + Grafana) docker compose -f docker/docker-compose.yml --profile monitoring up -d
Base URL: http://localhost:3000 (default)
- Health Check:
GET /health- Service health status - API Documentation:
GET /docs- Swagger UI interactive documentation - OpenAPI Spec:
GET /docs/json- OpenAPI JSON specification
Main API Endpoints:
GET /api/v1/users/:id- Get user profileGET /api/v1/countries/:id- Get country profileGET /api/v1/notes- Search notesGET /api/v1/notes/:id- Get specific noteGET /api/v1/analytics/global- Global analytics
See docs/API.md for complete API reference.
-
Build and Type Check
npm run build # Compile TypeScript npm run type-check # Verify types without building
-
Testing
npm test # Run all tests (master test command) npm run test:unit # Unit tests only npm run test:integration # Integration tests only
Master Test Command:
npm test- Executes all tests using Jest -
Code Quality
npm run lint # Check code style npm run format # Format code
-
Health Monitoring
curl http://localhost:3000/health
-
View Logs
# Docker docker compose -f docker/docker-compose.yml logs -f api # PM2 pm2 logs osm-notes-api
-
Restart Service
# Docker docker compose -f docker/docker-compose.yml restart api # PM2 pm2 restart osm-notes-api
See docs/RUNBOOK.md for complete operations procedures.
- Installation - Complete installation guide
- Usage - API usage manual with examples
- API Reference - Complete API reference documentation
- API Reference (OpenAPI) - OpenAPI/Swagger documentation
- Deployment Guide - Production deployment instructions
- Production Deployment (192.168.0.7) - Specific guide for production server
- Operations Runbook - Operational procedures and runbook
- Troubleshooting - Common issues and solutions
- CI/CD Guide - Continuous Integration and Deployment
- Performance Guide - Performance optimization and benchmarking
- SLA/SLOs - Service Level Agreements and Objectives
- Monitoring Guide - Prometheus and Grafana setup
- Disaster Recovery - Disaster recovery procedures
- Backup Strategy - Backup and restore procedures
- Capacity Planning - Capacity planning guide
- Terms of Service - API terms of service
- Privacy Policy - Privacy policy (GDPR compliant)
- Database Schema - Database schema and data requirements
- Database User Setup - Create read-only database user
- Redis Setup (Optional) - Redis configuration (optional but recommended)
- Redis Troubleshooting - Fix Redis connection issues
- Testing Guide - Testing documentation
- Security Testing - OWASP ZAP security testing guide
- Development Guide - Development guidelines
- Contributing - Contributor guide
- Architecture Decision Records - ADRs documenting technical decisions
- Changelog - Change history
- API Versioning - API versioning strategy
OSM-Notes-API/
βββ src/ # Source code
β βββ config/ # Configuration
β βββ routes/ # API routes
β βββ controllers/ # Controllers
β βββ services/ # Business logic
β βββ middleware/ # Custom middleware
β βββ utils/ # Utilities
β βββ types/ # TypeScript types
βββ tests/ # Tests
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ load/ # Load tests
βββ docs/ # Documentation
β βββ INSTALLATION.md # Installation manual
β βββ USAGE.md # Usage manual
β βββ api/ # OpenAPI documentation
βββ docker/ # Docker configuration
βββ package.json # Dependencies and scripts
npm run build # Build TypeScript
npm start # Run compiled application
npm run dev # Development with hot reload
npm run type-check # Verify TypeScript typesnpm test # Run all tests
npm run test:unit # Unit tests only
npm run test:integration # Integration tests only
npm run test:coverage # Tests with coverage report
npm run test:watch # Run tests in watch mode
npm run test:light # Run unit tests with 1 worker (for performance)
npm run test:integration:single # Run integration tests sequentiallynpm run lint # Run ESLint
npm run lint:fix # Fix ESLint errors automatically
npm run format # Format code with Prettier
npm run format:check # Check code formatting# Run performance benchmarks
./scripts/run_benchmarks.sh
# Create database indexes
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -f scripts/create_indexes.sql
# Analyze query performance
psql -h $DB_HOST -U $DB_USER -d $DB_NAME -f scripts/analyze_queries.sql# Install k6 first (see tests/load/README.md)
k6 run tests/load/users.js
k6 run tests/load/notes.js
k6 run tests/load/analytics.js
k6 run tests/load/all-endpoints.js- User-Agent required: All requests must include a valid User-Agent with format
AppName/Version (Contact) - Rate Limiting: 50 requests/15min for anonymous users, 1000 req/hour for authenticated
- Anti-abuse protection: Automatic blocking of known AIs and bots without OAuth
- Security headers: Helmet.js configured with security best practices
- Input validation: All inputs validated with Joi schemas
- Optional OAuth: Available for advanced features (Phase 5)
See docs/USAGE.md and docs/security/ for more security details.
- Prometheus Metrics: Available at
/metricsendpoint - Grafana Dashboards: Pre-configured dashboards for:
- Request rate and latency (P50, P95, P99)
- Error rates by endpoint
- Rate limiting events
- User-Agent statistics
- Health Checks:
/healthendpoint with database and Redis status - Structured Logging: JSON logs with Winston
- Alerting: Prometheus alerts configured for:
- High error rates
- High latency
- Frequent rate limiting
- Service downtime
See docs/MONITORING.md for monitoring setup.
- Response Times:
- Simple endpoints (datamarts): P95 < 500ms
- Complex analytics: P95 < 2000ms
- Caching: Redis-based response caching with configurable TTL
- Database Optimization:
- Indexes created via
scripts/create_indexes.sql - Query analysis via
scripts/analyze_queries.sql
- Indexes created via
- Benchmarks: Performance benchmarks script available (
scripts/run_benchmarks.sh)
See docs/PERFORMANCE.md for performance optimization guide.
Version: 0.1.0 (Production Ready - Phases 1-4 Complete)
Test Coverage: 87.54% statements, 93.93% branches, 87.56% functions
- β 224+ tests passing (100% pass rate)
- β 25+ test suites passing
- β Unit tests: 100% pass rate
- β Integration tests: 100% pass rate
- β CI/CD pipeline configured with GitHub Actions
- β Load testing scripts (k6) available
Implementation Phases:
-
β Phase 1: MVP (Core endpoints, basic features, documentation)
- β Notes endpoints (get, search, comments)
- β User profiles endpoint
- β Country profiles endpoint
- β Global analytics endpoint
- β User-Agent validation
- β Rate limiting
- β Anti-abuse protection
- β OpenAPI/Swagger documentation
- β Comprehensive integration tests
- β Test database configuration
-
β Phase 2: Basic Features (Rankings, search, caching)
- β User and country rankings
- β Basic search functionality
- β Pagination support
- β Redis caching implementation
- β Prometheus metrics
-
β Phase 3: Advanced Features (Advanced search, monitoring)
- β Advanced search with multiple filters
- β Hashtags endpoints
- β Analytics comparisons
- β Trends analysis
- β Grafana dashboards
- β Prometheus alerts
- β Load testing scripts (k6)
-
β Phase 4: Production (Documentation, operations, compliance)
- β CI/CD pipeline configured
- β Complete documentation (installation, usage, API reference)
- β Operations runbook
- β Disaster recovery plan
- β Backup strategy
- β Capacity planning
- β SLA/SLOs defined
- β Legal documentation (Terms of Service, Privacy Policy)
- β Performance benchmarks
- β Performance optimization scripts
-
β³ Phase 5: Webhooks and Notifications (Future - if needed)
- β³ Webhook system
- β³ Event subscriptions
- β³ OAuth integration
Contributions are welcome. Please read CONTRIBUTING.md for details on our code of conduct and pull request process.
Important: This API processes and serves data that may contain personal information from OpenStreetMap, including usernames and geographic locations. We are committed to GDPR compliance.
This API has its own Privacy Policy that covers API-specific GDPR compliance. Additionally, GDPR compliance mechanisms are fully implemented in the base project OSM-Notes-Ingestion. For comprehensive GDPR documentation, including detailed procedures and SQL scripts for handling data subject requests, please refer to:
- GDPR Privacy Policy: OSM-Notes-Ingestion/docs/GDPR_Privacy_Policy.md
- GDPR Procedures: OSM-Notes-Ingestion/docs/GDPR_Procedures.md - Detailed procedures for handling data subject requests
- GDPR SQL Scripts: OSM-Notes-Ingestion/sql/gdpr/README.md - SQL scripts to handle GDPR requests
This API reads data from OSM-Notes-Analytics (which originates from OSM-Notes-Ingestion) and is subject to the same GDPR compliance measures.
This project is licensed under the GNU General Public License v3.0 - see LICENSE for details.
For shared documentation of the complete ecosystem, see:
- OSM Notes Ecosystem - Ecosystem landing page
- Global Glossary - Terms and definitions
- Complete Installation Guide - Step-by-step installation of all projects
- End-to-End Data Flow - Complete data flow
- Decision Guide - Which project do I need?
This API project is part of the OSM-Notes ecosystem, consisting of 8 interconnected projects. OSM-Notes-Ingestion is the base project - it was the first created and provides the foundation for all others.
-
OSM-Notes-Ingestion - Base project
- Downloads and synchronizes OSM notes from Planet and API
- Populates base PostgreSQL tables
- First project created, foundation for all others
-
- ETL processes and data warehouse
- Generates analytics and datamarts
- Requires: OSM-Notes-Ingestion (reads from base tables)
- This API reads from: Analytics data warehouse (
osm_notes_dwh)
-
OSM-Notes-API (this project)
- REST API for programmatic access
- Provides dynamic queries and advanced features
- Requires: OSM-Notes-Analytics (reads from data warehouse)
- Complementary to: Static JSON system (OSM-Notes-Data)
-
- Web application for interactive visualization
- Consumes JSON data from OSM-Notes-Data (GitHub Pages)
- Requires: OSM-Notes-Data (which is generated by OSM-Notes-Analytics)
- Alternative: Can also use this API for dynamic queries
-
- Web Map Service for geographic visualization
- Publishes WMS layers for mapping applications
- Requires: OSM-Notes-Ingestion (uses same database)
-
- Centralized monitoring and alerting
- Monitors all ecosystem components including this API
- Requires: Access to all other projects' databases/services
-
- Shared Bash libraries and utilities
- Used as Git submodule by multiple projects
- Used by: Ingestion, Analytics, WMS, Monitoring
- Note: This API project (Node.js/TypeScript) does not use Common
-
- JSON data files exported from Analytics
- Served via GitHub Pages
- Requires: OSM-Notes-Analytics (generates and publishes the data)
- Consumed by: Viewer (primary consumer), API (optional - can use Analytics DWH directly)
graph TB
subgraph External["External Sources"]
OSM[OSM Planet/API]
end
subgraph Base["Base Project"]
INGESTION[OSM-Notes-Ingestion<br/>Base project]
end
subgraph Processing["Processing Layer"]
ANALYTICS[OSM-Notes-Analytics<br/>ETL β Data Warehouse]
WMS[OSM-Notes-WMS<br/>WMS layers]
end
subgraph Delivery["Delivery Layer"]
DATA[OSM-Notes-Data<br/>JSON files<br/>GitHub Pages]
API[OSM-Notes-API<br/>REST API<br/>this project<br/>reads from Analytics DWH]
VIEWER[OSM-Notes-Viewer<br/>Consumes JSON from Data]
end
subgraph Support["Support Layer"]
MONITORING[OSM-Notes-Monitoring<br/>Monitors all projects<br/>including this API]
COMMON[OSM-Notes-Common<br/>Shared libraries<br/>submodule<br/>not used by this API]
end
OSM -->|Downloads| INGESTION
INGESTION -->|Base Tables| ANALYTICS
INGESTION -->|Same Database| WMS
ANALYTICS -->|JSON Export| DATA
ANALYTICS -->|Data Warehouse| API
DATA -->|JSON Files| VIEWER
MONITORING -.->|Monitors| INGESTION
MONITORING -.->|Monitors| ANALYTICS
MONITORING -.->|Monitors| API
COMMON -.->|Used by| INGESTION
COMMON -.->|Used by| ANALYTICS
COMMON -.->|Used by| WMS
COMMON -.->|Used by| MONITORING
style OSM fill:#ADD8E6
style INGESTION fill:#90EE90
style ANALYTICS fill:#FFFFE0
style WMS fill:#FFE4B5
style DATA fill:#E0F6FF
style API fill:#FFB6C1
style VIEWER fill:#DDA0DD
style MONITORING fill:#F0E68C
style COMMON fill:#D3D3D3
When setting up the complete ecosystem, install projects in this order:
- OSM-Notes-Ingestion - Install first (base project)
- OSM-Notes-Analytics - Requires Ingestion
- OSM-Notes-WMS - Requires Ingestion
- OSM-Notes-Data - Requires Analytics (auto-generated by Analytics export script)
- OSM-Notes-Viewer - Requires Data (consumes JSON from GitHub Pages)
- OSM-Notes-API (this project) - Requires Analytics (reads from Analytics data warehouse)
- OSM-Notes-Monitoring - Requires all others (monitors them)
- OSM-Notes-Common - Used as submodule (no installation needed, not used by this API)
This API is complementary to the static JSON system:
- Static JSON (OSM-Notes-Data): Pre-computed, fast, served via GitHub Pages
- Used by: Viewer (primary), simple integrations
- Advantages: No server needed, fast loading, CDN-ready
- REST API (this project): Dynamic queries, real-time data, advanced features
- Used by: Applications requiring dynamic queries, integrations, real-time data
- Advantages: Flexible queries, filtering, sorting, pagination, real-time updates
Both systems coexist and serve different use cases.
- OpenStreetMap: https://www.openstreetmap.org
For questions or support, please open an issue on GitHub.
Note: This project is part of the OSM Notes ecosystem and is designed to work together with the other projects in the ecosystem.