A production-oriented backend system designed for a clothing e-commerce platform.
This project emphasizes clean architecture, scalable MongoDB data modeling,
RBAC-driven authorization, and a comprehensive automated testing setup using
mongodb-memory-server, vitest, and supertest.
This repository highlights my work on the database system, schema design, validation rules, and backend structure required for real-world e-commerce inventory, user management, and product workflows.
Below is a high-level view of how major components interact within the backend:
graph TD
A[Client App / Postman] -->|HTTP Requests| B(Express API - app.js / routes);
B -->|Routing & Middleware| C(Controllers);
C -->|Business Logic| D(Models - Mongoose Schemas);
D -->|ODM Operations| E[MongoDB];
%% Styling for clarity
style A fill:#e0e0e0,stroke:#333
style B fill:#f9f,stroke:#333
style C fill:#fcc,stroke:#333
style D fill:#ccf,stroke:#333
style E fill:#cfc,stroke:#333
This diagram showcases how your test system works using an in-memory MongoDB instance.
graph TD
A[Vitest - Test Runner Engine] --> B(Supertest - API Request Testing);
B --> C[Express App];
C --> D(MongoDB-Memory-Server - In-memory Isolated Database);
style A fill:#ffc,stroke:#333
style B fill:#ddf,stroke:#333
style D fill:#fcc,stroke:#333
- Zero external dependencies
- Fully isolated environments
- Higher test reliability
- Extremely fast execution
The system uses a modular and scalable schema layout supporting:
- Products, Categories, Users, Reviews
- Embedded + referenced document patterns
- Schema-level validation rules
- Schema inheritance for product subtypes
- Timestamps, indexes & lifecycle hooks
Products share a base schema, while specialized product types extend it:
- Top-wear
- Bottom-wear
Each subtype inherits common product fields and adds category-specific attributes. Examples include:
- Top-wear: sleeve, neckline
- Bottom-wear: length, rise
This structure supports rich filtering and scalable product categorization.
Each product supports:
- Multiple variants (e.g., colors)
- Dynamic size arrays
- Stock tracking per size
- Style objects per product type
The User schema includes:
- Secure password hashing
- Token rotation system
- Multiple addresses per user
- Data sanitization
- Schema-level validation rules
- Role-based access control (RBAC)
Admin and customer roles enforce access boundaries throughout the application.
Categories are stored as separate documents, enabling structured filtering and
category-specific product queries.
Across the schemas:
- JSON schema validation for required fields
- Email pattern matching
- Minimum password length enforcement
- Enum restrictions for user roles
- Automatic timestamps
- Optional indexing for performance
The system uses a clean RBAC structure:
- Admin Users: Can create, update, and manage products & categories
- Customers: Can register, log in, manage addresses, and purchase items
Authorization logic is tied directly to user roles in the database, ensuring strong separation of privileges.
The project includes a dedicated /tests folder covering:
- Authentication & token rotation
- RBAC access control
- Product and category endpoint behavior
- Validation errors & edge cases
- CRUD operations with in-memory MongoDB
| Tool | Purpose |
|---|---|
vitest |
Test runner |
supertest |
HTTP endpoint testing |
mongodb-memory-server |
In-memory database instance for isolated, fast testing |
- No external DB required to run tests
- Tests run in milliseconds
- Ensures consistent, repeatable results
- Suitable for CI/CD integration
The current test suite covers 96 passing tests, ensuring stability and confidence in core functionality.
- Node.js, Express
- MongoDB, Mongoose
- Vitest, Supertest
- mongodb-memory-server
- JSON Schema Validation
- JWT-based token and refresh-token strategy
./
├── logs/
└── error.log
├── src/
├── config/
├── controllers/
├── errors/
├── middleware/
├── models/
├── routes/
├── utils/
├── validators/
├── app.js
└── server.js
├── tests/
├── auth.test.js
├── product.test.js
├── category.test.js
├── review.test.js
└── user.test.js
├── .env
├── .gitignore
└── package.json
This ReadMe highlights the engineering work that went into building:
- A clean, scalable MongoDB data model
- Security-aware authorization systems
- A reliable, high-coverage automated testing environment