A robust, enterprise-grade RESTful API for managing orders. This service handles comprehensive CRUD operations for orders and their nested items, powered by a relational PostgreSQL database and guarded by JSON Web Token (JWT) authentication.
- Order Management: Full CRUD capabilities for bulk orders and individual item arrays.
- Relational Integrity: Implements proper one-to-many relationship mapping between Orders and Items.
- Secure: Endpoint access guarded by Bearer Token JWT authentication.
- Documented: Fully documented interactive OpenAPI/Swagger specification.
- Type-safe Database: Uses Prisma ORM for robust migrations and database queries.
- Language: JavaScript (Node.js)
- Framework: Express.js
- Database: PostgreSQL 15
- ORM: Prisma
- Authentication: JWT (jsonwebtoken)
- Documentation: Swagger UI & YAML
- Infrastructure: Docker & Docker Compose
Before running the application locally, ensure you have the following installed:
- Node.js (v18.x or v20.x recommended)
- npm (Node Package Manager)
- Docker and Docker Compose (to spin up the Postgres database)
git clone <your-repository-url>
cd <repository-directory>Install all necessary Node runtime packages and development tools:
npm installCreate a .env file at the root of the project to configure the database credentials and JWT secrets.
You can use the following default configuration for basic local development:
# Relational DB connection string (PostgreSQL)
DATABASE_URL="postgresql://postgres:password@localhost:5432/jitterbit_orders?schema=public"
# Application Config
PORT=3000
JWT_SECRET="super-secret-key-jitterbit-challenge-2026"Spin up the local PostgreSQL instance using Docker Compose:
docker-compose up -dOnce the container is running and healthy on port 5432, push the database schema using Prisma:
npx prisma db pushThis command instantly provisions the Order and Item tables defined in prisma/schema.prisma.
You can start the server in standard mode or development mode (which auto-restarts on save):
# Start standard server
npm start
# Run using Nodemon (Development)
npm run devThe application will report that it is running at http://localhost:3000.
A full interactive console mapping all endpoints, expected payloads, and query parameters is generated via Swagger.
Start the server, then navigate to: http://localhost:3000/api-docs
├── prisma/
│ └── schema.prisma # Database scheme definitions for Orders & Items
├── src/
│ ├── controllers/ # Business logic and payload handling
│ │ ├── authController.js # Handles login/token generation
│ │ └── orderController.js# Handles Order CRUD
│ ├── middlewares/ # Security and Interceptors
│ │ ├── authMiddleware.js # Parses/validates Bearer JWT
│ │ └── errorMiddleware.js# Standardized error emission wrapper
│ ├── routes/ # Express routing layer
│ │ ├── authRoutes.js
│ │ └── orderRoutes.js
│ ├── utils/ # Helper utilities
│ │ └── dataMapper.js # Data transformation and payload adaptation
│ ├── app.js # Core Express application assembly
│ └── server.js # HTTP Server bootstrap
├── swagger.yml # OpenAPI definition document
├── docker-compose.yml # PostgreSQL container infrastructure
└── package.json
- Client hits a
/orderor/authendpoint. - Express Router parses the JSON body.
authMiddleware.jsintercepts private/orderroutes, decoding and validating the JWT authorization header.- Payload hits
orderController.js. dataMapper.jsis leveraged to adapt external localized payload schemas (e.g.numeroPedido) gracefully into deep internal entity models (orderId).- Prisma communicates symmetrically to Postgres.
- Express responds with properly formatted standard data and correct HTTP Status codes (e.g.,
201 Created,400 Bad Request,404 Not Found).
| Command | Description |
|---|---|
npm start |
Boots standard Express server |
npm run dev |
Boots dev-server via Nodemon |
npx prisma studio |
Opens a web-based GUI to view your PostgreSQL tables locally |
docker-compose up -d |
Starts the database container |
docker-compose down |
Shuts down the database container |