Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nelrondon/backend-proyecto-estructuras/llms.txt

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

This guide walks you through getting a local instance of the Estructuras Backend API running from scratch and executing your first authenticated real estate listing request. You will clone the repository, configure the required environment variables, start the server, register a user, log in, and query both the user profile and the property catalog — all in a few minutes.
The Estructuras API issues authentication tokens as HTTP-only cookies. In a browser you must always send requests with credentials: 'include' (Fetch API) or withCredentials: true (Axios) so the cookie is attached automatically. For curl, use -c cookies.txt -b cookies.txt to persist and replay the cookie across commands. Examples for both are provided in each step below.

Prerequisites

  • Node.js 18 or later
  • pnpm 10 or later (npm install -g pnpm)
  • A Turso account with access to the estructuradb-nelrondon database (or your own Turso database — see Configuration)

1

Clone the repository and install dependencies

Clone the project from GitHub and install all dependencies with pnpm. Because the project ships a packageManager field pinned to pnpm@10.12.1, npm and yarn will warn you to switch.
git clone https://github.com/nelrondon/backend-proyecto-estructuras.git
cd backend-proyecto-estructuras
pnpm install
After installation your node_modules will contain Express v5, @libsql/client, jsonwebtoken, bcrypt, zod, and the rest of the runtime dependencies.
2

Create your .env file

The server will not start without a valid .env file at the project root. Create one based on the template below:
# .env
PORT=3000
SECRET_KEY=your-super-secret-jwt-signing-key-change-this
DB_TOKEN=your-turso-database-auth-token
SALT_ROUNDS=10
VariableRequiredDescription
PORTNo (default: 3000)TCP port the HTTP server will bind to
SECRET_KEYYesSecret used to sign and verify JWTs — must be a strong random string in production
DB_TOKENYesTurso authentication token for libsql://estructuradb-nelrondon.aws-us-east-1.turso.io
SALT_ROUNDSNo (default: 10)bcrypt cost factor for password hashing
Never commit .env to version control. Add it to your .gitignore immediately. For instructions on generating a strong SECRET_KEY and obtaining a DB_TOKEN, see the Configuration guide.
3

Start the server

The start script launches the server using Node.js built-in --watch mode, which restarts the process automatically whenever a source file changes — no nodemon required.
pnpm start
You should see the following output in your terminal:
listening on port http://localhost:3000
You can verify the server is alive by hitting the root endpoint:
curl http://localhost:3000/
# → BIENVENIDO
4

Register a new user

Send a POST request to /api/register with the five required user fields. On success the server creates the account, signs a 7-day JWT, and sets it as an HTTP-only token cookie.
curl -s -X POST http://localhost:3000/api/register \
  -H "Content-Type: application/json" \
  -c cookies.txt \
  -d '{
    "name": "María García",
    "email": "maria@example.com",
    "phone": "555-123-4567",
    "username": "mariagarcia",
    "password": "SecurePass123!"
  }'
Successful response (200):
{
  "id": "uuid-string",
  "name": "María García",
  "username": "mariagarcia",
  "email": "maria@example.com",
  "phone": "555-123-4567",
  "last_login": "2024-01-15T10:30:00.000Z"
}
The name field must not contain numbers. The email must be a valid email address. The phone must match a standard North American or international format (e.g. 555-123-4567, +1 (555) 123-4567). Invalid values return a 422 with a specific error message from Zod.
5

Log in

If you already have an account — or want to start a new session — send credentials to POST /api/login. Only username and password are required. The server validates credentials, signs a fresh JWT, and writes the token cookie.
curl -s -X POST http://localhost:3000/api/login \
  -H "Content-Type: application/json" \
  -c cookies.txt -b cookies.txt \
  -d '{
    "username": "mariagarcia",
    "password": "SecurePass123!"
  }'
Successful response (200):
{
  "id": "uuid-string",
  "name": "María García",
  "username": "mariagarcia",
  "email": "maria@example.com",
  "phone": "555-123-4567",
  "last_login": "2024-01-15T10:30:00.000Z"
}
The -c cookies.txt flag tells curl to save the Set-Cookie header to cookies.txt. The -b cookies.txt flag tells curl to send cookies from that file on future requests. You must include both flags on every subsequent authenticated request.
6

Fetch your profile

With the session cookie in hand, call GET /api/ to retrieve the authenticated user’s full profile. This endpoint requires a valid token cookie — it will return 401 Unauthorized if the cookie is missing or the JWT has expired.
curl -s http://localhost:3000/api/ \
  -b cookies.txt
Successful response (200):
{
  "id": "uuid-string",
  "name": "María García",
  "email": "maria@example.com",
  "phone": "555-123-4567",
  "role": null,
  "username": "mariagarcia",
  "last_login": "2024-01-15T10:30:00.000Z"
}
7

List all properties

Property listing endpoints are publicly accessible — no session cookie is required to read data. Call GET /api/properties to retrieve the full catalog.
curl -s http://localhost:3000/api/properties
Successful response (200):
[
  {
    "id": "uuid-string",
    "title": "Modern 3-Bedroom House in Caracas",
    "description": "Spacious home with mountain views in a gated community.",
    "status": "Venta",
    "property_type": "Casa",
    "address": "Av. Principal 45",
    "city": "Caracas",
    "state": "Miranda",
    "price": 180000,
    "bedrooms": 3,
    "bathrooms": 2,
    "parking_lots": 1,
    "square_feet": 1800
  }
]
You can also filter by type or status:
# Filter by property type
curl -s http://localhost:3000/api/properties/type/Casa
curl -s http://localhost:3000/api/properties/type/Apartamento

# Filter by listing status
curl -s http://localhost:3000/api/properties/status/Venta
curl -s http://localhost:3000/api/properties/status/Alquiler
Valid type values are Casa, Apartamento, Terreno, and Comercial. Valid status values are Venta, Alquiler, and Ambas. Pass these values exactly as shown in the URL path.

Next Steps

Now that your server is running and you have made your first authenticated requests, explore the rest of the documentation:
  • Configuration — Learn about every environment variable, how CORS works, and how to obtain your Turso auth token.
  • API Reference — Full endpoint documentation with request/response schemas, error codes, and field-level descriptions.

Build docs developers (and LLMs) love