Elentra Car APIA Node.js car management REST API on Express and MongoDB

A case study in designing the backend for a car management system: RESTful vehicle endpoints, JWT authentication and authorization, Mongoose data models, central error handling and a Postman test collection.

Category
Backend
Industry
Automotive
Platform
REST API
Status
Private project
  • RESTendpoints for every car operation
  • JWTstateless auth and authorization
  • 1central error handler
  • Postmantested, failure cases included
Elentra Car API
Elentra website hero reading Book Your New Eco-Friendly Ride, with a silver car beside a charging station and specification tiles for top speed, motor output, acceleration and engine power
Overview

Elentra Car API: a Node.js REST API for car management systems

Elentra Car API is a Node.js car management REST API I architected and built as the backend for car management systems, on Express, MongoDB and Mongoose.

It handles vehicle data operations, user management and third-party integrations through RESTful Express endpoints, with JWT for authentication and authorization and Postman for testing. It was designed to support high-traffic applications.

The screenshot shows the Elentra front end; this case study is about the API side. A client sees predictable resource URLs for cars and users, a token check before anything protected runs, and errors that come back as consistent JSON whatever went wrong.

Role
Backend developer
Industry
Automotive
Audience
Car management applications and their users
Platform
REST API
Type
REST API backend
Category
Backend
Stack
Node.js, Express.js, MongoDB, JWT
Status
Private project
The challenge

Why a car management system needs a purpose-built REST API

A car management system asks more of its data than a typical CRUD app, because the same vehicles are read in different shapes by different screens.

Each vehicle record holds many fields: a list needs a summary, a detail page needs everything, an admin view needs to edit it. Reads far outnumber writes, so the backend has to answer common queries quickly without sending more than each screen needs.

On top of the vehicle data, the API manages user accounts, decides which users may do what, and exchanges data with outside services through third-party integrations. It was also meant to support high-traffic applications, which ruled out designs that only hold up under light load, such as keeping session state in one server's memory.

How things worked before Elentra Car API, compared with Elentra Car API
Before Elentra Car APIWith Elentra Car API
Every screen fetching the full vehicle recordLean list responses, with the full document from the detail route
Session state held in one server's memoryA signed JWT that any instance can verify
Validation repeated, or missed, in each handlerValidation declared once in the Mongoose schemas
Errors in a different shape from every routeOne error handler and consistent JSON

The brief I set myself

  • PredictableRoutes a client developer can guess.
  • StatelessAny instance can verify any request.
  • Read-firstFast answers to the queries clients make most.
  • ConsistentEvery error in the same JSON shape.
My role

My role: architecting the Elentra Car API backend

I architected and developed the Elentra backend, from the route structure and the Mongoose models for vehicles and users to the Postman collection used to test it.

Between those two ends sat the authentication and authorization layer, the error handling and logging middleware, and the third-party integrations. Because the API has no screen of its own, the Postman collection was also how I checked each route as it was built.

Scope of work on Elentra Car API
RoutesResource-based Express routers and controllers for cars and users, with deliberate status codes.
DataMongoose schemas for vehicles and users, with validation and indexes on the fields used to filter and sort.
AuthA JWT authentication middleware, and a second middleware for what each user may do.
ReliabilityOne Express error handler, logging middleware, and wrapped calls to third-party services.
TestingA Postman collection with a request for each endpoint, including the failure cases.
How it works

How a request moves through the Elentra Car API

Every protected request takes the same path: its token is checked, its permissions are checked, the data goes through a Mongoose model, and a consistent response comes back.

  1. Step 1

    Authenticate

    The first middleware verifies the signed JWT on a protected route. Any instance can do this on its own, with no shared session store to consult.

    Rejected
    Missing tokenExpired token
  2. Step 2

    Authorize and route

    A second middleware checks what that user is allowed to do. Only then does the request reach the router and controller for its resource.

    Resources
    CarsUsers
  3. Step 3

    Read or write through Mongoose

    The controller works through the Mongoose model. Writes are validated against the schema, and list reads return only the fields a list view needs.

    Schema checks
    Required fieldsTypesAllowed values
  4. Step 4

    Respond

    A success comes back as JSON with a deliberate status code. A failure goes to the single error handler, which returns consistent JSON and logs the detail on the server.

    Handled errors
    ValidationMissing recordUnexpected exception
Key features

Elentra Car API features: endpoints, auth and testing

The features are the things a client developer depends on: predictable endpoints for cars and users, authentication handled once, and errors that always look the same.

RESTful endpoints for every car operation

Listing, reading, creating, updating and removing vehicles through predictable resource URLs.

JWT authentication and authorization

Protected routes are checked by middleware before any controller runs.

User management

User accounts are a resource of their own, with permissions decided in middleware.

Optimised MongoDB data models

Vehicle information defined as Mongoose schemas with validation and indexes.

Error handling and logging middleware

Errors come back in one consistent format, and the server records what went wrong.

Third-party integrations

Connections to outside services, wrapped so a failing service returns a clear error instead of crashing the process.

A Postman collection

A request for each endpoint, used to test the API as it was built and as a reference for client developers.

Designed for high traffic

Stateless authentication and indexed reads, the two choices that design rests on.

Architecture

How the Elentra Car API is built: Node.js architecture and stack

Four decisions shaped the API: resource-based routes, models built around how cars are read, stateless authentication, and one place for every error.

