Skip to main content

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.

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.

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.
1

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.
2

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.
3

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.
4

Client is notified

Once a reservation’s reservation_accepted flag is set to true, the front-end or a notification layer can inform the client that their appointment has been confirmed, along with the finalised date and hour stored on the record.

Tech stack

Despacho Backend is intentionally lean. Every dependency has a concrete role in the application:
TechnologyRole
Node.js (ES modules)Runtime; the project declares "type": "module" in package.json, so all files use import/export syntax
Express 4HTTP server, routing, and middleware pipeline
MongoDB via Mongoose 8Primary data store; strictQuery mode enabled
jsonwebtokenSigns and verifies JWTs used for lawyer authentication
bcryptHashes lawyer passwords at registration and compares them at login
Socket.io 4Included as a dependency for real-time event delivery (e.g. notifying connected clients when a reservation is accepted)
multerMultipart form-data parsing for file upload endpoints
dotenvLoads PORT, SECRET, and MONGODB_URL from a .env file at startup
morganHTTP request logger (dev format) active in the Express middleware chain
nodemonDev-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:
despacho-backend/
├── package.json              # "type": "module" — ES module project
├── .env                      # Environment variables (not committed)
└── src/
    ├── index.js              # Entry point — starts HTTP server and connects DB
    ├── app.js                # Express app — middleware + route mounting
    ├── config.js             # Reads .env via dotenv, exports PORT/SECRET/MONGODB_URL
    ├── database/
    │   └── DB/
    │       └── mongooseDB.js # MongooseDB() connection helper
    ├── models/
    │   ├── LawyerUser.js     # Mongoose schema + bcrypt helpers for lawyer accounts
    │   └── FormReserve.js    # Mongoose schema for client reservation forms
    ├── controllers/
    │   ├── lawyerUserController.js    # create_lawyer_user, login_lawyer
    │   └── FormReserveController.js   # CRUD + accept logic for reservations
    ├── middleware/
    │   ├── tools/
    │   │   └── segurity.js   # Token middleware — verifies Bearer JWT on protected routes
    │   └── lib/
    │       └── Paginate.js   # Pagination middleware — sets skippag + limit on req.body
    └── routes/
        ├── lawyerUserRoutes.js   # Mounts under /api/lawyer/user
        └── formReserveRoutes.js  # Mounts under /api/form/reserve
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.

Build docs developers (and LLMs) love