Backend API for Clothica built with Node.js, Express and MongoDB.
- 🔐 JWT Authentication (Access & Refresh Tokens)
- 🛡️ Security (Helmet, CORS, Rate Limiting)
- ✅ Request Validation (Celebrate/Joi)
- 📚 API Documentation (Swagger)
- 🏗️ Functional Architecture
- 🔄 Centralized Error Handling
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcrypt
- Validation: Celebrate (Joi wrapper)
- Security: Helmet, CORS, express-rate-limit
- Documentation: Swagger (swagger-jsdoc, swagger-ui-express)
- Module System: ES Modules (type: "module")
- Architecture: Functional Programming
clothica-shop-backend/
├── src/
│ ├── server.js
│ ├── admin/
│ │ ├── admin.config.js
│ │ ├── auth.js
│ │ └── resources.js
│ ├── constants/
│ │ ├── colors.js
│ │ ├── orderStatuses.js
│ │ └── time.js
│ ├── controllers/
│ │ ├── authController.js
│ │ ├── userController.js
│ │ ├── categoryController.js
│ │ ├── goodController.js
│ │ ├── orderController.js
│ │ ├── feedbackController.js
│ │ └── subscriptionController.js
│ ├── db/
│ │ └── connectMongoDB.js
│ ├── middleware/
│ │ ├── authenticate.js
│ │ ├── logger.js
│ │ ├── errorHandler.js
│ │ ├── notFoundHandler.js
│ │ ├── rateLimitAuth.js
│ │ ├── rateLimitSearch.js
│ │ ├── requireAdmin.js
│ │ ├── processCategoryFilter.js
│ │ └── multer.js
│ ├── models/
│ │ ├── user.js
│ │ ├── session.js
│ │ ├── category.js
│ │ ├── good.js
│ │ ├── order.js
│ │ ├── feedback.js
│ │ ├── subscription.js
│ │ └── counter.js
│ ├── routes/
│ │ ├── authRoutes.js
│ │ ├── userRoutes.js
│ │ ├── categoryRoutes.js
│ │ ├── goodRoutes.js
│ │ ├── orderRoutes.js
│ │ ├── feedbackRoutes.js
│ │ └── subscriptionRoutes.js
│ ├── seeds/
│ │ └── setCounter.js
│ ├── services/
│ │ ├── auth.js
│ │ └── telegram.js
│ ├── templates/
│ │ └── reset-password-email.html
│ ├── utils/
│ │ ├── ctrlWrapper.js
│ │ ├── modifyFileToCloudinary.js
│ │ └── sendMail.js
│ ├── validations/
│ │ ├── authValidation.js
│ │ ├── categoriesValidation.js
│ │ ├── goodsValidation.js
│ │ ├── ordersValidation.js
│ │ ├── feedbacksValidation.js
│ └── └── subscriptionsValidation.js
├── config/
│ └── swagger.js
├── .env.example
├── .gitignore
├── package.json
└── README.md
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd clothica-shop-backend- Install dependencies:
npm install- Create environment file:
cp .env.example .env- Configure environment variables in
.env.
Development mode with auto-restart:
npm run devProduction mode:
npm startOnce the server is running, access the Swagger documentation at:
/api-docs
POST /api/auth/registerPOST /api/auth/loginPOST /api/auth/logoutPOST /api/auth/refreshPOST /api/auth/request-password-resetPOST /api/auth/reset-password
GET /api/users/profilePATCH /api/users/profileDELETE /api/users/profileGET /api/users/profile/telegram-link
GET /api/categoriesGET /api/categories/:idPOST /api/categoriesPATCH /api/categories/:idDELETE /api/categories/:idPATCH /api/categories/:id/img
GET /api/goodsGET /api/goods/:idPOST /api/goodsPATCH /api/goods/:idDELETE /api/goods/:id
GET /api/ordersPOST /api/ordersPATCH /api/orders/:id/status
GET /api/feedbacksPOST /api/feedbacks
POST /api/subscriptions
Authentication endpoints (/register and /login) are rate-limited to 10 requests per 15 minutes per IP address to prevent brute-force attacks.
- Passwords are hashed using bcrypt with salt rounds
- Minimum password length: 8 characters
- Maximum password length: 128 characters
- Access tokens expire in 15 minutes
- Refresh tokens expire in 1 day
- Tokens are verified on protected routes
- Helmet middleware sets secure HTTP headers
- CORS configured for cross-origin requests
- name: Required, string, max 32 characters
- phone: Required, string, max 13 characters
- password: Required, string, min 8 characters, max 128 characters
- phone: Required, string, max 13 characters
- password: Required, string
The API uses centralized error handling with consistent error responses:
{
"success": false,
"message": "Error message",
"errors": [...] // Optional validation errors
}Common HTTP status codes:
200- Success201- Created400- Bad Request (validation errors)401- Unauthorized404- Not Found409- Conflict (duplicate resource)429- Too Many Requests (rate limit exceeded)500- Internal Server Error
This project follows a functional programming approach:
- Controllers: Pure functions that handle requests and responses
- Services: Pure functions that contain business logic
- Models: Mongoose schemas with named exports
- Middleware: Functions for request processing
- Error Handling: Centralized with
ctrlWrapperutility