Skip to content

Commit f04f7b1

Browse files
authored
Merge pull request #26 from weaponsforge/dev
v1.1.3
2 parents d158c1d + 62d07fa commit f04f7b1

63 files changed

Lines changed: 1789 additions & 2017 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Bug Report
2+
description: Create a bug report
3+
labels: ['bug']
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
Before opening a new issue:
9+
10+
- Do a search of existing issues.
11+
- Pull the latest updates from this repository's `dev` branch.
12+
13+
- type: textarea
14+
attributes:
15+
label: To Reproduce
16+
description: A step-by-step description of how to reproduce the issue, or a link to the reproducible repository.
17+
placeholder: |
18+
1. Start the application in development (npm run dev)
19+
2. Press enter
20+
3. An error appears: "❌ MongoDB connection error MongooseServerSelectionError: getaddrinfo ENOTFOUND db-ph-regions"
21+
validations:
22+
required: true
23+
24+
- type: textarea
25+
attributes:
26+
label: Current vs. Expected behavior
27+
description: A clear and concise description of what the bug is, and what you expected to happen.
28+
placeholder: 'Following the steps from the previous section, I expected A to happen, but I observed B instead'
29+
validations:
30+
required: true
31+
32+
- type: textarea
33+
attributes:
34+
label: Provide environment information
35+
description: Please run `npm run info` in the root directory of your project and paste the results.
36+
render: bash
37+
placeholder: |
38+
Node version: v24.11.0
39+
Platform: win32
40+
Arch: x64
41+
V8 version: 13.6.233.10-node.28
42+
npm version: 11.6.1
43+
validations:
44+
required: true
45+
46+
- type: dropdown
47+
attributes:
48+
label: Which area(s) are affected? (Select all that apply)
49+
multiple: true
50+
options:
51+
- 'Not sure'
52+
- 'REST API'
53+
- 'Local development'
54+
- 'API documentation'
55+
- 'Database querying'
56+
- 'Open API files (json, yml)'
57+
- 'Others'
58+
validations:
59+
required: true
60+
61+
- type: textarea
62+
attributes:
63+
label: Additional context
64+
description: |
65+
Any extra information that might help us investigate.
66+
placeholder: |
67+
I tested my reproduction against different `mongoose` releases, and the first one that introduced the bug was "v9.4.1", since reverting to "v8.16.5" works.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Feature Request
2+
description: Suggest a new feature or improvement to the project
3+
labels: ['enhancement']
4+
body:
5+
- type: textarea
6+
attributes:
7+
label: What problem will this feature address?
8+
description: A clear and concise description of what the problem is.
9+
placeholder: |
10+
I'm always frustrated when I can't do X
11+
validations:
12+
required: true
13+
14+
- type: textarea
15+
attributes:
16+
label: Describe the solution you'd like
17+
description: A clear and concise description of what you want to happen.
18+
placeholder: Add X to the core
19+
validations:
20+
required: true
21+
22+
- type: textarea
23+
attributes:
24+
label: Describe alternatives you've considered
25+
description: A clear and concise description of any alternative solutions or features you've considered.
26+
placeholder: |
27+
Maybe use Y as a workaround?
28+
validations:
29+
required: true
30+
31+
- type: textarea
32+
attributes:
33+
label: Additional context
34+
description: Add any other context or screenshots about the feature request here.
35+
validations:
36+
required: false

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Summary
2+
<!-- Provide a short summary of your changes and the motivation behind them. -->
3+
4+
## Related Issues
5+
<!-- List any related issues, e.g. Fixes #123 or Closes #456 -->
6+
7+
## Type of Change
8+
- [ ] Bug fix
9+
- [ ] New feature
10+
- [ ] Breaking change
11+
- [ ] Refactor
12+
- [ ] Documentation
13+
- [ ] Other (please describe):
14+
15+
## Checklist
16+
- [ ] I have read the [CONTRIBUTING.md](https://github.com/weaponsforge/ph-regions/blob/dev/CONTRIBUTING.md)
17+
- [ ] My code follows the CODE STYLE ([folder structure](https://github.com/weaponsforge/ph-regions/blob/dev/README.md#-project-folder-structure), [new endpoints](https://github.com/weaponsforge/ph-regions/blob/dev/README.md#%EF%B8%8F-adding-new-endpoints), [code formatting](https://github.com/weaponsforge/ph-regions/blob/dev/server/eslint.config.mjs)) of this project
18+
- [ ] I have added tests where applicable
19+
- [ ] I have tested my changes locally
20+
- [ ] I have linked relevant issues
21+
- [ ] I have added screenshots for UI changes (if applicable)
22+
23+
## Screenshots (if applicable)
24+
<!-- Add before/after screenshots or GIFs here -->
25+
26+
## Additional Context
27+
<!-- Add any other context or information about the PR here -->

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
- name: Checkout the repository
1414
uses: actions/checkout@v4
1515

16-
- name: Use NodeJS v22.14.0
16+
- name: Use NodeJS v24.11.0
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: 22.14.0
19+
node-version: 24.11.0
2020
registry-url: https://registry.npmjs.org/
2121

2222
- name: Install Dependencies

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
with:
2323
ref: ${{ github.event.release.tag_name }}
2424

25-
- name: Use NodeJS v22.14.0
25+
- name: Use NodeJS v24.11.0
2626
uses: actions/setup-node@v4
2727
with:
28-
node-version: 22.14.0
28+
node-version: 24.11.0
2929

3030
- name: Install Vercel CLI
3131
run: npm install --global vercel@47.0.6

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
**ph-regions** is a RESTful API serving hierarchical Philippine location data (islands → regions → provinces → municipalities → barangays). It supports testing/simulating RESTful API requests from client applications, with deployment targets for both regular Node.js and Vercel serverless.
8+
9+
The codebase lives in `/server` — all development work happens there.
10+
11+
## Commands
12+
13+
Run these from the `/server` directory:
14+
15+
```bash
16+
# Development
17+
npm run dev # Start with nodemon (tsx, no compilation needed)
18+
npm run watch # Watch TypeScript files (tsc --watch)
19+
20+
# Type checking & linting
21+
npm run transpile:noemit # Type-check without emitting files
22+
npm run lint # Lint TypeScript files
23+
npm run lint:fix # Auto-fix lint errors
24+
25+
# Build (full pipeline: transpile + docs)
26+
npm run build # Compile TypeScript + build all API docs
27+
npm run transpile # Compile TypeScript only (tsc-alias for path rewrites)
28+
29+
# Database seeding
30+
npm run seed # Seed MongoDB with Philippine location data
31+
32+
# API documentation
33+
npm run docs:gen # Generate OpenAPI YAML/JSON from Zod schemas
34+
npm run docs:build # Build Redocly HTML documentation
35+
npm run docs:swagger # Copy Swagger UI assets + generate docs
36+
```
37+
38+
Docker (run from repo root):
39+
```bash
40+
docker compose up # Start app + MongoDB (development mode)
41+
```
42+
43+
## Architecture
44+
45+
### Request Lifecycle
46+
```
47+
HTTP Request → CORS → Body Parser → Zod Validation Middleware → Controller → MongoCrudClass → Mongoose → MongoDB
48+
```
49+
50+
### Key Abstractions
51+
52+
**`server/src/classes/mongo.class.ts`**`MongoCrudClass` provides reusable `find`, `findOne`, `create`, `update`, `delete` methods used by all controllers. Controllers instantiate it with a Mongoose model.
53+
54+
**`server/src/middleware/validate.ts`** — Generic validation middleware that takes a Zod schema and validates `req.query` or `req.body`. Throws `ServerError` on failure.
55+
56+
**`server/src/middleware/connectServerless.ts`** — Wraps controllers for Vercel serverless, re-establishing MongoDB connections per request (stateless environment).
57+
58+
**`server/src/utils/error.ts`**`ServerError extends Error` with a `status` property. The global error handler in `app.ts` catches these and formats the error response.
59+
60+
### Data Model (Hierarchical)
61+
```
62+
Island (1) → Region (many) → Province (many) → Municipality (many) → Barangays (Stats collection)
63+
```
64+
Mongoose models use virtual population for nested queries. `Stats` holds barangay counts per municipality.
65+
66+
### Zod as Single Source of Truth
67+
Zod schemas in `server/src/schemas/` drive both:
68+
1. **Runtime validation** — query parameter and payload validation via middleware
69+
2. **OpenAPI documentation**`@asteasolutions/zod-to-openapi` generates the spec from the same schemas
70+
71+
When adding or modifying endpoints, update the corresponding Zod schema, the OpenAPI doc file in `server/src/scripts/openapi/docs/`, and run `npm run docs:gen`.
72+
73+
### API Response Shape
74+
All successful responses follow this structure:
75+
```json
76+
{
77+
"success": true,
78+
"total": 17,
79+
"metadata": { "version": "...", "author": "...", "url": "...", "description": "..." },
80+
"data": []
81+
}
82+
```
83+
Error responses:
84+
```json
85+
{ "success": false, "error": "...", "message": ["..."], "status": 400 }
86+
```
87+
88+
### Deployment Platform Branching
89+
The `DEPLOYMENT_PLATFORM` env var (`"regular"` | `"vercel"`) controls:
90+
- Route mounting in `app.ts` (serverless wrapper applied only on Vercel)
91+
- MongoDB connection strategy (`server.ts` vs `connectServerless.ts`)
92+
93+
### Module System
94+
The project uses ESM (`"type": "module"`). TypeScript targets `NodeNext` modules. Path alias `@/*` maps to `src/*``tsc-alias` rewrites these after compilation.
95+
96+
## Environment Setup
97+
98+
Copy `server/.env.example` to `server/.env` and set:
99+
- `MONGO_URI` — MongoDB connection string
100+
- `DEPLOYMENT_PLATFORM``regular` for local dev
101+
- `ALLOW_CORS=1` and `ALLOW_ALL_ORIGINS=1` for local dev
102+
- `BASE_API_URL` — e.g. `http://localhost:3001`
103+
104+
## Code Style
105+
106+
ESLint enforces: single quotes, no semicolons, 2-space indent, Unix line endings, no trailing commas. Run `npm run lint:fix` before committing. TypeScript strict mode is on — no implicit `any`, strict null checks.

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for gu
5454

5555
## 📋 Requirements
5656

57-
1. NodeJS LTS >= v22
57+
1. NodeJS LTS >= v24
58+
```text
59+
Recommended:
60+
node: 24.11.0
61+
npm: 11.6.1
62+
```
5863
2. Docker
5964

6065
### 📦 Core Libraries/Frameworks
@@ -64,15 +69,15 @@ We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for gu
6469

6570
| Library | Version | Description |
6671
| --- | --- | --- |
67-
| Express | `5.1.0` | Node.js web framework for building APIs and web servers. |
68-
| Mongoose | `8.16.5` | ODM for MongoDB that provides schema-based modeling and data interaction. |
69-
| Zod | `4.0.10` | TypeScript-first schema validation for request payloads and query parameters. |
70-
| Nodemon | `3.1.10` | Development tool that automatically restarts the server on file changes. |
71-
| tsx | `4.20.3` | Executes TypeScript and TSX files directly, ideal for dev and script running. |
72+
| Express | `5.2.1` | Node.js web framework for building APIs and web servers. |
73+
| Mongoose | `9.4.1` | ODM for MongoDB that provides schema-based modeling and data interaction. |
74+
| Zod | `4.3.6` | TypeScript-first schema validation for request payloads and query parameters. |
75+
| Nodemon | `3.1.14` | Development tool that automatically restarts the server on file changes. |
76+
| tsx | `4.21.0` | Executes TypeScript and TSX files directly, ideal for dev and script running. |
7277
| tsc-alias | `1.8.16` | Rewrites path aliases in compiled TypeScript output (`tsconfig` paths). |
73-
| ESlint | `9.32.0` | Linting tool that enforces code style, quality, and formatting rules. |
74-
| @asteasolutions/zod-to-openapi | `8.1.0` | Generates OpenAPI YAML and JSON files from Zod schemas. |
75-
| @redocly/cli | `2.1.0` | Generates an API documentation using an OpenAPI YAML input. |
78+
| ESlint | `10.2.1` | Linting tool that enforces code style, quality, and formatting rules. |
79+
| @asteasolutions/zod-to-openapi | `8.5.0` | Generates OpenAPI YAML and JSON files from Zod schemas. |
80+
| @redocly/cli | `2.28.1` | Generates an API documentation using an OpenAPI YAML input. |
7681
| swagger-ui-express | `4.1.8` | Generates a Swagger UI API documentation using an OpenAPI JSON input. |
7782

7883
</details>
@@ -296,6 +301,10 @@ Runs type-checking without generating the JavaScript or declaration files from t
296301

297302
Watches file changes in `.ts` files using the `tsc --watch` option.
298303

304+
### `npm run info`
305+
306+
Logs the installed Node.js and npm version, environment platform, architecture and V8 version.
307+
299308
### `npm run lint`
300309

301310
Lints TypeScript source codes.

server/.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.14.0
1+
24.11.0

server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# BASE PROFILE
2-
FROM node:22.14.0-alpine AS base
2+
FROM node:24.11.0-alpine AS base
33
RUN mkdir -p /opt/server
44
WORKDIR /opt/server
55
RUN chown -R node:node /opt/server

0 commit comments

Comments
 (0)