{"id":30221684,"url":"https://github.com/bes-js/nestjs-ecommerce-api","last_synced_at":"2025-08-19T17:04:04.585Z","repository":{"id":309768726,"uuid":"1037497752","full_name":"Bes-js/nestjs-ecommerce-api","owner":"Bes-js","description":"E-commerce API with NestJS, TypeORM, GraphQL, Kafka, and JWT","archived":false,"fork":false,"pushed_at":"2025-08-13T17:53:29.000Z","size":1513,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-13T19:23:38.013Z","etag":null,"topics":["api","ecommerce","graphql","jwt","kafka","microservice","mvc","nest","nestjs","rest-api","typeorm","typescript"],"latest_commit_sha":null,"homepage":"https://discord.gg/luppux","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bes-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2025-08-13T16:59:20.000Z","updated_at":"2025-08-13T17:53:32.000Z","dependencies_parsed_at":"2025-08-13T19:23:44.689Z","dependency_job_id":"53c8e46e-c23e-4305-8939-8530fa4e7556","html_url":"https://github.com/Bes-js/nestjs-ecommerce-api","commit_stats":null,"previous_names":["bes-js/nestjs-ecommerce-api"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Bes-js/nestjs-ecommerce-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bes-js%2Fnestjs-ecommerce-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bes-js%2Fnestjs-ecommerce-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bes-js%2Fnestjs-ecommerce-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bes-js%2Fnestjs-ecommerce-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bes-js","download_url":"https://codeload.github.com/Bes-js/nestjs-ecommerce-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bes-js%2Fnestjs-ecommerce-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270407963,"owners_count":24578345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"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","ecommerce","graphql","jwt","kafka","microservice","mvc","nest","nestjs","rest-api","typeorm","typescript"],"created_at":"2025-08-14T11:00:59.047Z","updated_at":"2025-08-14T11:02:43.012Z","avatar_url":"https://github.com/Bes-js.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS E-Commerce API\n\nA modern e-commerce API built with NestJS, TypeORM, GraphQL, Kafka, JWT, and TypeScript.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/project.png\" width=\"350\" height=\"350\" /\u003e\n\u003c/p\u003e\n\n\n## 🚀 Features\n\n- **NestJS Framework** - Modern Node.js framework\n- **TypeORM** - SQL database with ORM\n- **GraphQL** - Apollo Server GraphQL API\n- **JWT Authentication** - Secure authentication\n- **Role-based Authorization** - Role-based access control\n- **Email Verification** - Email verification system\n- **Kafka Integration** - Message queue integration\n- **Class Validator** - Data validation\n- **TypeScript** - Type safety\n\n## 📋 Prerequisites\n\n- Node.js (v16 or higher)\n- npm or yarn\n- Kafka (optional)\n\n## 🛠️ Installation\n\n1. **Clone the repository:**\n```bash\ngit clone https://github.com/Bes-js/nestjs-ecommerce-api\ncd nestjs-ecommerce-api\n```\n\n2. **Install dependencies:**\n```bash\nnpm install\n```\n\n3. **Set up environment variables:**\n```bash\ncp .env.example .env\n```\n\n4. **Configure your environment variables in `.env`:**\n```env\n# Application\nNODE_ENV=development\nPORT=3000\n\n# JWT\nJWT_SECRET=yourSuperSecretJwtKeyChangeThisInProduction\n\n# Database\nDB_TYPE=sqlite\nDB_DATABASE=database.sqlite\n\n# Email Configuration\nSMTP_HOST=smtp.gmail.com\nSMTP_PORT=587\nSMTP_USER=your-email@gmail.com\nSMTP_PASS=your-app-password\nSMTP_FROM=noreply@ecommerce.com\nFRONTEND_URL=http://localhost:3000\n\n# Kafka (Optional)\nKAFKA_BROKERS=localhost:9092\nKAFKA_CLIENT_ID=ecommerce-api\nKAFKA_GROUP_ID=ecommerce-group\nKAFKAJS_NO_PARTITIONER_WARNING=1\n```\n\n5. **Start the application:**\n```bash\n# Development mode\nnpm run start:dev\n\n# Production mode\nnpm run build\nnpm run start:prod\n```\n\n## 🗄️ Database\n\nSQLite database is automatically created. Database file: `database.sqlite`\n\n## 📊 GraphQL Playground\n\nAfter starting the application, access GraphQL Playground:\n```\nhttp://localhost:3000/graphql\n```\n\n## 🔐 Authentication\n\n### User Registration\n```graphql\nmutation {\n  createUser(createUserDto: {\n    email: \"user@example.com\"\n    firstName: \"Berkant\"\n    lastName: \"Özdemir\"\n    username: \"Bes-js\"\n    password: \"password123\"\n  }) {\n    id\n    email\n    firstName\n    lastName\n    username\n    role\n    isActive\n    isEmailVerified\n    createdAt\n  }\n}\n```\n\n**Note:** After user registration, an email verification is sent. Users cannot login until they verify their email.\n\n### Login\n```graphql\nmutation {\n  login(loginDto: {\n    email: \"user@example.com\"\n    password: \"password123\"\n  })\n}\n```\n\n**Response:**\n```json\n{\n  \"data\": {\n    \"login\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\"\n  }\n}\n```\n\n### Email Verification\n```graphql\nmutation {\n  verifyEmail(verifyEmailDto: {\n    token: \"emailVerificationTokenHere\"\n  })\n}\n```\n\n### Resend Verification Email\n```graphql\nmutation {\n  resendVerificationEmail(resendVerificationDto: {\n    email: \"user@example.com\"\n  })\n}\n```\n\n### Authorization Header\nAdd Authorization header to GraphQL requests:\n```\nAuthorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\n```\n\n## 📦 API Endpoints\n\n### 👥 Users\n\n#### 1. Create User (Public)\n```graphql\nmutation {\n  createUser(createUserDto: {\n    email: \"admin@example.com\"\n    firstName: \"Admin\"\n    lastName: \"User\"\n    username: \"admin\"\n    password: \"admin123\"\n    role: \"admin\"\n  }) {\n    id\n    email\n    firstName\n    lastName\n    username\n    role\n    isActive\n    isEmailVerified\n    createdAt\n  }\n}\n```\n\n#### 2. Get All Users (Admin Only)\n```graphql\nquery {\n  users {\n    id\n    email\n    firstName\n    lastName\n    username\n    role\n    isActive\n    isEmailVerified\n    createdAt\n    orders {\n      id\n      orderNumber\n      status\n    }\n  }\n}\n```\n\n#### 3. Get User Details (Authenticated)\n```graphql\nquery {\n  user(id: \"userIdHere\") {\n    id\n    email\n    firstName\n    lastName\n    username\n    role\n    isActive\n    isEmailVerified\n    createdAt\n    orders {\n      id\n      orderNumber\n      totalAmount\n      status\n      createdAt\n    }\n  }\n}\n```\n\n#### 4. Update User (Authenticated)\n```graphql\nmutation {\n  updateUser(\n    id: \"userIdHere\"\n    updateUserDto: {\n      firstName: \"Updated Name\"\n      lastName: \"Updated Last Name\"\n    }\n  ) {\n    id\n    firstName\n    lastName\n    updatedAt\n  }\n}\n```\n\n#### 5. Delete User (Admin Only)\n```graphql\nmutation {\n  removeUser(id: \"userIdHere\") {\n    id\n    email\n  }\n}\n```\n\n### 🏷️ Categories\n\n#### 1. Create Category (Admin Only)\n```graphql\nmutation {\n  createCategory(createCategoryDto: {\n    name: \"Electronics\"\n    description: \"Electronic products category\"\n    image: \"https://example.com/electronics.jpg\"\n  }) {\n    id\n    name\n    description\n    image\n    isActive\n    createdAt\n  }\n}\n```\n\n#### 2. Get All Categories (Public)\n```graphql\nquery {\n  categories {\n    id\n    name\n    description\n    image\n    isActive\n    createdAt\n    products {\n      id\n      name\n      price\n    }\n  }\n}\n```\n\n#### 3. Get Category Details (Public)\n```graphql\nquery {\n  category(id: \"categoryIdHere\") {\n    id\n    name\n    description\n    image\n    isActive\n    createdAt\n    products {\n      id\n      name\n      price\n      description\n      stock\n    }\n  }\n}\n```\n\n#### 4. Update Category (Admin Only)\n```graphql\nmutation {\n  updateCategory(\n    id: \"categoryIdHere\"\n    updateCategoryDto: {\n      name: \"Updated Category\"\n      description: \"Updated description\"\n    }\n  ) {\n    id\n    name\n    description\n    updatedAt\n  }\n}\n```\n\n#### 5. Delete Category (Admin Only)\n```graphql\nmutation {\n  removeCategory(id: \"categoryIdHere\") {\n    id\n    name\n  }\n}\n```\n\n### 📦 Products\n\n#### 1. Create Product (Admin Only)\n```graphql\nmutation {\n  createProduct(createProductDto: {\n    name: \"iPhone 16 Pro Max\"\n    description: \"Apple iPhone 16 Pro Max 256GB\"\n    price: 1199.99\n    discountPrice: 999.99\n    stock: 55\n    isActive: true\n    isFeatured: true\n    images: [\n      \"https://example.com/iphone1.jpg\",\n      \"https://example.com/iphone2.jpg\"\n    ]\n    specifications: {\n      \"storage\": \"256GB\",\n      \"color\": \"Desert Titanium\",\n      \"screen\": \"6.9 inch\",\n      \"cpu\": \"Apple A18 Pro\"\n    }\n    categoryId: \"categoryIdHere\"\n  }) {\n    id\n    name\n    description\n    price\n    discountPrice\n    stock\n    isActive\n    isFeatured\n    rating\n    reviewCount\n    images\n    specifications\n    createdAt\n    category {\n      id\n      name\n    }\n  }\n}\n```\n\n#### 2. Get All Products (Public)\n```graphql\nquery {\n  products {\n    id\n    name\n    description\n    price\n    discountPrice\n    stock\n    isActive\n    isFeatured\n    rating\n    reviewCount\n    images\n    specifications\n    createdAt\n    category {\n      id\n      name\n    }\n    variants {\n      id\n      name\n      price\n      stock\n    }\n  }\n}\n```\n\n#### 3. Get Featured Products (Public)\n```graphql\nquery {\n  featuredProducts {\n    id\n    name\n    description\n    price\n    discountPrice\n    stock\n    rating\n    reviewCount\n    images\n    category {\n      id\n      name\n    }\n  }\n}\n```\n\n#### 4. Get Products by Category (Public)\n```graphql\nquery {\n  productsByCategory(categoryId: \"categoryIdHere\") {\n    id\n    name\n    description\n    price\n    discountPrice\n    stock\n    isActive\n    rating\n    reviewCount\n    images\n    category {\n      id\n      name\n    }\n  }\n}\n```\n\n#### 5. Get Product Details (Public)\n```graphql\nquery {\n  product(id: \"productIdHere\") {\n    id\n    name\n    description\n    price\n    discountPrice\n    stock\n    isActive\n    isFeatured\n    rating\n    reviewCount\n    images\n    specifications\n    createdAt\n    category {\n      id\n      name\n      description\n    }\n    variants {\n      id\n      name\n      price\n      discountPrice\n      stock\n      attributes\n      sku\n      isActive\n    }\n  }\n}\n```\n\n#### 6. Update Product (Admin Only)\n```graphql\nmutation {\n  updateProduct(\n    id: \"productIdHere\"\n    updateProductDto: {\n      name: \"Updated Product Name\"\n      price: 1099.99\n      stock: 75\n      isFeatured: true\n    }\n  ) {\n    id\n    name\n    price\n    stock\n    isFeatured\n    updatedAt\n  }\n}\n```\n\n#### 7. Delete Product (Admin Only)\n```graphql\nmutation {\n  removeProduct(id: \"productIdHere\") {\n    id\n    name\n  }\n}\n```\n\n### 🔄 Variants\n\n#### 1. Create Variant (Admin Only)\n```graphql\nmutation {\n  createVariant(createVariantDto: {\n    name: \"256GB Black Titanium\"\n    price: 1099.99\n    discountPrice: 999.99\n    stock: 25\n    attributes: {\n      \"storage\": \"256GB\",\n      \"color\": \"Black Titanium\",\n      \"size\": \"6.9 inch\"\n    }\n    sku: \"IPHONE16PRO-MAX-256-BLACK-TITANIUM\"\n    isActive: true\n    productId: \"productIdHere\"\n  }) {\n    id\n    name\n    price\n    discountPrice\n    stock\n    attributes\n    sku\n    isActive\n    createdAt\n    product {\n      id\n      name\n    }\n  }\n}\n```\n\n#### 2. Get All Variants (Public)\n```graphql\nquery {\n  variants {\n    id\n    name\n    price\n    discountPrice\n    stock\n    attributes\n    sku\n    isActive\n    createdAt\n    product {\n      id\n      name\n    }\n  }\n}\n```\n\n#### 3. Get Variants by Product (Public)\n```graphql\nquery {\n  variantsByProduct(productId: \"productIdHere\") {\n    id\n    name\n    price\n    discountPrice\n    stock\n    attributes\n    sku\n    isActive\n  }\n}\n```\n\n#### 4. Get Variant Details (Public)\n```graphql\nquery {\n  variant(id: \"variantIdHere\") {\n    id\n    name\n    price\n    discountPrice\n    stock\n    attributes\n    sku\n    isActive\n    createdAt\n    product {\n      id\n      name\n      description\n    }\n  }\n}\n```\n\n#### 5. Update Variant (Admin Only)\n```graphql\nmutation {\n  updateVariant(\n    id: \"variantIdHere\"\n    updateVariantDto: {\n      price: 1399.99\n      stock: 30\n      attributes: {\n        \"storage\": \"512GB\",\n        \"color\": \"Black Titanium\"\n      }\n    }\n  ) {\n    id\n    name\n    price\n    stock\n    attributes\n    updatedAt\n  }\n}\n```\n\n#### 6. Delete Variant (Admin Only)\n```graphql\nmutation {\n  removeVariant(id: \"variantIdHere\") {\n    id\n    name\n  }\n}\n```\n\n### 🛒 Orders\n\n#### 1. Create Order (Authenticated)\n```graphql\nmutation {\n  createOrder(createOrderDto: {\n    totalAmount: 1099.99\n    discountAmount: 100.00\n    finalAmount: 999.99\n    shippingAddress: {\n      \"firstName\": \"Berkant\",\n      \"lastName\": \"Özdemir\",\n      \"address\": \"123 Main St\",\n      \"city\": \"Istanbul\",\n      \"country\": \"Turkey\",\n      \"postalCode\": \"34000\",\n      \"phone\": \"+905551234567\"\n    }\n    billingAddress: {\n      \"firstName\": \"Berkant\",\n      \"lastName\": \"Özdemir\",\n      \"address\": \"123 Main St\",\n      \"city\": \"Istanbul\",\n      \"country\": \"Turkey\",\n      \"postalCode\": \"34000\",\n      \"phone\": \"+905551234567\"\n    }\n    notes: \"Please package carefully\"\n    orderItems: [\n      {\n        productId: \"productIdHere\"\n        variantId: \"variantIdHere\"\n        quantity: 2\n      },\n      {\n        productId: \"anotherProductId\"\n        quantity: 1\n      }\n    ]\n  }) {\n    id\n    orderNumber\n    totalAmount\n    discountAmount\n    finalAmount\n    status\n    shippingAddress\n    billingAddress\n    notes\n    createdAt\n    user {\n      id\n      firstName\n      lastName\n      email\n    }\n    orderItems {\n      id\n      quantity\n      unitPrice\n      totalPrice\n      product {\n        id\n        name\n      }\n      variant {\n        id\n        name\n      }\n    }\n  }\n}\n```\n\n#### 2. Get All Orders (Admin Only)\n```graphql\nquery {\n  orders {\n    id\n    orderNumber\n    totalAmount\n    discountAmount\n    finalAmount\n    status\n    shippingAddress\n    billingAddress\n    notes\n    createdAt\n    user {\n      id\n      firstName\n      lastName\n      email\n    }\n    orderItems {\n      id\n      quantity\n      unitPrice\n      totalPrice\n      product {\n        id\n        name\n      }\n      variant {\n        id\n        name\n      }\n    }\n  }\n}\n```\n\n#### 3. Get User Orders (Authenticated)\n```graphql\nquery {\n  myOrders {\n    id\n    orderNumber\n    totalAmount\n    discountAmount\n    finalAmount\n    status\n    shippingAddress\n    billingAddress\n    notes\n    createdAt\n    orderItems {\n      id\n      quantity\n      unitPrice\n      totalPrice\n      product {\n        id\n        name\n        images\n      }\n      variant {\n        id\n        name\n      }\n    }\n  }\n}\n```\n\n#### 4. Get Order Details (Authenticated)\n```graphql\nquery {\n  order(id: \"orderIdHere\") {\n    id\n    orderNumber\n    totalAmount\n    discountAmount\n    finalAmount\n    status\n    shippingAddress\n    billingAddress\n    notes\n    createdAt\n    user {\n      id\n      firstName\n      lastName\n      email\n    }\n    orderItems {\n      id\n      quantity\n      unitPrice\n      totalPrice\n      product {\n        id\n        name\n        description\n        images\n      }\n      variant {\n        id\n        name\n        attributes\n      }\n    }\n  }\n}\n```\n\n#### 5. Update Order (Admin Only)\n```graphql\nmutation {\n  updateOrder(\n    id: \"orderIdHere\"\n    updateOrderDto: {\n      notes: \"Updated notes\"\n    }\n  ) {\n    id\n    orderNumber\n    notes\n    updatedAt\n  }\n}\n```\n\n#### 6. Update Order Status (Admin Only)\n```graphql\nmutation {\n  updateOrderStatus(\n    id: \"orderIdHere\"\n    status: \"shipped\"\n  ) {\n    id\n    orderNumber\n    status\n    updatedAt\n  }\n}\n```\n\n#### 7. Delete Order (Admin Only)\n```graphql\nmutation {\n  removeOrder(id: \"orderIdHere\") {\n    id\n    orderNumber\n  }\n}\n```\n\n## 🔧 Configuration\n\n### Environment Variables\n```env\n# Application\nNODE_ENV=development\nPORT=3000\n\n# JWT\nJWT_SECRET=your-secret-key\n\n# Database\nDB_TYPE=sqlite\nDB_DATABASE=database.sqlite\n\n# Email Configuration\nSMTP_HOST=smtp.gmail.com\nSMTP_PORT=587\nSMTP_USER=your-email@gmail.com\nSMTP_PASS=your-app-password\nSMTP_FROM=noreply@ecommerce.com\nFRONTEND_URL=http://localhost:3000\n\n# Kafka (Optional)\nKAFKA_BROKERS=localhost:9092\nKAFKA_CLIENT_ID=ecommerce-api\nKAFKA_GROUP_ID=ecommerce-group\nKAFKAJS_NO_PARTITIONER_WARNING=1\n```\n\n### Email Configuration\nFor Gmail, you need to:\n1. Enable 2-factor authentication\n2. Generate an App Password\n3. Use the App Password in `SMTP_PASS`\n\n### Kafka Configuration\nKafka integration requires a running Kafka service. The application works without Kafka.\n\n## 🧪 Testing\n\n```bash\n# Unit tests\nnpm run test\n\n# E2E tests\nnpm run test:e2e\n\n# Test coverage\nnpm run test:cov\n```\n\n## 📁 Project Structure\n\n```\nsrc/\n├── auth/                # Authentication\n│   ├── guards/          # Guards\n│   ├── strategies/      # JWT strategy\n│   ├── decorators/      # Custom decorators\n│   └── dto/             # Auth DTOs\n├── users/               # User module\n├── products/            # Product module\n├── variants/            # Variant module\n├── categories/          # Category module\n├── orders/              # Order module\n├── email/               # Email service\n├── kafka/               # Kafka integration\n├── types/               # TypeScript types\n└── main.ts              # Application entry point\n```\n\n## 🚀 Deployment\n\n### Docker\n```bash\ndocker build -t nestjs-ecommerce-api .\ndocker run -p 3000:3000 nestjs-ecommerce-api\n```\n\n### Production\n```bash\nnpm run build\nnpm run start:prod\n```\n\n## 📝 License\n\nThis project is licensed under the GPL-3.0 License.\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📞 Support\n\nFor questions about the project, please open an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbes-js%2Fnestjs-ecommerce-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbes-js%2Fnestjs-ecommerce-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbes-js%2Fnestjs-ecommerce-api/lists"}