Skip to content

A REST API built with NestJS, TypeScript, and Neo4j that serves Philippine Government Budget Data from a Neo4j graph database. Based on data from the open-budget-data repository.

License

Notifications You must be signed in to change notification settings

alvinveroy/open-budget-api

Β 
Β 

Repository files navigation

BetterGovPH Open Budget API

A comprehensive REST API for Philippine Government Budget Data (NEP/GAA 2020-2026) built on a Neo4j graph database with full UACS dimension linking and hierarchical relationships.

🎯 Project Overview

A production-ready, open-source API for Philippine government budget transparency built with NestJS, Neo4j, and TypeScript. This API provides programmatic access to 6.8+ million budget records totaling β‚±106.9 trillion with comprehensive filtering, aggregation, year-over-year comparisons, and hierarchical analytics.

Key Features

  • βœ… Complete Budget Data: NEP/GAA records from 2020-2026
  • βœ… Hierarchical Structures: Full organizational and expense classification hierarchies
  • βœ… NEP vs GAA Comparisons: Built-in comparison analytics
  • βœ… Geographic Coverage: Regional, provincial, and municipal breakdowns
  • βœ… UACS Compliant: Following Unified Accounts Code Structure standards
  • βœ… Graph Database: Complex relationship queries via Neo4j
  • βœ… REST API: Clean, well-documented endpoints
  • βœ… TypeScript: Full type safety and IDE support

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • Neo4j Database 5.x with BetterGovPH budget data loaded
  • Yarn package manager

Note: The Neo4j database must be pre-populated with budget data from the open-budget-data repository. See Data Source section below.

Installation

# Clone the repository
git clone https://github.com/bettergovph/open-budget-api.git
cd open-budget-api

# Install dependencies
yarn install

# Configure environment
cp .env.example .env
# Edit .env with your Neo4j credentials and configuration

Running the Application

# Development mode (with hot reload)
yarn start:dev

# Production mode
yarn build
yarn start:prod

Access the API

  • API Base URL: http://localhost:3000/api/v1
  • Swagger Documentation: http://localhost:3000/api/docs
  • Health Check: http://localhost:3000/api/v1/health

πŸ“š API Endpoints

Budget Summary & Analytics

Endpoint Description
GET /api/v1/budget/summary Comprehensive budget overview with year-over-year comparisons
GET /api/v1/budget/total Total budget amount with optional filters
GET /api/v1/budget/by-department Budget aggregated by department
GET /api/v1/budget/by-department-all All departments with NEP/GAA comparison
GET /api/v1/budget/compare-nep-gaa Compare NEP vs GAA budgets
GET /api/v1/budget/records-mapped Paginated budget records with full UACS mappings

Departments

Endpoint Description
GET /api/v1/departments List all departments with optional budget data
GET /api/v1/departments/:code Detailed department information with hierarchical breakdown

Regions

Endpoint Description
GET /api/v1/regions List all regions with optional budget allocations
GET /api/v1/regions/:code Detailed regional budget breakdown

Expense Classifications

Endpoint Description
GET /api/v1/expense-categories Hierarchical expense classifications (Classification β†’ SubClass β†’ Group β†’ Object)
GET /api/v1/expense-categories/budget Budget breakdown by expense category with top sub-objects

Funding Sources

Endpoint Description
GET /api/v1/funding-sources List all funding sources
GET /api/v1/funding-sources/:code Detailed funding source information

Organizations

Endpoint Description
GET /api/v1/organizations Search and list organizations
GET /api/v1/organizations/:uacsCode Organization details with budget data

Locations

Endpoint Description
GET /api/v1/locations/provinces List all provinces
GET /api/v1/locations/cities List all cities/municipalities
GET /api/v1/locations/barangays List all barangays

Health & Monitoring

Endpoint Description
GET /api/v1/health Basic health check
GET /api/v1/health/detailed Detailed health check with database connectivity

Complete API Documentation: Available at http://localhost:3000/api/docs (Swagger UI)

πŸ”§ Configuration

Environment variables (.env):

NODE_ENV=development
PORT=3000
API_VERSION=v1

# Neo4j Configuration
NEO4J_URI=neo4j://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your-password

# App Configuration
CORS_ORIGIN=*
RATE_LIMIT_TTL=60
RATE_LIMIT_MAX=100

# Logging
LOG_LEVEL=debug

πŸ“ Project Structure

open-budget-api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/                    # Configuration files
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   └── neo4j/                # Neo4j database module
β”‚   β”œβ”€β”€ modules/
β”‚   β”‚   β”œβ”€β”€ budget/               # Budget summary & analytics endpoints
β”‚   β”‚   β”œβ”€β”€ departments/          # Department endpoints & hierarchies
β”‚   β”‚   β”œβ”€β”€ regions/              # Regional allocation endpoints
β”‚   β”‚   β”œβ”€β”€ expense-categories/   # Expense classification endpoints
β”‚   β”‚   β”œβ”€β”€ funding-sources/      # Funding source endpoints
β”‚   β”‚   β”œβ”€β”€ organizations/        # Organization search & details
β”‚   β”‚   β”œβ”€β”€ locations/            # Geographic location endpoints
β”‚   β”‚   └── health/               # Health check endpoints
β”‚   β”œβ”€β”€ common/                   # Shared utilities
β”‚   β”‚   β”œβ”€β”€ dto/                  # Data Transfer Objects
β”‚   β”‚   β”œβ”€β”€ filters/              # Exception filters
β”‚   β”‚   └── interceptors/         # Request/Response interceptors
β”‚   β”œβ”€β”€ app.module.ts             # Root application module
β”‚   └── main.ts                   # Application entry point
β”œβ”€β”€ FRONTEND_INTEGRATION.md       # Frontend integration guide
β”œβ”€β”€ FRONTEND_IMPLEMENTATION_GUIDE.md  # Complete implementation guide
└── README.md                      # This file

