{"id":21767476,"url":"https://github.com/saketkothari/tshirt-store-backend-api","last_synced_at":"2026-02-27T03:01:52.137Z","repository":{"id":149769935,"uuid":"491812059","full_name":"SaketKothari/tshirt-store-backend-api","owner":"SaketKothari","description":"A robust backend API for managing an online t-shirt store, handling product listings, orders, and customer data.","archived":false,"fork":false,"pushed_at":"2025-04-29T17:00:33.000Z","size":430,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T18:20:12.056Z","etag":null,"topics":["api","authentication","bcryptjs","cloudinary","cookie-parser","ejs","expressjs","file-upload","jwt-token","mongodb","mongoose","morgan-middleware","node-js","nodemailer","nodemon","stripe","swagger"],"latest_commit_sha":null,"homepage":"https://tshirt-store.onrender.com/api-docs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SaketKothari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-13T08:09:44.000Z","updated_at":"2025-04-29T17:00:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"e5cc961c-ac76-4710-9526-8587121198a6","html_url":"https://github.com/SaketKothari/tshirt-store-backend-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SaketKothari/tshirt-store-backend-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaketKothari%2Ftshirt-store-backend-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaketKothari%2Ftshirt-store-backend-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaketKothari%2Ftshirt-store-backend-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaketKothari%2Ftshirt-store-backend-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SaketKothari","download_url":"https://codeload.github.com/SaketKothari/tshirt-store-backend-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaketKothari%2Ftshirt-store-backend-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29883111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T23:51:21.483Z","status":"online","status_checked_at":"2026-02-27T02:00:06.759Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","authentication","bcryptjs","cloudinary","cookie-parser","ejs","expressjs","file-upload","jwt-token","mongodb","mongoose","morgan-middleware","node-js","nodemailer","nodemon","stripe","swagger"],"created_at":"2024-11-26T13:25:27.525Z","updated_at":"2026-02-27T03:01:52.132Z","avatar_url":"https://github.com/SaketKothari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 👕 T-Shirt Store Backend API\n\nA production-ready RESTful API for an e-commerce t-shirt store built with Node.js, Express, and MongoDB.\n\n[![Live API](https://img.shields.io/badge/API-Live-brightgreen)](https://tshirt-store.onrender.com/api-docs/)\n[![Node.js](https://img.shields.io/badge/Node.js-18+-green)](https://nodejs.org/)\n[![Express](https://img.shields.io/badge/Express-4.x-blue)](https://expressjs.com/)\n[![MongoDB](https://img.shields.io/badge/MongoDB-8.x-green)](https://www.mongodb.com/)\n[![License](https://img.shields.io/badge/License-ISC-yellow)](./LICENSE)\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"https://user-images.githubusercontent.com/81709725/171385115-0a72bda1-fbc2-40c5-aa03-8acbb0912f6d.png\" alt=\"T-Shirt Store API\" /\u003e\n\u003c/p\u003e\n\n## 📚 API Documentation\n\nExplore the complete API documentation with interactive testing:\n\n🔗 **[Live Swagger Documentation](https://tshirt-store.onrender.com/api-docs/)**\n\n---\n\n## ✨ Features\n\n### 🔐 Authentication \u0026 Authorization\n\n- **JWT-based authentication** with httpOnly cookies\n- **Role-based access control** (User, Manager, Admin)\n- Secure password hashing with bcrypt\n- Password reset via email tokens\n\n### 👤 User Management\n\n- User registration with profile photo upload\n- Login/Logout with secure token handling\n- Forgot password \u0026 reset password flow\n- User dashboard with profile updates\n- Admin can manage all users\n\n### 🛍️ Product Management\n\n- Full CRUD operations for products\n- Multiple product images via Cloudinary\n- Product categories (shortsleeves, longsleeves, sweatshirt, hoodies)\n- Product search, filtering \u0026 pagination\n- Product reviews and ratings system\n\n### 📦 Order Management\n\n- Create and track orders\n- Order history for users\n- Admin order management with status updates\n- Detailed order information with shipping details\n\n### 💳 Payment Integration\n\n- **Stripe** payment processing\n- **Razorpay** payment processing\n- Secure payment intent creation\n\n---\n\n## 🛠️ Tech Stack\n\n| Category           | Technology                |\n| ------------------ | ------------------------- |\n| **Runtime**        | Node.js                   |\n| **Framework**      | Express.js                |\n| **Database**       | MongoDB with Mongoose ODM |\n| **Authentication** | JWT (JSON Web Tokens)     |\n| **File Upload**    | Cloudinary                |\n| **Payments**       | Stripe, Razorpay          |\n| **Email**          | Nodemailer                |\n| **Documentation**  | Swagger/OpenAPI 3.0       |\n| **Validation**     | Validator.js              |\n\n---\n\n## 🚀 Getting Started\n\n### Prerequisites\n\n- Node.js 18+ installed\n- MongoDB database (local or Atlas)\n- Cloudinary account\n- Stripe account (for payments)\n- Razorpay account (for payments)\n\n### Installation\n\n1. **Clone the repository**\n\n```bash\ngit clone https://github.com/SaketKothari/tshirt-store-backend-api.git\ncd tshirt-store-backend-api\n```\n\n2. **Install dependencies**\n\n```bash\nnpm install\n```\n\n3. **Configure environment variables**\n\nCreate a `.env` file in the root directory:\n\n```env\n# Server\nPORT=4000\n\n# Database\nMONGODB_URL=mongodb://localhost:27017/tshirt-store\n\n# JWT\nJWT_SECRET=your-super-secret-jwt-key\nJWT_EXPIRY=3d\nCOOKIE_TIME=3\n\n# Cloudinary\nCLOUDINARY_NAME=your-cloud-name\nCLOUDINARY_API_KEY=your-api-key\nCLOUDINARY_API_SECRET=your-api-secret\n\n# Stripe\nSTRIPE_API_KEY=sk_test_...\nSTRIPE_SECRET_KEY=sk_test_...\n\n# Razorpay\nRAZORPAY_API_KEY=rzp_test_...\nRAZORPAY_SECRET=your-razorpay-secret\n\n# Email (SMTP)\nSMTP_HOST=smtp.mailtrap.io\nSMTP_PORT=587\nSMTP_USER=your-smtp-user\nSMTP_PASS=your-smtp-password\n```\n\n4. **Start the server**\n\n```bash\n# Development mode (with hot reload)\nnpm run dev\n\n# Production mode\nnpm start\n```\n\n5. **Access the API**\n\n- API Base URL: `http://localhost:4000/api/v1`\n- Swagger Docs: `http://localhost:4000/api-docs`\n\n---\n\n## 📁 Project Structure\n\n```\ntshirt-store-backend-api/\n├── config/\n│   └── db.js                 # MongoDB connection\n├── controllers/\n│   ├── homeController.js     # Health check endpoints\n│   ├── userController.js     # User authentication \u0026 profile\n│   ├── productController.js  # Product CRUD \u0026 reviews\n│   ├── orderController.js    # Order management\n│   └── paymentController.js  # Payment processing\n├── middlewares/\n│   ├── bigPromise.js         # Async error wrapper\n│   └── user.js               # Auth \u0026 role middlewares\n├── models/\n│   ├── user.js               # User schema\n│   ├── product.js            # Product schema\n│   └── order.js              # Order schema\n├── routes/\n│   ├── home.js               # Home routes\n│   ├── user.js               # User routes\n│   ├── product.js            # Product routes\n│   ├── order.js              # Order routes\n│   └── payment.js            # Payment routes\n├── utils/\n│   ├── cookieToken.js        # JWT token helper\n│   ├── customError.js        # Custom error class\n│   ├── emailHelper.js        # Email sending utility\n│   └── whereClause.js        # Query builder for filtering\n├── views/\n│   └── signuptest.ejs        # Test view template\n├── app.js                    # Express app setup\n├── index.js                  # Server entry point\n├── swagger.yaml              # API documentation\n└── package.json\n```\n\n---\n\n## 🔌 API Endpoints\n\n### Authentication\n\n| Method | Endpoint                        | Description            |\n| ------ | ------------------------------- | ---------------------- |\n| POST   | `/api/v1/signup`                | Register new user      |\n| POST   | `/api/v1/login`                 | User login             |\n| GET    | `/api/v1/logout`                | User logout            |\n| POST   | `/api/v1/forgotPassword`        | Request password reset |\n| POST   | `/api/v1/password/reset/:token` | Reset password         |\n\n### User Profile\n\n| Method | Endpoint                       | Description      |\n| ------ | ------------------------------ | ---------------- |\n| GET    | `/api/v1/userdashboard`        | Get current user |\n| POST   | `/api/v1/userdashboard/update` | Update profile   |\n| POST   | `/api/v1/password/update`      | Change password  |\n\n### Products\n\n| Method | Endpoint                    | Description                     |\n| ------ | --------------------------- | ------------------------------- |\n| GET    | `/api/v1/products`          | Get all products (with filters) |\n| GET    | `/api/v1/product/:id`       | Get single product              |\n| GET    | `/api/v1/reviews?id=`       | Get product reviews             |\n| PUT    | `/api/v1/review`            | Add/Update review               |\n| DELETE | `/api/v1/review?productId=` | Delete review                   |\n\n### Orders\n\n| Method | Endpoint               | Description       |\n| ------ | ---------------------- | ----------------- |\n| POST   | `/api/v1/order/create` | Create new order  |\n| GET    | `/api/v1/order/:id`    | Get order details |\n| GET    | `/api/v1/myorder`      | Get user's orders |\n\n### Payments\n\n| Method | Endpoint                  | Description             |\n| ------ | ------------------------- | ----------------------- |\n| GET    | `/api/v1/stripekey`       | Get Stripe public key   |\n| GET    | `/api/v1/razorpaykey`     | Get Razorpay public key |\n| POST   | `/api/v1/capturestripe`   | Create Stripe payment   |\n| POST   | `/api/v1/capturerazorpay` | Create Razorpay order   |\n\n### Admin Routes\n\n| Method | Endpoint                    | Description         |\n| ------ | --------------------------- | ------------------- |\n| GET    | `/api/v1/admin/users`       | Get all users       |\n| GET    | `/api/v1/admin/user/:id`    | Get user by ID      |\n| PUT    | `/api/v1/admin/user/:id`    | Update user         |\n| DELETE | `/api/v1/admin/user/:id`    | Delete user         |\n| GET    | `/api/v1/admin/products`    | Get all products    |\n| POST   | `/api/v1/admin/product/add` | Add product         |\n| PUT    | `/api/v1/admin/product/:id` | Update product      |\n| DELETE | `/api/v1/admin/product/:id` | Delete product      |\n| GET    | `/api/v1/admin/orders`      | Get all orders      |\n| PUT    | `/api/v1/admin/order/:id`   | Update order status |\n| DELETE | `/api/v1/admin/order/:id`   | Delete order        |\n\n### Manager Routes\n\n| Method | Endpoint                | Description                |\n| ------ | ----------------------- | -------------------------- |\n| GET    | `/api/v1/manager/users` | Get users with 'user' role |\n\n---\n\n## 🔒 Authentication\n\nThe API supports two authentication methods:\n\n### 1. Cookie Authentication\n\nAfter login, a JWT token is automatically set as an httpOnly cookie named `token`.\n\n### 2. Bearer Token\n\nPass the JWT token in the Authorization header:\n\n```\nAuthorization: Bearer \u003cyour-jwt-token\u003e\n```\n\n---\n\n## 🧪 Testing the API\n\n### Using Swagger UI\n\nVisit the [Swagger Documentation](https://tshirt-store.onrender.com/api-docs/) to test endpoints directly in your browser.\n\n### Using cURL\n\n```bash\n# Register a new user\ncurl -X POST https://tshirt-store.onrender.com/api/v1/signup \\\n -F \"name=John Doe\" \\\n -F \"email=john@example.com\" \\\n -F \"password=password123\" \\\n -F \"photo=@/path/to/photo.jpg\"\n\n# Login\ncurl -X POST https://tshirt-store.onrender.com/api/v1/login \\\n -H \"Content-Type: application/json\" \\\n -d '{\"email\":\"john@example.com\",\"password\":\"password123\"}'\n\n# Get all products\ncurl https://tshirt-store.onrender.com/api/v1/products\n```\n\n### Using Postman\n\nImport the Swagger specification from `swagger.yaml` into Postman for a complete collection.\n\n---\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n---\n\n## 📄 License\n\nThis project is licensed under the ISC License.\n\n---\n\n## 👨‍💻 Author\n\n**Saket Kothari**\n\n- Website: [saketkothari.vercel.app](https://saketkothari.vercel.app)\\\n- GitHub: [@SaketKothari](https://github.com/SaketKothari)\n\n---\n\n## ⭐ Show Your Support\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaketkothari%2Ftshirt-store-backend-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaketkothari%2Ftshirt-store-backend-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaketkothari%2Ftshirt-store-backend-api/lists"}