first commit
This commit is contained in:
289
README.md
Normal file
289
README.md
Normal file
@@ -0,0 +1,289 @@
|
||||
# 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
|
||||
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd vaishnavi-backend
|
||||
npm install
|
||||
```
|
||||
|
||||
### 2. Environment Configuration
|
||||
|
||||
Copy the environment template and configure your variables:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Edit `.env` with your local database configuration:
|
||||
|
||||
```env
|
||||
# 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
|
||||
|
||||
1. **Create the database**:
|
||||
```sql
|
||||
-- Connect to PostgreSQL and create the database
|
||||
CREATE DATABASE vaishnavi_db;
|
||||
```
|
||||
|
||||
2. **Generate Prisma client and run migrations**:
|
||||
```bash
|
||||
# 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
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
The API will be available at `http://localhost:3000`
|
||||
|
||||
## 🔧 Troubleshooting
|
||||
|
||||
### Database Connection Issues
|
||||
|
||||
1. **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;"`
|
||||
|
||||
2. **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`
|
||||
|
||||
3. **Redis Connection Error** (Optional):
|
||||
- If you don't have Redis installed, you can comment out the REDIS_URL in your `.env` file
|
||||
- The application will work without Redis, but caching and background jobs won't be available
|
||||
|
||||
## 📚 API Endpoints
|
||||
|
||||
### Authentication
|
||||
- `POST /api/auth/register` - User registration
|
||||
- `POST /api/auth/login` - User login
|
||||
- `POST /api/auth/refresh` - Refresh JWT token
|
||||
- `POST /api/auth/logout` - User logout
|
||||
- `GET /api/auth/me` - Get current user profile
|
||||
|
||||
### Users
|
||||
- `GET /api/users/profile` - Get user profile
|
||||
- `PUT /api/users/profile` - Update user profile
|
||||
- `GET /api/users/addresses` - Get user addresses
|
||||
- `POST /api/users/addresses` - Add address
|
||||
- `GET /api/users/orders` - Get user orders
|
||||
- `GET /api/users/wishlist` - Get user wishlist
|
||||
|
||||
### Products
|
||||
- `GET /api/products` - Get all products (with filters)
|
||||
- `GET /api/products/:slug` - Get single product
|
||||
- `POST /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 order
|
||||
- `GET /api/orders` - Get user orders
|
||||
- `GET /api/orders/:id` - Get single order
|
||||
- `PUT /api/orders/:id/cancel` - Cancel order
|
||||
|
||||
### Wardrobe
|
||||
- `GET /api/wardrobe` - Get user's wardrobe
|
||||
- `POST /api/wardrobe/items` - Add item to wardrobe
|
||||
- `PUT /api/wardrobe/items/:id` - Update wardrobe item
|
||||
- `DELETE /api/wardrobe/items/:id` - Remove wardrobe item
|
||||
- `GET /api/wardrobe/recommendations` - Get outfit recommendations
|
||||
|
||||
### Admin
|
||||
- `GET /api/admin/dashboard` - Dashboard statistics
|
||||
- `GET /api/admin/users` - Manage users
|
||||
- `GET /api/admin/orders` - Manage orders
|
||||
- `GET /api/admin/products` - Manage products
|
||||
- `GET /api/admin/categories` - Manage categories
|
||||
- `GET /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 users
|
||||
- `ADMIN` - Full access to all endpoints
|
||||
- `MODERATOR` - Limited admin access
|
||||
- `SELLER` - 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
|
||||
|
||||
```bash
|
||||
# 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 server
|
||||
- `npm run dev` - Start development server with nodemon
|
||||
- `npm run build` - Generate Prisma client
|
||||
- `npm run lint` - Run ESLint
|
||||
- `npm run format` - Format code with Prettier
|
||||
- `npm run db:studio` - Open Prisma Studio
|
||||
- `npm 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
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
||||
3. Commit changes: `git commit -m 'Add amazing feature'`
|
||||
4. Push to branch: `git push origin feature/amazing-feature`
|
||||
5. 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**
|
||||
Reference in New Issue
Block a user