Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/astrxnomo/shop-microservers/llms.txt

Use this file to discover all available pages before exploring further.

Shop Microservers exposes every backend capability through a single Nginx reverse proxy. Whether you are calling from the Next.js frontend, a mobile client, or a curl terminal session, all requests travel through the gateway and are routed to the correct internal microservice — Auth (port 3004), Catalog (port 3001), Cart (port 3002), or Orders (port 3003). The frontend itself is served at the root path and also communicates exclusively through this gateway; it never contacts a service directly.

Base URL

The default gateway base URL is:
http://localhost
The gateway binds to port 80 by default. You can override this with the GATEWAY_PORT environment variable in your .env file. The Next.js frontend reads NEXT_PUBLIC_API_URL to construct its API calls — set this to match your gateway address when deploying outside of the default Docker Compose setup.
VariablePurposeDefault
GATEWAY_PORTPublic port the Nginx gateway listens on80
NEXT_PUBLIC_API_URLBase URL the frontend uses to reach the gatewayhttp://localhost

Authentication

Most endpoints require a JSON Web Token (JWT). Obtain a token by calling POST /api/auth/register to create a new account or POST /api/auth/login to authenticate an existing one. Both endpoints return a signed JWT in the response body. Once you have a token, attach it to every protected request using the standard Authorization header:
Authorization: Bearer <token>
Tokens are signed with JWT_SECRET and expire after 7 days. The frontend stores the token in localStorage and includes it automatically on every API call.
curl http://localhost/api/cart/ \
  -H "Authorization: Bearer eyJhbGci..."
Endpoints marked No in the Auth column below are publicly accessible and do not require an Authorization header. All other endpoints will return 401 Unauthorized if the header is absent or the token is invalid or expired.

Response Format

Every response from every microservice follows the same envelope shape, enforced by a shared respond() utility:
{ "success": true, "data": { ... }, "error": null }
When an error occurs, success is false, data is null, and error contains a human-readable message:
{ "success": false, "data": null, "error": "Error message" }
This consistent structure means you can always check the top-level success boolean before reading data, regardless of which service handled the request.

Common HTTP Status Codes

StatusMeaning
200Success
201Created
400Validation error
401Invalid or missing JWT
404Resource not found
409Conflict (e.g., email already registered)
500Internal server error

Endpoints Summary

MethodPathAuthServiceDescription
POST/api/auth/registerNoAuthRegister a new account
POST/api/auth/loginNoAuthLogin and receive JWT
GET/api/catalog/productsNoCatalogList all products
GET/api/catalog/products/:idNoCatalogGet a product
PATCH/api/catalog/products/:id/stockNo*CatalogDecrement stock
GET/api/cart/YesCartGet current cart
POST/api/cart/itemsYesCartAdd item to cart
DELETE/api/cart/items/:productIdYesCartRemove item from cart
DELETE/api/cart/YesCartClear cart
GET/api/orders/YesOrdersList orders
GET/api/orders/:idYesOrdersGet order by ID
POST/api/orders/YesOrdersCheckout
GET/healthNoGatewayHealth check
The PATCH /api/catalog/products/:id/stock endpoint is called internally by the Orders service during checkout to decrement product stock. It does not require a JWT in the gateway routing layer, but it is not intended for direct external use.

Explore by Service

Auth: Register

Create a new user account and receive a JWT.

Catalog: Products

Browse products and retrieve stock information.

Cart: Cart

Manage the current user’s ephemeral shopping cart.

Orders: Orders

Checkout, and retrieve past order history.

Build docs developers (and LLMs) love