8.5 KiB
Vaishnavi Creation - E-commerce Backend API
A comprehensive e-commerce backend API built with Node.js, Express, PostgreSQL, and MongoDB, designed for fashion and wardrobe management with AI-powered features.
🚀 Tech Stack
- Backend: Node.js 18+, Express.js
- Databases:
- PostgreSQL (transactional data) with Prisma ORM
- MongoDB (flexible product/wardrobe documents) with Mongoose
- Caching & Jobs: Redis with BullMQ
- File Storage: AWS S3
- Authentication: JWT with bcrypt
- Containerization: Docker
- CI/CD: GitHub Actions
📁 Project Structure
vaishnavi-backend/
├── src/
│ ├── config/ # Database and app configuration
│ ├── controllers/ # Route controllers
│ ├── middleware/ # Custom middleware (auth, error handling)
│ ├── models/ # Database models
│ │ └── mongodb/ # MongoDB models (Product, Wardrobe)
│ ├── routes/ # API routes
│ ├── services/ # Business logic services
│ ├── jobs/ # Background job processors
│ ├── utils/ # Utility functions
│ ├── types/ # TypeScript type definitions
│ └── server.js # Application entry point
├── prisma/ # Prisma schema and migrations
├── tests/ # Test files
└── package.json
🛠️ Setup & Installation
Prerequisites
- Node.js 18+
- PostgreSQL 15+ (running locally)
- MongoDB 7+ (running locally)
- Redis 7+ (optional, for caching and job queues)
1. Clone and Install Dependencies
git clone <repository-url>
cd vaishnavi-backend
npm install
2. Environment Configuration
Copy the environment template and configure your variables:
cp .env.example .env
Edit .env with your local database configuration:
# Database URLs - Update with your local credentials
DATABASE_URL="postgresql://postgres:yourpassword@localhost:5432/vaishnavi_db"
MONGODB_URI="mongodb://localhost:27017/vaishnavi_products"
REDIS_URL="redis://localhost:6379"
# JWT Secrets - Change these in production!
JWT_SECRET="your-super-secret-jwt-key"
JWT_REFRESH_SECRET="your-super-secret-refresh-key"
# AWS S3 Configuration (Optional)
AWS_ACCESS_KEY_ID="your-aws-access-key"
AWS_SECRET_ACCESS_KEY="your-aws-secret-key"
AWS_S3_BUCKET="vaishnavi-files"
3. Database Setup
PostgreSQL Setup
- Create the database:
-- Connect to PostgreSQL and create the database
CREATE DATABASE vaishnavi_db;
- Generate Prisma client and run migrations:
# Generate Prisma client
npm run db:generate
# Run migrations to create tables
npm run db:migrate
# Seed database with sample data
npm run db:seed
MongoDB Setup
MongoDB will automatically create collections when first accessed. Make sure your MongoDB service is running on the default port (27017).
Redis Setup (Optional)
If you have Redis installed locally, make sure it's running on port 6379. If not, you can comment out the Redis URL in your .env file.
4. Start Development Server
npm run dev
The API will be available at http://localhost:3000
🔧 Troubleshooting
Database Connection Issues
-
PostgreSQL Connection Error:
- Ensure PostgreSQL is running:
sudo systemctl start postgresql(Linux) or start PostgreSQL service (Windows) - Check your connection string in
.env - Verify the database exists:
psql -U postgres -c "CREATE DATABASE vaishnavi_db;"
- Ensure PostgreSQL is running:
-
MongoDB Connection Error:
- Ensure MongoDB is running:
sudo systemctl start mongod(Linux) or start MongoDB service (Windows) - Check if MongoDB is listening on port 27017:
netstat -an | grep 27017
- Ensure MongoDB is running:
-
Redis Connection Error (Optional):
- If you don't have Redis installed, you can comment out the REDIS_URL in your
.envfile - The application will work without Redis, but caching and background jobs won't be available
- If you don't have Redis installed, you can comment out the REDIS_URL in your
📚 API Endpoints
Authentication
POST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/refresh- Refresh JWT tokenPOST /api/auth/logout- User logoutGET /api/auth/me- Get current user profile
Users
GET /api/users/profile- Get user profilePUT /api/users/profile- Update user profileGET /api/users/addresses- Get user addressesPOST /api/users/addresses- Add addressGET /api/users/orders- Get user ordersGET /api/users/wishlist- Get user wishlist
Products
GET /api/products- Get all products (with filters)GET /api/products/:slug- Get single productPOST /api/products- Create product (Admin)PUT /api/products/:id- Update product (Admin)DELETE /api/products/:id- Delete product (Admin)
Orders
POST /api/orders- Create new orderGET /api/orders- Get user ordersGET /api/orders/:id- Get single orderPUT /api/orders/:id/cancel- Cancel order
Wardrobe
GET /api/wardrobe- Get user's wardrobePOST /api/wardrobe/items- Add item to wardrobePUT /api/wardrobe/items/:id- Update wardrobe itemDELETE /api/wardrobe/items/:id- Remove wardrobe itemGET /api/wardrobe/recommendations- Get outfit recommendations
Admin
GET /api/admin/dashboard- Dashboard statisticsGET /api/admin/users- Manage usersGET /api/admin/orders- Manage ordersGET /api/admin/products- Manage productsGET /api/admin/categories- Manage categoriesGET /api/admin/coupons- Manage coupons
🔐 Authentication
The API uses JWT-based authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
User Roles
CUSTOMER- Default role for registered usersADMIN- Full access to all endpointsMODERATOR- Limited admin accessSELLER- Can manage their own products
🗄️ Database Schema
PostgreSQL (Prisma)
- Users & Authentication
- Orders & Transactions
- Addresses
- Reviews & Ratings
- Wishlist & Cart
- Categories & Coupons
- System Configuration
MongoDB (Mongoose)
- Products (flexible schema for variants, images, AI tags)
- Wardrobe (user clothing collections with AI analysis)
🚀 Deployment
Environment Variables for Production
Ensure all production environment variables are set:
- Database URLs (production databases)
- JWT secrets (strong, unique values)
- AWS credentials
- Email/SMS service credentials
Deployment Options
You can deploy this application to various platforms:
- Heroku: Use the Procfile and configure environment variables
- AWS EC2: Set up Node.js environment and configure databases
- DigitalOcean App Platform: Connect your repository and configure environment variables
- Railway: Connect your GitHub repository for automatic deployments
- Vercel: For serverless deployment (with some modifications)
🧪 Testing
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage
📝 Scripts
npm start- Start production servernpm run dev- Start development server with nodemonnpm run build- Generate Prisma clientnpm run lint- Run ESLintnpm run format- Format code with Prettiernpm run db:studio- Open Prisma Studionpm run db:migrate- Run database migrations
🔄 Background Jobs
The application uses BullMQ with Redis for processing:
- AI image tagging for wardrobe items
- Email notifications
- Image processing and optimization
- Recommendation engine updates
📊 Monitoring & Logging
- Health check endpoint:
GET /health - Structured logging with Morgan
- Error tracking and reporting
- Database connection monitoring
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
📄 License
This project is licensed under the ISC License.
🆘 Support
For support and questions:
- Create an issue in the repository
- Check the API documentation at
/api/docs - Review the health check at
/health
Built with ❤️ for Vaishnavi Creation