Unified ZIP Code
For a reader to check the claims in my case study on the Philippine zip code, the code set behind them has to be public. I published all 42,047 codes as open data, with a lookup app and a public API. Each code points to one barangay, the smallest unit of local government.
TL;DR
- The Philippine zip code has four digits and reaches a city or municipality. In Malabon City, twelve of the twenty one barangays share the code 1470.
- For 1,632 of the 1,634 municipalities, a rule derives each new code from the government's list of places. For Manila and two barangays of Cebu City, the published data is the authority.
- The code set's files are CSV and JSON under the MIT licence. A lookup library with no imports of its own reads them in Node or in a browser.
- In the app, each of Malabon City's twenty one barangays shows its own new code beside the old one.
What it is
The Unified ZIP Code is a seven character postal code for the Philippines that
reaches the barangay. Its first two letters stand for the province, the next two
digits for the municipality, and the last three digits for the barangay. The
code BC23023 means barangay Poblacion, in the municipality of San Rafael, in
the province of Bulacan.
Where the case study tells why the code exists, this project is the deliverable itself. It publishes the full set of 42,047 codes as open data in CSV and JSON. Alongside the data are a lookup library, a one page app and a public API, all released under the MIT licence.
The problem
The case study makes three claims about the code set. Every barangay in the country carries a unique seven character code. Twelve of Malabon’s twenty one barangays share the existing zip code 1470. Row by row, the new code reconciles with the government’s geographic code and with the old zip code.
The code set behind those claims was a spreadsheet that only I held. Publishing it lets anyone check the claims without taking my word for them.
The decision
The code derives from the Philippine Standard Geographic Code (PSGC), the government’s own list of places. For every municipality but two, the rule takes the municipality’s four character prefix and adds the last three digits of each barangay’s nine digit PSGC.
In Manila, 896 of the 897 barangays carry a sequential number in place of their
PSGC digits. In Cebu City, the barangays of North Reclamation Area and Santo
Niño have no PSGC assigned. Their codes, CE17999 and CE17998, sit outside
the derived range.
Manila and Cebu City are the reason the project ships the data rather than the rule alone. Beside the data, the documentation states the rule and names both exceptions.
What it does
The app takes a barangay, a municipality, a seven character code, a
municipality’s four character code such as BC23, a nine digit PSGC, or an old
four digit zip code. It answers any of these with the record of each barangay
that matches. The search box below sends each search to the app’s
public API.
Try ,, or.
For each search, the live app at zip.jamesventura.dev shows the request it made to the same API. Open to the public with no key, the API has seven GET endpoints. They return one barangay by its code or by its PSGC, every barangay under an old zip code, the results of a free text search, and listings of the provinces, the municipalities and the barangays.
Every response from the API is JSON with an ok field. The API answers
malformed input with a 400 and unknown input with a 404. Each response also
carries rate limit headers, at 60 requests a minute per address.
The project has five dependencies: Astro, its Vercel adapter and three fonts. While all five belong to the app and the API, the lookup library itself imports nothing. The library runs in Node or in a browser. From a browser, it can fetch the whole code set as one file of about 430 KB compressed.
Of the project’s 28 tests, one asserts that all 42,047 codes are unique and
well formed. Another asserts that BC23023, the worked example in the case
study, resolves to the barangay it names.
What I’d do differently
Although the code set is a snapshot of the 2019 deliverable, the Philippine Statistics Authority has kept publishing the PSGC. A barangay created, merged or renamed after 2019 is not in the set. Keeping up with those changes is the maintenance problem the case study ends on.
The next version regenerates the set from the live PSGC. Each regenerated set carries a version and its own date, for anyone using the data to tell how current it is.
Result
The app and its API are live at zip.jamesventura.dev. The source and the data are open at github.com/0xC0000094/unified-zip-code.
A search for Malabon returns twenty four records: the twenty one barangays of Malabon City, and three barangays elsewhere with Malabon in their names. While twelve of Malabon City’s barangays show the shared zip code 1470, each of the twenty one carries its own new code.