Despacho Backend is a RESTful API built for law firms that need a reliable, structured system for handling client appointment requests. It solves the everyday operational challenge of tracking inbound reservation inquiries — clients submit their contact details, the legal service they need, and their preferred date and time, and the API stores those requests in MongoDB for lawyers to review, accept, modify, or remove through authenticated endpoints. Lawyers and administrators use the API directly (or through a connected front-end) to manage their caseload calendar, while clients interact only with the public reservation submission endpoint.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/despacho-backend/llms.txt
Use this file to discover all available pages before exploring further.
Quickstart
Install, configure, and run Despacho Backend locally in under 5 minutes, then make your first authenticated API request.
Configuration
Full reference for every environment variable — PORT, SECRET, and MONGODB_URL — with examples for local and Atlas setups.
Authentication
Learn how lawyer accounts are created, how JWTs are issued on login, and how the Token middleware protects routes.
Reservations
Understand the reservation lifecycle: from a client’s initial form submission through lawyer acceptance, modification, and removal.
How it works
Despacho Backend models a simple but complete appointment workflow. A client never needs an account — they submit a public form. The lawyer, however, must be authenticated before they can view or act on any reservation data.Client submits a reservation form
A client calls the public
POST /api/form/reserve/create endpoint with their full name, email, phone number, required legal service (chosen from a fixed enum of six practice areas), preferred date and hour, and an optional additional message. No authentication is required at this stage.Lawyer logs in
A lawyer navigates to (or calls)
POST /api/lawyer/user/login with their registered email and password. The API validates the credentials with bcrypt, signs a JWT with a 365-day expiry, stores the token on the user document, and returns it in the response body.Lawyer reviews and manages reservations
Using the JWT as a
Bearer token, the lawyer can list all pending reservations (/list/reservation-false), all accepted ones (/list/reservation-true), or the complete set (/list/reservation-all). They can accept and optionally reschedule a reservation via POST /api/form/reserve/accept/:reserveId/reserve, or permanently delete it with POST /api/form/reserve/remove/reservation/:reservationId.Tech stack
Despacho Backend is intentionally lean. Every dependency has a concrete role in the application:| Technology | Role |
|---|---|
| Node.js (ES modules) | Runtime; the project declares "type": "module" in package.json, so all files use import/export syntax |
| Express 4 | HTTP server, routing, and middleware pipeline |
| MongoDB via Mongoose 8 | Primary data store; strictQuery mode enabled |
| jsonwebtoken | Signs and verifies JWTs used for lawyer authentication |
| bcrypt | Hashes lawyer passwords at registration and compares them at login |
| Socket.io 4 | Included as a dependency for real-time event delivery (e.g. notifying connected clients when a reservation is accepted) |
| multer | Multipart form-data parsing for file upload endpoints |
| dotenv | Loads PORT, SECRET, and MONGODB_URL from a .env file at startup |
| morgan | HTTP request logger (dev format) active in the Express middleware chain |
| nodemon | Dev-mode runner — npm run dev restarts the process on file changes |
Project structure
The repository follows a conventional Express layout with each concern in its own directory:The project uses ES modules throughout —
"type": "module" is set in package.json. This means you must use import/export syntax in any new files you add, and Node.js will reject CommonJS require() calls. The dev script runs nodemon --exec node src/index.js rather than a transpiler, so Node.js 14.13+ (ideally 18+) is required.