StratoStruct Backend is an Express API deployed to AWS Lambda with the Serverless Framework. It provides authentication, product and supplier management, Mapbox-backed distance/route lookups, and aggregate supplier search for the StratoStruct frontend.
Frontend: https://www.stratostruct.com
- JWT authentication for users.
- Admin authorization for product and supplier mutation routes.
- Product CRUD endpoints.
- Supplier CRUD endpoints.
- Aggregate supplier search by site postcode and selected product IDs.
- Mapbox geocoding, driving distance, and route geometry endpoints.
- Lambda-safe MongoDB connection handling with controlled
503responses when the database is unavailable.
- Node.js 20 on AWS Lambda
- Express
- MongoDB Atlas
- Mongoose
- Serverless Framework v3
- serverless-http
- Mapbox APIs
controllers/ Route handler logic
middleware/ Authentication and admin authorization
models/ Mongoose models
routes/ Express route definitions
db.js Reusable MongoDB connection helper
handler.js Lambda/serverless-http entry point
server.js Express app setup
serverless.yml AWS Lambda deployment config
The backend requires:
export MONGO_URI='mongodb+srv://...'
export SECRET='your_jwt_secret'
export MAPBOX_API_KEY='your_mapbox_token'These variables are read by serverless.yml during package/deploy and by the app at runtime.
Install dependencies:
npm ciValidate that the Lambda handler loads:
node -e "require('./handler'); console.log('handler loaded')"Package locally with placeholder values:
MONGO_URI=mongodb://localhost/test SECRET=test MAPBOX_API_KEY=test npx serverless package --stage devDeploy with real environment variables exported:
source .env
npx serverless deploy --stage devThe current deployment target is configured in serverless.yml:
- Runtime:
nodejs20.x - Region:
eu-west-2 - Timeout:
15 - Service:
stratostruct-lambda
All product, supplier, and Mapbox routes require authentication.
POST /api/user/signupPOST /api/user/loginDELETE /api/user/delete
GET /api/productsGET /api/products/:idPOST /api/productsadmin onlyPATCH /api/products/:idadmin onlyDELETE /api/products/:idadmin only
GET /api/suppliersGET /api/suppliers/:idGET /api/suppliers/product/:idPOST /api/suppliersadmin onlyPATCH /api/suppliers/:idadmin onlyDELETE /api/suppliers/:idadmin onlyPOST /api/suppliers/searchPOST /api/suppliers/suppliers-by-products
POST /api/suppliers/search accepts:
{
"sitePostcode": "SE15 4BT",
"productIds": ["product-id-1", "product-id-2"]
}It returns the site coordinates, matching products, ranked suppliers, supplier coordinates, component match counts, driving distances, and drive durations.
GET /api/mapbox/getDistance?postcode1=&postcode2=POST /api/mapbox/getRouteGET /api/mapbox/getCoordinates?postcode=
- If Atlas is paused or the MongoDB SRV record is unavailable, search/login routes can fail. The app now returns a controlled
503instead of hanging until Lambda timeout. - Rotate
MONGO_URIcredentials andSECRETif they are exposed in logs, screenshots, or shared text. - The backend currently uses Mapbox directly per lookup; caching postcode coordinates and route summaries would reduce latency and API usage in a future pass.