{"_id":"@abdullahbakouni/nestjs-microservices-generator","_rev":"2-d41b52539b573a2859f9fc7cc2f08462","name":"@abdullahbakouni/nestjs-microservices-generator","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@abdullahbakouni/nestjs-microservices-generator","version":"1.0.0","keywords":["nestjs","microservices","kafka","redis","generator","cli"],"author":{"name":"Abdullah Bakouni"},"license":"MIT","_id":"@abdullahbakouni/nestjs-microservices-generator@1.0.0","maintainers":[{"name":"abdullahbakouni","email":"aboodbak70@gmail.com"}],"bin":{"nest-micro-gen":"bin/cli.js","create-nest-microservices":"bin/cli.js"},"dist":{"shasum":"73acc7a4783706f18b533c49e9bc0d8deaad2b0e","tarball":"https://registry.npmjs.org/@abdullahbakouni/nestjs-microservices-generator/-/nestjs-microservices-generator-1.0.0.tgz","fileCount":4,"integrity":"sha512-rKy8auYyglSR324QUVU1O0EkQBUUE3Z1L96ddRf5XnxS3NvHCfgeGTKPl1n3ReGevsG/JhFFr+eU/VuV9U4Tgg==","signatures":[{"sig":"MEYCIQDXA/v+jksYuEvgjujHyNWF3cEeGsoX4JwrdHRDAtjoBQIhAITp4vAwuc3nvJJbNPcHhHrHxVRlxTx5kgoDjGGIIXly","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":34666},"main":"index.js","engines":{"node":">=16.0.0"},"scripts":{"test":"echo \"No tests yet\""},"_npmUser":{"name":"abdullahbakouni","email":"aboodbak70@gmail.com"},"_npmVersion":"11.8.0","description":"Interactive CLI to generate NestJS microservices monorepo with Kafka & Redis","directories":{},"_nodeVersion":"24.13.1","dependencies":{"ora":"^5.4.1","chalk":"^4.1.2","fs-extra":"^11.1.1","inquirer":"^8.2.5"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/nestjs-microservices-generator_1.0.0_1771177565855_0.6072955424295376","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@abdullahbakouni/nestjs-microservices-generator","version":"1.0.1","description":"Interactive CLI to generate NestJS microservices monorepo with Kafka & Redis","main":"index.js","bin":{"create-nest-microservices":"bin/cli.js","nest-micro-gen":"bin/cli.js"},"scripts":{"test":"echo \"No tests yet\""},"keywords":["nestjs","microservices","kafka","redis","generator","cli"],"author":{"name":"Abdullah Bakouni"},"license":"MIT","dependencies":{"inquirer":"^8.2.5","chalk":"^4.1.2","ora":"^5.4.1","fs-extra":"^11.1.1"},"engines":{"node":">=16.0.0"},"_id":"@abdullahbakouni/nestjs-microservices-generator@1.0.1","_nodeVersion":"24.13.1","_npmVersion":"11.8.0","dist":{"integrity":"sha512-GvgNql6L3grHTQVuWdcTIO16p/DQs81PNkRs/QVK9FV4lCxk+4+Jps5e0szVxdp0tcGWV1RI9glVHH9Dx7aZbw==","shasum":"678b3103254e4752a2ac50bdd1b6f3a29f24c7f7","tarball":"https://registry.npmjs.org/@abdullahbakouni/nestjs-microservices-generator/-/nestjs-microservices-generator-1.0.1.tgz","fileCount":5,"unpackedSize":46213,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCFVJv5d8JRUkgfOhzYZe/rAxSsnvjFeAlvMHIOd7WpqQIgS0voWAVVVcipsxyM9UJ11Ztd3aINPSzaSAIV7BoKC2w="}]},"_npmUser":{"name":"abdullahbakouni","email":"aboodbak70@gmail.com"},"directories":{},"maintainers":[{"name":"abdullahbakouni","email":"aboodbak70@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nestjs-microservices-generator_1.0.1_1771178369972_0.8504944912935939"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-15T17:46:05.718Z","modified":"2026-02-15T17:59:30.239Z","1.0.0":"2026-02-15T17:46:06.060Z","1.0.1":"2026-02-15T17:59:30.118Z"},"author":{"name":"Abdullah Bakouni"},"license":"MIT","keywords":["nestjs","microservices","kafka","redis","generator","cli"],"description":"Interactive CLI to generate NestJS microservices monorepo with Kafka & Redis","maintainers":[{"name":"abdullahbakouni","email":"aboodbak70@gmail.com"}],"readme":"# 🚀 NestJS Microservices Generator\n\nInteractive CLI tool to generate a complete NestJS microservices monorepo with Kafka, Redis, and more in seconds!\n\n[![npm version](https://img.shields.io/npm/v/@abdullahbakouni/nestjs-microservices-generator.svg)](https://www.npmjs.com/package/@abdullahbakouni/nestjs-microservices-generator)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Node.js Version](https://img.shields.io/node/v/@abdullahbakouni/nestjs-microservices-generator.svg)](https://nodejs.org)\n\n## ✨ Features\n\n- 🎯 **Interactive CLI** - Guided setup with beautiful prompts\n- 🏗️ **NestJS Monorepo** - Single package.json for all microservices\n- 📦 **Shared Libraries** - Pre-configured `@app/common` with Kafka & Redis modules\n- ⚡ **Kafka Integration** - Full Kafka module with producer/consumer support\n- 🔴 **Redis Integration** - Complete Redis service with all operations (cache, pub/sub, lists, sets, etc.)\n- 🐳 **Docker Compose** - Ready-to-use Docker setup with Kafka, Zookeeper, and Redis\n- 🔧 **TypeScript** - Fully typed with best practices\n- 🎨 **Customizable** - Choose only the features you need\n- 📝 **Auto-generated** - Creates controllers, services, and modules automatically\n\n## 📦 Installation\n\n### Global Installation (Recommended)\n```bash\nnpm install -g @abdullahbakouni/nestjs-microservices-generator\n```\n\n### Or use with npx (No installation needed)\n```bash\nnpx @abdullahbakouni/nestjs-microservices-generator\n```\n\n## 🎬 Quick Start\n```bash\n# Run the generator\ncreate-nest-microservices\n\n# Or with npx\nnpx @abdullahbakouni/nestjs-microservices-generator\n```\n\nFollow the interactive prompts:\n```\n🚀 NestJS Microservices Generator\n\n? What is your project name? my-ecommerce\n? How many microservices do you want to create? 3\n? Name for microservice #1: api-gateway\n? Name for microservice #2: user-service\n? Name for microservice #3: order-service\n? Select features to include: \n  ◉ Kafka integration\n  ◉ Redis integration\n  ◉ Docker Compose\n  ◯ TypeORM Database\n  ◯ JWT Authentication\n? Kafka broker address: localhost:9092\n? Redis host: localhost\n? Redis port: 6379\n\n✅ Project generated successfully!\n```\n\n## 🏗️ Generated Project Structure\n```\nmy-ecommerce/\n├── package.json                    # Single package.json for all services\n├── nest-cli.json                   # Monorepo configuration\n├── tsconfig.json\n├── docker-compose.yml              # Kafka, Redis, and services\n├── apps/\n│   ├── api-gateway/\n│   │   └── src/\n│   │       ├── main.ts            # HTTP + Kafka bootstrap\n│   │       ├── api-gateway.module.ts\n│   │       ├── api-gateway.controller.ts\n│   │       └── api-gateway.service.ts\n│   ├── user-service/\n│   └── order-service/\n└── libs/\n    └── common/\n        └── src/\n            ├── index.ts\n            ├── kafka/\n            │   ├── kafka.module.ts      # forRoot, forRootAsync, forProducer, forConsumer\n            │   ├── kafka.service.ts     # emit, send, consume, subscribe\n            │   └── events/\n            │       └── topics.ts        # Predefined Kafka topics\n            ├── redis/\n            │   ├── redis.module.ts      # forRoot, forRootAsync\n            │   └── redis.service.ts     # Full Redis operations\n            └── interfaces/\n                └── index.ts\n```\n\n## 🚀 Usage\n\n### Install Dependencies\n```bash\ncd my-ecommerce\nnpm install\n```\n\n### Start All Services\n```bash\n# Start with Docker Compose (includes Kafka & Redis)\ndocker-compose up -d\n\n# Start a specific service in development mode\nnpm run start:api-gateway\nnpm run start:user-service\nnpm run start:order-service\n```\n\n### Available Scripts\n```bash\nnpm run build              # Build all services\nnpm run build:all          # Build all services explicitly\nnpm run start              # Start default service\nnpm run start:dev          # Start in watch mode\nnpm run start:api-gateway  # Start specific service\nnpm run start:user-service\nnpm run start:order-service\n```\n\n## 📚 Using Shared Libraries\n\n### Kafka Module\n\nThe generated Kafka module supports multiple patterns:\n\n#### 1. Basic Usage (forRoot)\n```typescript\nimport { Module } from '@nestjs/common';\nimport { KafkaModule } from '@app/common';\n\n@Module({\n  imports: [\n    KafkaModule.forRoot({\n      clientId: 'user-service',\n      brokers: ['localhost:9092'],\n      groupId: 'user-service-group',\n    }),\n  ],\n})\nexport class UserModule {}\n```\n\n#### 2. Async Configuration (forRootAsync)\n```typescript\nimport { ConfigModule, ConfigService } from '@nestjs/config';\nimport { KafkaModule } from '@app/common';\n\n@Module({\n  imports: [\n    KafkaModule.forRootAsync({\n      imports: [ConfigModule],\n      inject: [ConfigService],\n      useFactory: (config: ConfigService) => ({\n        clientId: config.get('KAFKA_CLIENT_ID'),\n        brokers: [config.get('KAFKA_BROKER')],\n        groupId: config.get('KAFKA_GROUP_ID'),\n      }),\n    }),\n  ],\n})\nexport class UserModule {}\n```\n\n#### 3. Producer Only (forProducer)\n```typescript\nKafkaModule.forProducer({\n  clientId: 'notification-producer',\n  brokers: ['localhost:9092'],\n})\n```\n\n#### 4. Consumer Only (forConsumer)\n```typescript\nKafkaModule.forConsumer({\n  clientId: 'order-consumer',\n  brokers: ['localhost:9092'],\n  groupId: 'order-service-group',\n})\n```\n\n### Kafka Service Usage\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { KafkaService, KAFKA_TOPICS } from '@app/common';\n\n@Injectable()\nexport class UserService {\n  constructor(private readonly kafkaService: KafkaService) {}\n\n  async createUser(userData: any) {\n    // Emit event (fire and forget)\n    this.kafkaService.emit(KAFKA_TOPICS.USER_CREATED, {\n      userId: userData.id,\n      email: userData.email,\n    });\n\n    // Send and wait for response\n    const result = await this.kafkaService.send(\n      KAFKA_TOPICS.NOTIFICATION_SEND,\n      { type: 'welcome', userId: userData.id }\n    );\n\n    return result;\n  }\n}\n```\n\n#### Listen to Events with @EventPattern\n```typescript\nimport { Controller } from '@nestjs/common';\nimport { EventPattern, Payload } from '@nestjs/microservices';\nimport { KAFKA_TOPICS } from '@app/common';\n\n@Controller()\nexport class UserController {\n  @EventPattern(KAFKA_TOPICS.USER_CREATED)\n  async handleUserCreated(@Payload() data: any) {\n    console.log('User created:', data);\n    // Process the event\n  }\n}\n```\n\n### Redis Module\n\n#### Basic Usage\n```typescript\nimport { RedisModule } from '@app/common';\n\n@Module({\n  imports: [\n    RedisModule.forRoot({\n      host: 'localhost',\n      port: 6379,\n      password: 'your-password', // optional\n      db: 0,\n      keyPrefix: 'myapp:',\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n#### Async Configuration\n```typescript\nRedisModule.forRootAsync({\n  imports: [ConfigModule],\n  inject: [ConfigService],\n  useFactory: (config: ConfigService) => ({\n    host: config.get('REDIS_HOST'),\n    port: config.get('REDIS_PORT'),\n    password: config.get('REDIS_PASSWORD'),\n  }),\n})\n```\n\n### Redis Service Usage\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { RedisService } from '@app/common';\n\n@Injectable()\nexport class CacheService {\n  constructor(private readonly redis: RedisService) {}\n\n  // Basic operations\n  async cacheUser(userId: string, userData: any) {\n    await this.redis.set(`user:${userId}`, userData, 3600); // TTL 1 hour\n  }\n\n  async getUser(userId: string) {\n    return await this.redis.get(`user:${userId}`);\n  }\n\n  // Hash operations\n  async saveUserProfile(userId: string, profile: any) {\n    await this.redis.hset(`profile:${userId}`, 'name', profile.name);\n    await this.redis.hset(`profile:${userId}`, 'email', profile.email);\n  }\n\n  async getUserProfile(userId: string) {\n    return await this.redis.hgetall(`profile:${userId}`);\n  }\n\n  // List operations\n  async addToQueue(task: any) {\n    await this.redis.rpush('task-queue', task);\n  }\n\n  async getNextTask() {\n    return await this.redis.lpop('task-queue');\n  }\n\n  // Pub/Sub\n  async publishNotification(message: any) {\n    await this.redis.publish('notifications', message);\n  }\n\n  async subscribeToNotifications() {\n    await this.redis.subscribe('notifications', (message) => {\n      console.log('Received:', message);\n    });\n  }\n\n  // Sorted Sets (leaderboards)\n  async addScore(userId: string, score: number) {\n    await this.redis.zadd('leaderboard', score, { userId, score });\n  }\n\n  async getTopPlayers(limit: number) {\n    return await this.redis.zrange('leaderboard', 0, limit - 1);\n  }\n}\n```\n\n## 🐳 Docker Compose\n\nThe generated `docker-compose.yml` includes:\n\n- **Zookeeper** - Kafka dependency\n- **Kafka** - Message broker on port 9092\n- **Redis** - Cache & pub/sub on port 6379\n- **All your microservices** - Auto-configured and networked\n```bash\n# Start everything\ndocker-compose up -d\n\n# View logs\ndocker-compose logs -f\n\n# Stop everything\ndocker-compose down\n```\n\n## 🎯 Kafka Topics\n\nPre-configured topics in `libs/common/src/kafka/events/topics.ts`:\n```typescript\nexport const KAFKA_TOPICS = {\n  // User Events\n  USER_CREATED: 'user.created',\n  USER_UPDATED: 'user.updated',\n  USER_DELETED: 'user.deleted',\n\n  // Order Events\n  ORDER_CREATED: 'order.created',\n  ORDER_COMPLETED: 'order.completed',\n  ORDER_CANCELLED: 'order.cancelled',\n\n  // Notification Events\n  NOTIFICATION_SEND: 'notification.send',\n  EMAIL_SEND: 'email.send',\n  SMS_SEND: 'sms.send',\n};\n```\n\nAdd your own topics easily!\n\n## ⚙️ Configuration\n\nEach microservice has its own `.env.example`:\n```env\nAPI_GATEWAY_PORT=3000\nKAFKA_BROKER=localhost:9092\nREDIS_HOST=localhost\nREDIS_PORT=6379\nREDIS_PASSWORD=\n```\n\n## 🔧 Customization\n\n### Add a New Microservice\n```bash\n# Use NestJS CLI\nnest generate app payment-service\n```\n\nThe service will be automatically added to `nest-cli.json`!\n\n### Add Custom Kafka Topics\n\nEdit `libs/common/src/kafka/events/topics.ts`:\n```typescript\nexport const KAFKA_TOPICS = {\n  // Your custom topics\n  PAYMENT_PROCESSED: 'payment.processed',\n  INVOICE_GENERATED: 'invoice.generated',\n} as const;\n```\n\n## 📖 API Reference\n\n### KafkaService Methods\n\n| Method | Description |\n|--------|-------------|\n| `emit(topic, data)` | Fire and forget event |\n| `send(topic, data)` | Send and wait for response |\n| `subscribeToTopic(topic)` | Subscribe to a topic |\n| `consume(options)` | Set up consumer with callback |\n\n### RedisService Methods\n\n| Category | Methods |\n|----------|---------|\n| **Basic** | `get`, `set`, `del`, `exists`, `expire`, `ttl` |\n| **Hash** | `hset`, `hget`, `hgetall`, `hdel` |\n| **List** | `lpush`, `rpush`, `lpop`, `lrange` |\n| **Set** | `sadd`, `smembers`, `sismember`, `srem` |\n| **Sorted Set** | `zadd`, `zrange`, `zrangebyscore` |\n| **Pub/Sub** | `publish`, `subscribe`, `unsubscribe` |\n| **Counter** | `incr`, `decr`, `incrby` |\n| **Pattern** | `keys`, `deletePattern` |\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📝 License\n\nMIT © [Abdullah Bakouni](https://github.com/abdullahbakouni)\n\n## 🐛 Issues\n\nFound a bug? [Open an issue](https://github.com/abdullahbakouni/nestjs-microservices-generator/issues)\n\n## ⭐ Show Your Support\n\nGive a ⭐️ if this project helped you!\n\n## 📧 Contact\n\n- GitHub: [@abdullahbakouni](https://github.com/abdullahbakouni)\n- Email: your.email@example.com\n\n---\n\n**Made with ❤️ by Abdullah Bakouni**\n","readmeFilename":"README.md"}