This project is a high-performance, scalable NestJS API for logging user locations and checking if they enter predefined geographic areas (polygons). It is designed to handle heavy load and concurrent requests efficiently.
- Log user locations and check if they enter any predefined area (polygon)
- List and create areas (GeoJSON polygons)
- List logs of area entries (with user, area, and timestamp)
- Highly concurrent: optimized for high-load scenarios
- Pagination for large datasets
- Postman collection included for easy testing
- Install dependencies:
pnpm install
- Configure your PostgreSQL connection in
.env(seeprisma/schema.prismafor details) - Run database migrations:
pnpm exec prisma migrate dev --name init pnpm exec prisma generate
- (Optional) Seed test data:
pnpm exec ts-node scripts/seed.ts # or for bulk area insert: pnpm exec ts-node scripts/bulk-seed.ts
- Start the server:
pnpm run start:dev
Note: The server must be running at
http://localhost:3000for e2e tests to work.
- Run all tests:
pnpm run test - Run only e2e tests:
pnpm run test:e2e
- What is tested?
- API endpoints (including
/locationsunder load) - Example:
test/locations.e2e-spec.tssends 100 concurrent POST requests to/locationsand checks the results.
- API endpoints (including
- POST /areas
- Body:
{ "name": "Test Area", "polygon": { "type": "Polygon", "coordinates": [ [ [29.9, 40.4], [29.9, 40.6], [30.1, 40.6], [30.1, 40.4], [29.9, 40.4] ] ] } }
- GET /areas?page=1&limit=100
- Query Params:
page(default: 1)limit(default: 100)
- Response:
{ "items": [ ... ], "total": 1000000, "page": 1, "limit": 100, "pageCount": 10000 }
- POST /locations
- Body:
{ "userId": "test-user-1", "latitude": 40.000, "longitude": 30.000 } - Response:
{ "enteredAreas": ["area-id-1", ...], "logs": [ { "userId": "...", "areaId": "...", "timestamp": "..." }, ... ] }
- GET /logs?page=1&limit=100
- Query Params:
page(default: 1)limit(default: 100)
- Response:
{ "items": [ { "userId": "...", "areaId": "...", "timestamp": "...", ... }, ... ], "total": 12345, "page": 1, "limit": 100, "pageCount": 124 }
- The project includes a Jest test (
test/locations.e2e-spec.ts) that sends 100 concurrent POST requests to/locationsto verify high-load performance.
- A ready-to-use Postman collection is available in the
postman/folder. - Import
postman/LocationLoggingAPI.postman_collection.jsoninto Postman to test all endpoints easily, including paginated requests.
- All polygons use GeoJSON format: coordinates are
[longitude, latitude]. - The system is optimized for large datasets (millions of areas/logs) and concurrent requests.
- For best performance, use pagination on all list endpoints.
Developed by Ahmet ÖZALP
Feel free to reach out for questions, improvements, or contributions!