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

Β 

History

83 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

πŸš€ Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • npm >= 9.0.0
  • PostgreSQL 15+ (with access to osm_notes_dwh)
  • Redis 7+ (optional but recommended)

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 (contact@example.com)" \
     http://localhost:3000/health

Get a Note:

curl -H "User-Agent: MyApp/1.0 (contact@example.com)" \
     http://localhost:3000/api/v1/notes/12345

Search Notes:

curl -H "User-Agent: MyApp/1.0 (contact@example.com)" \
     "http://localhost:3000/api/v1/notes?status=open&country=42&limit=10"

Get User Profile:

curl -H "User-Agent: MyApp/1.0 (contact@example.com)" \
     http://localhost:3000/api/v1/users/12345

Get Country Profile:

curl -H "User-Agent: MyApp/1.0 (contact@example.com)" \
     http://localhost:3000/api/v1/countries/42

Get Global Analytics:

curl -H "User-Agent: MyApp/1.0 (contact@example.com)" \
     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.

πŸ“š 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.

πŸ“ License

This project is licensed under the MIT License - see LICENSE for details.

πŸ”— Related Links

πŸ“§ 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