Skip to content

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.

License

Notifications You must be signed in to change notification settings

OSM-Notes/OSM-Notes-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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
api
rest
nodejs
developers
api-consumers
OSM-Notes-API
active

OSM Notes API

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.

πŸ“‹ Description

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

⚠️ Important Note

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

Requirements

For complete installation instructions, see Installation and Dependencies Guide.

Application Requirements

  • Node.js >= 18.0.0
  • npm >= 9.0.0
  • PostgreSQL 15+ (with access to osm_notes_dwh database)
  • Redis 7+ (optional but recommended for caching and rate limiting)

Internal Repository Requirements

  • OSM-Notes-Analytics ⚠️ REQUIRED
    • This API reads from the Analytics data warehouse (osm_notes_dwh database)
    • Required schemas: dwh (data warehouse with datamarts)
    • Install Analytics FIRST before installing API

πŸš€ Quick Start

Installation

# 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

With Docker

# Start services
docker compose -f docker/docker-compose.yml up -d

# View logs
docker compose -f docker/docker-compose.yml logs -f api

See docs/INSTALLATION.md for detailed instructions.

Quick Usage Examples

Health Check:

curl -H "User-Agent: MyApp/1.0 ([email protected])" \
     http://localhost:3000/health

Get a Note:

curl -H "User-Agent: MyApp/1.0 ([email protected])" \
     http://localhost:3000/api/v1/notes/12345

Search 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/12345

Get Country Profile:

curl -H "User-Agent: MyApp/1.0 ([email protected])" \
     http://localhost:3000/api/v1/countries/42

Get Global Analytics:

curl -H "User-Agent: MyApp/1.0 ([email protected])" \
     http://localhost:3000/api/v1/analytics/global

Interactive API Documentation:

  • Swagger UI: http://localhost:3000/docs
  • OpenAPI JSON: http://localhost:3000/docs/json

See docs/USAGE.md for complete usage guide.

Recommended Reading Path

New to this project? Follow this reading path to understand the API (~1-2 hours):

For API Consumers

  1. Start Here (15 min)

    • Read this README.md (you're here!)
    • Understand the project purpose and main features
    • Review the Quick Start guide above
  2. 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
  3. API Documentation (15 min)

    • Visit Swagger UI: http://localhost:3000/docs (when running locally)
    • Review OpenAPI specification: docs/api/
    • Understand authentication and rate limiting

Total time: ~1 hour for basic API usage.

For Developers

  1. Foundation (45 min)

  2. Setup and Configuration (30 min)

  3. Testing and Quality (30 min)

  4. Deep Dive (as needed)

Total time: ~2 hours for complete developer overview.

For System Administrators

  1. Deployment (1 hour)

  2. Operations (45 min)

  3. Compliance and Operations (30 min)

Total time: ~2.5 hours for complete operations overview.

Entry Points

Main entry points for using and operating the API:

Application Entry Points

  1. Start the API Server

    npm start              # Production mode (requires build first)
    npm run dev            # Development mode with hot reload
  2. 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

API Endpoints (HTTP Entry Points)

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 profile
  • GET /api/v1/countries/:id - Get country profile
  • GET /api/v1/notes - Search notes
  • GET /api/v1/notes/:id - Get specific note
  • GET /api/v1/analytics/global - Global analytics

See docs/API.md for complete API reference.

Development Entry Points

  1. Build and Type Check

    npm run build          # Compile TypeScript
    npm run type-check     # Verify types without building
  2. 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

  3. Code Quality

    npm run lint           # Check code style
    npm run format         # Format code

Operations Entry Points

  1. Health Monitoring

    curl http://localhost:3000/health
  2. View Logs

    # Docker
    docker compose -f docker/docker-compose.yml logs -f api
    
    # PM2
    pm2 logs osm-notes-api
  3. 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.

πŸ“š Documentation

Getting Started

Operations & Deployment

Performance & Monitoring

Operations & Compliance

Development

Reference

πŸ—οΈ Project Structure

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

πŸ› οΈ Available Scripts

Development

npm run build          # Build TypeScript
npm start              # Run compiled application
npm run dev            # Development with hot reload
npm run type-check     # Verify TypeScript types

Testing

npm 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 sequentially

Code Quality

npm 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

Performance & Database

# 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

Load Testing (requires k6)

# 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

πŸ”’ Security

  • 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.

πŸ“ˆ Monitoring & Observability

  • Prometheus Metrics: Available at /metrics endpoint
  • 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: /health endpoint 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.

⚑ Performance

  • 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
  • Benchmarks: Performance benchmarks script available (scripts/run_benchmarks.sh)

See docs/PERFORMANCE.md for performance optimization guide.

πŸ“Š Project Status

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

🀝 Contributing

Contributions are welcome. Please read CONTRIBUTING.md for details on our code of conduct and pull request process.

GDPR Compliance

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:

This API reads data from OSM-Notes-Analytics (which originates from OSM-Notes-Ingestion) and is subject to the same GDPR compliance measures.

πŸ“ License

This project is licensed under the GNU General Public License v3.0 - see LICENSE for details.

πŸ“š Ecosystem Documentation

For shared documentation of the complete ecosystem, see:


🌐 OSM-Notes Ecosystem

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.

Ecosystem Projects

  1. 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
  2. OSM-Notes-Analytics

    • 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)
  3. 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)
  4. OSM-Notes-Viewer

    • 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
  5. OSM-Notes-WMS

    • Web Map Service for geographic visualization
    • Publishes WMS layers for mapping applications
    • Requires: OSM-Notes-Ingestion (uses same database)
  6. OSM-Notes-Monitoring

    • Centralized monitoring and alerting
    • Monitors all ecosystem components including this API
    • Requires: Access to all other projects' databases/services
  7. OSM-Notes-Common

    • 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
  8. OSM-Notes-Data

    • 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)

Project Relationships

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
Loading

Installation Order

When setting up the complete ecosystem, install projects in this order:

  1. OSM-Notes-Ingestion - Install first (base project)
  2. OSM-Notes-Analytics - Requires Ingestion
  3. OSM-Notes-WMS - Requires Ingestion
  4. OSM-Notes-Data - Requires Analytics (auto-generated by Analytics export script)
  5. OSM-Notes-Viewer - Requires Data (consumes JSON from GitHub Pages)
  6. OSM-Notes-API (this project) - Requires Analytics (reads from Analytics data warehouse)
  7. OSM-Notes-Monitoring - Requires all others (monitors them)
  8. OSM-Notes-Common - Used as submodule (no installation needed, not used by this API)

API vs Static JSON

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.

External Resources

πŸ“§ Contact

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.

About

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.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published