Skip to content

Commit 5434a48

Browse files
committed
feat: add graph entities
1 parent a7e41c9 commit 5434a48

1 file changed

Lines changed: 172 additions & 0 deletions

File tree

README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,178 @@ curl http://localhost:8000/api/search?q=Poblacion&type=barangay&sort=psgc_code&l
141141
curl http://localhost:8000/api/hierarchy/0301401007
142142
```
143143

144+
## Neo4j Graph Database Schema
145+
146+
### Entity Relationship Diagram
147+
148+
```mermaid
149+
graph TD
150+
%% Node definitions with properties
151+
Region["<b>Region</b><br/>━━━━━━━━━━<br/>• psgc_code<br/>• name<br/>• correspondence_code<br/>• geographic_level<br/>• population_2020<br/>• region_code<br/>• province_code (000)<br/>• municipality_code (00)<br/>• barangay_code (000)"]
152+
153+
Province["<b>Province</b><br/>━━━━━━━━━━<br/>• psgc_code<br/>• name<br/>• correspondence_code<br/>• geographic_level<br/>• population_2020<br/>• region_code<br/>• province_code<br/>• municipality_code (00)<br/>• barangay_code (000)"]
154+
155+
CityMunicipality["<b>CityMunicipality</b><br/>━━━━━━━━━━<br/>• psgc_code<br/>• name<br/>• correspondence_code<br/>• geographic_level<br/>• type (city/municipality)<br/>• city_class<br/>• income_classification<br/>• population_2020<br/>• region_code<br/>• province_code<br/>• municipality_code<br/>• barangay_code (000)"]
156+
157+
Barangay["<b>Barangay</b><br/>━━━━━━━━━━<br/>• psgc_code<br/>• name<br/>• correspondence_code<br/>• geographic_level<br/>• urban_rural<br/>• population_2020<br/>• region_code<br/>• province_code<br/>• municipality_code<br/>• barangay_code"]
158+
159+
SubMunicipality["<b>SubMunicipality</b><br/>━━━━━━━━━━<br/>• psgc_code<br/>• name<br/>• correspondence_code<br/>• geographic_level<br/>• population_2020<br/>• region_code<br/>• province_code<br/>• municipality_code"]
160+
161+
%% Relationships
162+
Region -->|HAS_PROVINCE| Province
163+
Province -->|HAS_CITY_MUNICIPALITY| CityMunicipality
164+
Region -->|"HAS_CITY_MUNICIPALITY<br/>(NCR Special Case)"| CityMunicipality
165+
CityMunicipality -->|HAS_BARANGAY| Barangay
166+
CityMunicipality -->|HAS_SUBMUNICIPALITY| SubMunicipality
167+
168+
%% Styling
169+
classDef nodeStyle fill:#e1f5fe,stroke:#01579b,stroke-width:2px,color:#000
170+
class Region,Province,CityMunicipality,Barangay,SubMunicipality nodeStyle
171+
```
172+
173+
### Nodes (Entities)
174+
175+
#### Region
176+
177+
Represents administrative regions of the Philippines.
178+
179+
- **Properties:**
180+
- `psgc_code`: Philippine Standard Geographic Code
181+
- `name`: Region name (e.g., "Region I (Ilocos Region)")
182+
- `correspondence_code`: Alternative code for correspondence
183+
- `geographic_level`: Always "Reg" for regions
184+
- `population_2020`: 2020 census population count
185+
- `region_code`: Regional code component of PSGC
186+
- `province_code`: Always "000" for regions
187+
- `municipality_code`: Always "00" for regions
188+
- `barangay_code`: Always "000" for regions
189+
190+
#### Province
191+
192+
Represents provinces within regions.
193+
194+
- **Properties:**
195+
- `psgc_code`: Philippine Standard Geographic Code
196+
- `name`: Province name (e.g., "Ilocos Norte")
197+
- `correspondence_code`: Alternative code for correspondence
198+
- `geographic_level`: Always "Prov" for provinces
199+
- `population_2020`: 2020 census population count
200+
- `region_code`: Parent region code
201+
- `province_code`: Province code component (non-"000")
202+
- `municipality_code`: Always "00" for provinces
203+
- `barangay_code`: Always "000" for provinces
204+
205+
#### CityMunicipality
206+
207+
Represents both cities and municipalities within provinces.
208+
209+
- **Properties:**
210+
- `psgc_code`: Philippine Standard Geographic Code
211+
- `name`: City/Municipality name
212+
- `correspondence_code`: Alternative code for correspondence
213+
- `geographic_level`: "City" or "Mun"
214+
- `type`: Either "city" or "municipality" (derived field)
215+
- `city_class`: Classification for cities (HUC, ICC, CC, etc.)
216+
- `income_classification`: Income classification (1st to 6th class)
217+
- `population_2020`: 2020 census population count
218+
- `region_code`: Parent region code
219+
- `province_code`: Parent province code
220+
- `municipality_code`: Municipality code component (non-"00")
221+
- `barangay_code`: Always "000" for cities/municipalities
222+
223+
#### Barangay
224+
225+
Represents barangays (villages) within cities/municipalities.
226+
227+
- **Properties:**
228+
- `psgc_code`: Philippine Standard Geographic Code
229+
- `name`: Barangay name
230+
- `correspondence_code`: Alternative code for correspondence
231+
- `geographic_level`: Always "Bgy" for barangays
232+
- `urban_rural`: Urban or Rural classification
233+
- `population_2020`: 2020 census population count
234+
- `region_code`: Parent region code
235+
- `province_code`: Parent province code
236+
- `municipality_code`: Parent municipality code
237+
- `barangay_code`: Barangay code component (non-"000")
238+
239+
#### SubMunicipality
240+
241+
Represents sub-municipalities (special administrative divisions).
242+
243+
- **Properties:**
244+
- `psgc_code`: Philippine Standard Geographic Code
245+
- `name`: Sub-municipality name
246+
- `correspondence_code`: Alternative code for correspondence
247+
- `geographic_level`: Always "SubMun"
248+
- `population_2020`: 2020 census population count
249+
- `region_code`: Parent region code
250+
- `province_code`: Parent province code
251+
- `municipality_code`: Parent municipality code
252+
253+
### Relationships
254+
255+
The graph database uses the following relationships to represent the
256+
hierarchical structure of Philippine administrative divisions:
257+
258+
#### HAS_PROVINCE
259+
260+
- **From:** Region
261+
- **To:** Province
262+
- **Description:** Links regions to their constituent provinces
263+
264+
#### HAS_CITY_MUNICIPALITY
265+
266+
- **From:** Province or Region (for NCR)
267+
- **To:** CityMunicipality
268+
- **Description:** Links provinces to their cities and municipalities. Note: NCR
269+
(Region 13) directly links to cities as it has no provinces.
270+
271+
#### HAS_BARANGAY
272+
273+
- **From:** CityMunicipality
274+
- **To:** Barangay
275+
- **Description:** Links cities/municipalities to their constituent barangays
276+
277+
#### HAS_SUBMUNICIPALITY
278+
279+
- **From:** CityMunicipality
280+
- **To:** SubMunicipality
281+
- **Description:** Links cities/municipalities to their sub-municipalities
282+
(special administrative divisions)
283+
284+
### Graph Structure Example
285+
286+
```
287+
Region (e.g., Region III)
288+
├─[HAS_PROVINCE]→ Province (e.g., Bulacan)
289+
│ ├─[HAS_CITY_MUNICIPALITY]→ CityMunicipality (e.g., City of Malolos)
290+
│ │ ├─[HAS_BARANGAY]→ Barangay (e.g., Bagong Bayan)
291+
│ │ └─[HAS_BARANGAY]→ Barangay (e.g., Poblacion)
292+
│ └─[HAS_CITY_MUNICIPALITY]→ CityMunicipality (e.g., Angat)
293+
│ └─[HAS_BARANGAY]→ Barangay (e.g., Laog)
294+
└─[HAS_PROVINCE]→ Province (e.g., Pampanga)
295+
296+
Special Case - NCR (National Capital Region):
297+
Region (NCR/Region 13)
298+
├─[HAS_CITY_MUNICIPALITY]→ CityMunicipality (e.g., City of Manila)
299+
└─[HAS_CITY_MUNICIPALITY]→ CityMunicipality (e.g., Quezon City)
300+
```
301+
302+
### Indexes
303+
304+
The following indexes are created for optimal query performance:
305+
306+
- `region_psgc`: Index on Region.psgc_code
307+
- `province_psgc`: Index on Province.psgc_code
308+
- `city_municipality_psgc`: Index on CityMunicipality.psgc_code
309+
- `barangay_psgc`: Index on Barangay.psgc_code
310+
- `submunicipality_psgc`: Index on SubMunicipality.psgc_code
311+
- `region_name`: Index on Region.name
312+
- `province_name`: Index on Province.name
313+
- `city_municipality_name`: Index on CityMunicipality.name
314+
- `barangay_name`: Index on Barangay.name
315+
144316
## Project Structure
145317

146318
```

0 commit comments

Comments
 (0)