Skip to content

Geospatial discovery#172

Merged
zakkiyyat merged 4 commits intoMixMatch-Inc:mainfrom
S-Mubarak:geospatial-discovery
Mar 7, 2026
Merged

Geospatial discovery#172
zakkiyyat merged 4 commits intoMixMatch-Inc:mainfrom
S-Mubarak:geospatial-discovery

Conversation

@S-Mubarak
Copy link
Contributor

This introduces a location-based discovery feature that allows users to view food items from restaurants physically near them. The goal is to improve relevance in the food discovery experience by prioritizing restaurants within the user’s geographic vicinity. To support this functionality, the Restaurant MongoDB schema has been updated to include a GeoJSON Point field for location data along with a 2dsphere index to enable efficient geospatial queries.

A new endpoint, GET /api/foods/discover, has been implemented to retrieve food items from nearby restaurants based on the user's coordinates. The endpoint accepts longitude, latitude, and cursor as query parameters. Internally, a MongoDB $geoNear aggregation pipeline is used to fetch FoodItems belonging to restaurants located within a defined radius (10km) of the provided coordinates. The results are sorted by proximity so that the closest restaurants appear first.

To support scalable browsing, the endpoint implements cursor-based pagination, returning results in batches of 10 items per request. Each response includes the calculated distance between the user and the restaurant, allowing the client application to display proximity information. Query performance is optimized through the use of the 2dsphere index on the restaurant location field, ensuring efficient geospatial lookups even as the dataset grows.

closes #150

Copy link
Contributor

@zakkiyyat zakkiyyat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes and they look good. Once the conflicts are addressed, this can be merged.

Comment on lines +5 to +9
const querySchema = z.object({
longitude: z.coerce.number(),
latitude: z.coerce.number(),
cursor: z.string().optional(),
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add strict longitude/latitude range checks ([-180,180], [-90,90]) from query validation, focus on:

  • coordinate validation boundaries and malformed query handling
  • $geoNear pipeline correctness and distance sorting
  • cursor pagination behavior (stability and safety)
  • response contract consistency (distanceMeters, cursor nullability)

# Conflicts:
#	backend/README.md
#	backend/src/models/food-item.model.ts
#	backend/src/models/index.ts
#	backend/src/routes/index.ts
Copy link
Contributor

@zakkiyyat zakkiyyat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comments. The changes look good. Approving.

@zakkiyyat zakkiyyat merged commit 61ce7d8 into MixMatch-Inc:main Mar 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Geospatial Discovery Algorithm

2 participants