Compatibility-first REST API for Tanzania location data backed by PostgreSQL and Prisma ORM 7.
- Prisma ORM 7 with a generated client in
src/generated/prisma - Dual API base paths:
/v1is canonical and/apiremains as a compatibility alias - Reproducible Prisma migration + seed flow for local development and CI
- Request IDs, structured HTTP logs, cache headers, and safer full-text search
- Dependabot and GitHub Actions for ongoing dependency updates and verification
- Node.js
22.13.0+ - pnpm
10.7.0+ - PostgreSQL
16+recommended
-
Install dependencies.
pnpm install
-
Create your environment file.
cp .env.example .env
-
Start PostgreSQL and update your connection strings if needed.
- Local and test environments use a direct PostgreSQL
DATABASE_URL. - Production uses a Prisma Accelerate
DATABASE_URL. - If you run
pnpm db:migrateagainst an Accelerate-backed environment, also provideDIRECT_DATABASE_URLso the migration bootstrap can talk to Postgres directly.
- Local and test environments use a direct PostgreSQL
-
Apply the checked-in schema and seed deterministic fixture data.
pnpm db:migrate pnpm db:seed
โ ๏ธ WARNING:pnpm db:seedis destructive โ it truncates all tables before inserting fixture data. Do not run it against a database you need to preserve. -
Start the development server.
pnpm dev
pnpm db:migrate
pnpm db:seed
pnpm lint
pnpm typecheck
pnpm build
pnpm test
pnpm test:ci
pnpm openapi:jsonpnpm db:migrateis the supported entrypoint for schema changes in this repo- On a fresh database it bootstraps the historical
initmigration, marks that baseline as applied, and then deploys later migrations - On an existing database that already has the older Prisma migration history, it only applies the new additive migrations
- Prefer
pnpm db:migrateover callingprisma migrate deploydirectly DATABASE_URLmay point at Prisma Accelerate in production, butpnpm db:migratestill requires a direct Postgres URL inDIRECT_DATABASE_URL
-
pnpm testexpects a database that has already been migrated and seeded -
pnpm test:cirunsgenerate,db:migrate,db:seed, and the Jest suite in one command -
For a clean local verification flow, run:
pnpm db:migrate pnpm db:seed pnpm test
/v1: canonical path for current integrations/api: compatibility alias for older consumers
Both base paths return the same payload shapes.
GET /v1/countriesGET /v1/regionsGET /v1/districtsGET /v1/wardsGET /v1/places
GET /v1/countries/:idGET /v1/regions/:regionCodeGET /v1/districts/:districtCodeGET /v1/wards/:wardCodeGET /v1/places/:id
GET /v1/countries/:countryCode/regionsGET /v1/regions/:regionCode/districtsGET /v1/districts/:districtCode/wardsGET /v1/wards/:wardCode/places
GET /v1/search?q=nzuguni
All collection endpoints support:
pagelimitsearch
Additional filters:
/regions:countryId/districts:countryId,regionCode/wards:countryId,regionCode,districtCode/places:countryId,regionCode,districtCode,wardCode
- Swagger UI:
http://localhost:8080/api-docs - OpenAPI JSON:
http://localhost:8080/openapi.json pnpm openapi:jsonexports the spec togenerated/openapi/openapi.json
- Prisma configuration lives in prisma.config.ts
- The checked-in migration chain now creates the
general.search_vectorcolumn, trigger, and GIN index used by/search - Seed data is intentionally small and deterministic so CI and tests can assert exact results
- The seed is destructive by design for local/CI fixture setup; do not run it against a database you expect to preserve unchanged
.github/dependabot.ymlopens weekly update PRs for npm packages and GitHub Actions.github/workflows/ci.ymlvalidates every PR against Postgres on Node22.13.0
This project is licensed under the CopyLeft License. See LICENSE.