Backend API¶
Last updated: July 2026
The backend of Crestr is a lightweight Python web application built with FastAPI.
It serves the interactive map, handles authentication, stores user data, and executes routing requests.
Architecture¶
The backend follows a classic monolithic structure suitable for the current scale of the application:
- FastAPI App (
src/fastapi_app.py): Main application with routes and auth. - Pathfinding Module (
src/Pathfinding/pathfinder.pyandsrc/Pathfinding/NodeFinder.py) : Contains the A* routing engine and spatial helpers. - Database Models (
models.py): SQLModel definitions for PostgreSQL. - NodeFinder Service: Central class managing graph loading, coordinate conversions, and route building.
Core Responsibilities¶
- User authentication and session management
- Saving and loading user routes and saved points
- Executing A* pathfinding requests
- File import/export (GPX, GeoJSON, KML, FIT)
- Search functionality via LocationIQ API
- Settings persistence
Key Endpoints¶
Authentication¶
POST /auth/loginPOST /auth/registerPOST /auth/logout
Routing¶
POST /routing/calculate-path--> Main endpoint that returns an optimised hiking route as GeoJSONPOST /routing/save-route--> Persists a generated route to the databasePOST /routing/load-route--> Retrieves a saved routePOST /routing/delete-route--> Deletes a route via route name (also ensures current user owns route)POST /routing/download-route--> Returns GPX or GeoJSON filePOST /routing/import-route-file–-> Supports GPX, FIT, KML, and GeoJSON uploads
Points of Interest¶
POST /points/save_pointGET /points/get_saved_pointsPOST /points/delete_point
Other¶
GET /get_settings/POST /save_settingsPOST /search_area–-> Location search
Database¶
- PostgreSQL with SQLModel
- Main tables:
user,route,point,settings,session_table,action_logandissues - Routes and points are scoped to individual users
Design Highlights¶
- Rate Limiting: Implemented via FastAPI-Limiter to protect against abuse.
- Coordinate Handling: Robust conversion between Web Mercator, WGS84, and BNG using pyproj.
- Graph Management: Lazy loading of the large trail graph with KDTree optimisation.
- Error Handling: Consistent JSON responses and custom error pages.
- Use of Sessions Table: Mixed with Cookies to send cryptographic session IDs which are sent back to the backend on each (authentication-required) API call
Current Limitations¶
- All routing runs synchronously --> FastAPI refactor has been shipped and so asynchronous calls should be started to be designed
Future Migration Path¶
- Move heavy pathfinding to a separate micro-service or background worker if needed.