Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/luisumit/LaPreviaRestobar/llms.txt

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

The La Previa Restobar backend is a lightweight Express.js server (v4.18.2) that uses the firebase-admin SDK (v12.0.0) to bridge the Android client to a Firebase Realtime Database. Every resource endpoint reads from or writes to a named node in the database (products, orders, tables, inventory, users). The server listens on port 3000 and requires a serviceAccountKey.json credential file to authenticate with Firebase.

Base URL

The Android app selects the base URL automatically at runtime through NetworkModule, using BuildConfig.BASE_URL for emulator targets and BuildConfig.PHYSICAL_BASE_URL for physical devices.
EnvironmentTargetBase URL
debugAndroid Emulatorhttp://10.0.2.2:8080/
debugPhysical Devicehttp://192.168.0.104:8080/
stagingPhysical Devicehttp://192.168.0.104:8080/
releaseProductionhttps://api.laprevia.com/
Note: 10.0.2.2 is the special loopback alias the Android Emulator uses to reach the host machine’s localhost. Use this address when running both the server and emulator on the same development machine.
Port discrepancy: server.js listens on port 3000 (see app.listen(3000, ...) and EXPOSE 3000 in the Dockerfile). However, the Android app’s BuildConfig.BASE_URL values all use port 8080. When the backend is deployed to Cloud Run, the platform remaps the container’s port 3000 to the externally visible port 8080. For local development, run the server normally on port 3000 and — if you are not using Cloud Run — either update the debug BASE_URL in build.gradle.kts to use port 3000, or place a reverse proxy in front of the server on port 8080.

How the Android App Consumes the API

The Android app uses Retrofit 2 with an OkHttp client, wired together by Hilt in NetworkModule. Key configuration details:
  • Converter: GsonConverterFactory — all bodies are JSON serialized/deserialized via Gson.
  • Timeouts: 30 seconds for connect, read, and write.
  • Logging: HttpLoggingInterceptor logs full request/response bodies in DEBUG builds; logging is suppressed in release builds.
  • Emulator detection: NetworkModule.isRunningOnEmulator() checks Build.FINGERPRINT, Build.MODEL for emulator signatures and routes to the correct base URL automatically.
  • Coroutines: Every ApiService function is suspend, intended to be called from a Kotlin coroutine scope (e.g., a ViewModel).
// di/NetworkModule.kt (excerpt)
@Provides
@Singleton
fun provideRetrofit(
    okHttpClient: OkHttpClient,
    @BaseUrl baseUrl: String
): Retrofit {
    return Retrofit.Builder()
        .baseUrl(baseUrl)
        .client(okHttpClient)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}

Authentication

The current server.js does not enforce any authentication headers or tokens on incoming requests. This is a development-grade API — no Bearer tokens, API keys, or session cookies are required for any endpoint. When moving to a production deployment you should add middleware (e.g., Firebase ID token verification) before exposing the server publicly.

Health Check

Use the health endpoint to verify the server is reachable before making resource calls.
GET /api/health
Response
{
  "status": "ok",
  "message": "Server is running",
  "timestamp": 1717200000000
}
The Android ApiService maps this to:
@GET("api/health")
suspend fun healthCheck(): Response<HealthResponse>

data class HealthResponse(
    val status: String,
    val message: String,
    val timestamp: Long
)

Endpoint Summary

The table below covers every route exposed by the backend, including both the typed Retrofit endpoints (ApiService.kt) and the raw Firebase pass-through routes in server.js.
MethodPathDescription
GET/api/healthServer health check
GET/productsList all menu products
GET/products/{id}Get a single product by ID
POST/productsCreate a new product
PUT/products/{id}Update an existing product
DELETE/products/{id}Delete a product
GET/products/categoriesList distinct product categories
GET/ordersList all orders
GET/orders/table/{tableId}List orders for a specific table
POST/ordersCreate a new order
PUT/orders/{id}/statusUpdate an order’s status
GET/tablesList all tables
GET/tables/{id}Get a single table by ID
PUT/tables/{id}/statusUpdate a table’s status
GET/inventoryList all inventory records
PUT/inventory/{productId}/stockUpdate stock for a product
GET/inventarioRaw Firebase inventory read
POST/inventarioRaw Firebase inventory write
GET/usuariosRaw Firebase user list
POST/usuariosRaw Firebase user save

Running Locally

Prerequisites:
  1. Node.js 18 or later.
  2. A Firebase project with Realtime Database enabled.
  3. A serviceAccountKey.json file downloaded from the Firebase console (Project Settings → Service accounts → Generate new private key). Place it in the same directory as server.js.
cd backend
npm install
node server.js
# → API Firebase corriendo en puerto 3000
The server starts on http://localhost:3000. If you are hitting it from an Android Emulator, use http://10.0.2.2:3000 as the base URL in your build config.

Docker Deployment

A Dockerfile is included for containerised deployment. It uses the official node:18 base image, copies all backend files, runs npm install, exposes port 3000, and starts the server with node server.js.
FROM node:18

WORKDIR /app

COPY . .

RUN npm install

EXPOSE 3000

CMD ["node", "server.js"]
Build and run the container:
docker build -t laprevia-backend .
docker run -p 3000:3000 laprevia-backend
Important: Make sure serviceAccountKey.json is present in the build context before running docker build, as it is copied into the image by COPY . ..

Resource Pages

Products

CRUD operations for menu items, pricing, and inventory tracking flags.

Orders

Create orders and advance them through the eight-step status lifecycle.

Tables

Retrieve table configurations and update table status as orders progress.

Inventory

Read current stock levels and update quantities for tracked products.

Build docs developers (and LLMs) love