API

Resource-based REST routes in Express

Cars and users are modelled as resources with predictable URLs and standard HTTP methods. Each resource has its own Express router and controller, which keeps route files short and lets a client developer guess an endpoint without opening the code. Status codes are chosen deliberately, so a client can tell a missing car from a validation failure or a permission problem.

Data

Mongoose models built around how cars are read

Since most traffic is reads, the vehicle schema is shaped for the queries clients make most often, with indexes on the fields used to filter and sort listings. List endpoints return only the fields a list view needs, and the full document comes from the detail route. Schema and index design did the same job at a larger scale in the Cyborg Gaming Node.js backend, where it cut query times.

Security

Stateless authentication with JWT

For an API expected to take heavy traffic, server-side sessions would force every instance to share a session store. A signed JWT lets any instance verify a request on its own. One middleware checks the token, a second checks what that user is allowed to do, and both run before the controller, so permission logic stays out of the individual handlers.

Reliability

One error handler and logging middleware

Controllers pass failures on to a single Express error handler instead of each writing its own response. That handler turns validation errors, missing records and unexpected exceptions into consistent JSON with the correct status code, and logs the detail on the server, so clients never receive a stack trace while I still have one to debug from.

The Elentra Car API tech stack

Technologies used in Elentra Car API and what each one does
TechnologyWhat it does in Elentra Car API
Node.jsThe runtime for the API.
Express.jsResource routers, controllers, and the auth, logging and error middleware.
MongoDBStorage for vehicle and user data, indexed for the common list queries.
JWTStateless authentication that any instance can verify.
MongooseSchemas with validation and indexes for vehicles and users.
PostmanA collection with a request for every endpoint, failure cases included.
Challenges

Challenges in building a Node.js REST API, and how I solved them

Three parts needed the most care: keeping vehicle data valid from every entry point, outside services that fail, and testing an API with no screen of its own.

Keeping vehicle data valid from every entry point

Problem

Cars can be written from more than one place, including the third-party integrations. If validation lives only in a route handler, every new entry point is another chance for incomplete or mistyped records to reach the database.

Solution

Validation sits in the Mongoose schemas, where required fields, types and allowed values are declared once. Anything that writes a car goes through the same model, so the collection only holds records the clients can depend on.

Outside services that fail on their own schedule

Problem

An integration is code that depends on someone else's uptime. A slow or failing outside service should not take a car request down with it, or leave a client waiting until it times out.

Solution

Calls to outside services are wrapped so their failures are caught, logged through the same middleware and returned as a clear error response instead of crashing the process. The rest of the API keeps answering while an integration is unavailable.

Testing an API that has no screen of its own

Problem

A backend's bugs should not wait for a front end to discover them. Testing by hand with one-off requests is easy to skip and impossible to repeat exactly after a change.

Solution

I kept a Postman collection with a request for each endpoint, including the failure cases: missing or expired tokens, invalid ids and malformed vehicle data. Running the collection again after a change showed quickly whether anything had broken, and it gave client developers a working reference for every route.

Results

Results: a car management REST API a front end can build on

The result is a Node.js car management REST API a front end can build on, with predictable routes, authentication handled once and errors in one shape.

Routes for vehicles and users follow one pattern, authentication runs once in middleware before any controller, and errors come back in the same shape every time. It was designed for high-traffic applications, and stateless authentication and indexed reads are the two choices that design rests on.

The token-based approach is the same one behind the team management system with three-tier access control, applied here to an API that serves other applications rather than its own interface.

What's next for Elentra Car API

Next I would add rate limiting and response caching for the busiest read endpoints, and publish OpenAPI documentation generated from the routes so client developers are not relying on the Postman collection alone.

FAQ

Elentra Car API: frequently asked questions

Short answers to the questions developers ask most about the Elentra Car API, its authentication and how it was tested.

What is Elentra Car API?

Elentra Car API is a Node.js REST API built as the backend for car management systems. It handles vehicle data operations, user management and third-party integrations through RESTful Express endpoints.

What is Elentra Car API built with?

Node.js and Express.js for the API, MongoDB with Mongoose for vehicle and user data, JWT for authentication and authorization, and Postman for testing.

How does Elentra Car API handle authentication?

With a signed JWT. One middleware verifies the token, a second checks what that user is allowed to do, and both run before any controller, so permission logic stays out of the individual handlers.

Why use JWT instead of sessions for a car management API?

The API was designed for high-traffic applications. Server-side sessions would force every instance to share a session store, while a signed JWT lets any instance verify a request on its own.

How was the Elentra Car API tested?

With a Postman collection holding a request for each endpoint, including missing or expired tokens, invalid ids and malformed vehicle data. Running it again after a change showed quickly whether anything had broken.

What happens when a third-party service fails?

Calls to outside services are wrapped, so a failure is caught, logged and returned as a clear error response. The rest of the API keeps answering while the integration is unavailable.

Who built Elentra Car API?

Muhammad Abdullah Awais, a full-stack developer based in Pakistan. I architected and developed the backend, and I am available for freelance and full-time backend work like it.

Available for new builds

Need a full-stack developer for a product like this?

I work remotely with teams in the US, Canada, the UK, Europe and the Gulf, and with clients across Pakistan. Based in Pakistan (PKT, UTC+5), available for freelance and full-time roles.