πŸ§ͺ Testing

# Unit tests
yarn test

# E2E tests
yarn test:e2e

# Test coverage
yarn test:cov

πŸ“– API Examples

Get Budget Summary (Year-over-Year)

curl "http://localhost:3000/api/v1/budget/summary?year=2025"

Returns comprehensive budget overview with selected year, previous year, and next year comparisons including NEP/GAA totals, growth rates, and statistics.

Get Budget Total

curl "http://localhost:3000/api/v1/budget/total?year=2025&type=GAA"

Get Budget by Department

curl "http://localhost:3000/api/v1/budget/by-department?year=2025&type=NEP&limit=10"

Get All Departments with NEP/GAA Comparison

curl "http://localhost:3000/api/v1/budget/by-department-all?year=2025&includeNepGaa=true"

Get Department Details with Hierarchical Breakdown

# Basic department info
curl "http://localhost:3000/api/v1/departments/07"

# With full budget breakdown (agencies, operating unit classes, expense classifications, projects)
curl "http://localhost:3000/api/v1/departments/07?year=2025"

Get Expense Classifications Hierarchy

# Basic classification list
curl "http://localhost:3000/api/v1/expense-categories"

# Full hierarchy with NEP/GAA budgets (Classification β†’ SubClass β†’ Group β†’ Object)
curl "http://localhost:3000/api/v1/expense-categories?year=2025"

Get Budget Records with UACS Mappings

curl "http://localhost:3000/api/v1/budget/records-mapped?year=2025&type=GAA&page=1&limit=50"

πŸ” Security Features

  • βœ… Helmet.js security headers
  • βœ… CORS configuration
  • βœ… Rate limiting (100 requests/minute)
  • βœ… Input validation
  • βœ… Request compression

🎨 Tech Stack

  • Framework: NestJS
  • Database: Neo4j
  • Language: TypeScript
  • Documentation: Swagger/OpenAPI
  • Security: Helmet, Rate Limiting
  • Validation: class-validator

πŸ“Š Data Source

This API serves budget data processed and published through the BetterGovPH Open Budget Data repository. The data originates from the Philippine Department of Budget and Management (DBM) and has been structured into a Neo4j graph database for comprehensive analysis.

Data Coverage

  • Budget Types: NEP (National Expenditure Program) and GAA (General Appropriations Act)
  • Fiscal Years: 2020-2026
  • Total Records: 6.8+ million budget records
  • Total Budget: β‚±106.9 trillion across all years
  • Dimensions: Full UACS (Unified Accounts Code Structure) hierarchy

Data Structure

The open-budget-data repository contains:

  • Raw budget data files (NEP/GAA CSV files)
  • Neo4j import scripts for graph database creation
  • UACS dimension mappings (departments, agencies, expense classifications, etc.)
  • Data validation and processing tools

Setting Up the Database

To use this API, you need to first populate your Neo4j database with the budget data:

  1. Clone the open-budget-data repository
  2. Follow the setup instructions to import data into Neo4j
  3. Configure this API to connect to your populated Neo4j instance

See the open-budget-data README for detailed setup instructions.

πŸ›£οΈ Roadmap

This project is part of a larger initiative to create Open APIs for all Philippine government datasets.

For the complete development roadmap, future Open API projects, and our vision for government data transparency, see PLAN.md.

Current Status

βœ… Open Budget API: comprehensive endpoints for budget data analysis

Upcoming Projects

Learn More: See PLAN.md for detailed timelines, planned features, and how to get involved.

πŸ“ License

MIT License - This project is open source and freely available for use, modification, and distribution.

🀝 Contributing

Contributions are welcome and encouraged! This is an open government data project that benefits from community involvement.

Quick Start:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

For detailed contribution guidelines, development workflow, code style, and testing requirements, please see CONTRIBUTING.md.

Areas for Contribution:

  • API endpoint enhancements
  • Performance optimizations
  • Documentation improvements
  • Test coverage
  • Bug fixes
  • Frontend integration examples
  • Data quality validation

πŸ“ž Contact & Resources

  • Project: BetterGovPH - Open Government Data Initiative
  • API Version: 1.0.0
  • Data Repository: open-budget-data
  • API Repository: open-budget-api
  • Issues: Report bugs or request features via GitHub Issues

🌟 Related Projects & Documentation

  • open-budget-data: Source data and Neo4j import scripts
  • PLAN.md: Complete roadmap and vision for Open APIs across all government datasets
  • CONTRIBUTING.md: Contribution guidelines, development workflow, and code standards
  • CODE_OF_CONDUCT.md: Community standards and behavior expectations

Built with ❀️ for Philippine Government Budget Transparency

About

A REST API built with NestJS, TypeScript, and Neo4j that serves Philippine Government Budget Data from a Neo4j graph database. Based on data from the open-budget-data repository.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.4%
  • JavaScript 0.6%