A scalable and robust backend architecture of E-commerce built with Node.js, TypeScript, Redis, and Docker.
Backend API for an E-commerce platform featuring JWT authentication, Redis caching, Zod validation, and MongoDb integration — optimized for performance and maintainability.
- 🌟 Features
- 🐳 Dockerized Deployment — Fully containerized setup for seamless deployment across environments; CI/CD pipeline planned using Jenkins or GitHub Actions.
- 🧰 Tech Stack
- ⚙️ Installation & Setup
- 📁 Folder Structure
- Postman Collection Link
- Swagger
- Some learnings and why I used a particualar stack
- Future plannings and integration
⚡ Optimized Performance with Redis — Implemented Redis for session and cart storage, reducing cart fetch time from 210 ms → 6 ms (performance proof in image section).
🔐 Advanced Authentication System — Secure login using JWT and Redis, with features like rate limiting, token rotation, and session invalidation for enhanced security.
🐳 Dockerized Deployment — Fully containerized setup for seamless deployment across environments; CI/CD pipeline planned using Jenkins or GitHub Actions.
Backend: Node.js, Express, TypeScript, Redis, MongoDb
Others: Docker, Swagger API Docs
Run the following commands on your bash :-
git clone https://github.com/Anshikakalpana/ecommerce-backend.git
cp .env.example .env
** docker compose up --build **
Your backend API will now be available at: " http://localhost:3000 "
🧩 Tech Notes
The backend connects to a Redis container defined in docker-compose.yml.
Local or external Redis instances are not supported unless you modify the configuration.
Stop containers anytime using: docker compose down
Let’s try to understand every file in short. (I’m explaining each file in 1–2 lines. Please read the whole code to understand it clearly.)
The main folder is the src folder, which contains everything about how the backend works.
server.ts
Ensures the database connection is properly established before the app starts.
index.ts
The soul of the system — initializes the Express server, connects all routes, and starts the backend.
swagger.ts
Handles API documentation setup using Swagger. It generates interactive documentation for testing and exploring API endpoints.
app folder
ontains the core logic of the application divided into modules:
User Section
Product Section
Cart Section
Each section follows a consistent structure with models, services, controllers, and routes.
models
Defines the schemas, types, and validations for each entity using Zod for type safety and schema validation.
services
Contains all the business logic. For example, addProductService allows a seller to add a product to the database.
controllers
Acts as the bridge between routes and services — validates incoming data, calls the right service, and returns appropriate responses.
middlewares
This folder contains 4 files right now
Currently includes four middleware files:
AuthMiddleware – Ensures the user is authenticated.
AuthRolesMiddleware – Checks if the user has permission (role) to perform certain actions.
RateLimiter – Protects routes from abuse and excessive API calls.
routes
Defines which API path triggers which controller function — in short, it maps endpoints to functionalities.
this was all about the src folder
.env
Contains environment variables and secrets (e.g., database URL, JWT keys).
package.json
Contains project dependencies, scripts, and configuration details for building, running, and managing the backend.
⚙️ Note: You don’t need to install dependencies manually — Docker automatically installs everything during the build process as defined in the Dockerfile.
https://drive.google.com/drive/folders/1jWixXb3RpZDIBUdcAlTQ3vXTSW0qgbbT?usp=drive_link
📘 Swagger Documentation
This project includes integrated API documentation using Swagger (OpenAPI 3.0) to make testing and exploring endpoints effortless.
Once your containers are running, the Swagger UI will be available at: 👉 http://localhost:3000/api-docs
🔍 What You Can Do
Explore all API endpoints (User, Product, Cart, etc.) interactively
Test requests and responses directly from your browser
View schema definitions and expected request formats
Automatically visualize authentication headers and parameters
⚙️ Note: The Swagger setup is defined in the swagger.ts file inside the src folder. It automatically reads route metadata and schemas to generate live API documentation.
Redis, being an in-memory data store, is utilized across multiple layers of this backend to optimize both speed and security. It powers key functionalities such as:
1- Rate Limiting: Prevents API abuse by tracking request counts per user/session.
2- Token & Session Management: Manages JWTs, refresh tokens, and session invalidation efficiently.
3- Cart Caching: Stores user carts in Redis for ultra-fast access — reducing cart fetch time from 125 ms → 6 ms.
Performance proof attached in the image section and Postman collection.
Used for schema validation and runtime type checking. Ensures every request payload strictly follows the defined data model, improving reliability and reducing runtime errors.
Provides type safety across the entire codebase. Helps catch errors during development, improves code maintainability, and enhances developer productivity with autocompletion and static checks.
Serves as the primary database for persistent storage. Handles user data, product listings, and cart details efficiently with schema flexibility and high scalability.
1- Subscription Module: Implement a premium subscription system (e.g., “Prime”) to offer users benefits like faster delivery, exclusive deals, and early access to new products.
2- Delivery Tracking & Updates: Integrate delivery management services with real-time order tracking, automated status updates, and notifications to enhance user experience.
3- Extended RBAC (Role-Based Access Control): Expand role management to include delivery agents, managers, and admins — ensuring secure, granular permission handling for each user type.
4- CI/CD Integration: Set up automated deployment pipelines using GitHub Actions or Jenkins for continuous integration and testing.
