{"id":29194735,"url":"https://github.com/rafiqdevhub/langchain-with-node.js","last_synced_at":"2025-07-02T04:37:57.986Z","repository":{"id":301827456,"uuid":"1007193687","full_name":"Rafiqdevhub/Langchain-With-Node.js","owner":"Rafiqdevhub","description":"An API with Node and Langchain.","archived":false,"fork":false,"pushed_at":"2025-06-29T03:44:31.000Z","size":179,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-29T04:30:23.496Z","etag":null,"topics":["generative-ai","langchain","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://codereviewbackend-sigma.vercel.app","language":"TypeScript","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/Rafiqdevhub.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":"2025-06-23T15:51:51.000Z","updated_at":"2025-06-29T03:44:35.000Z","dependencies_parsed_at":"2025-06-29T04:40:43.616Z","dependency_job_id":null,"html_url":"https://github.com/Rafiqdevhub/Langchain-With-Node.js","commit_stats":null,"previous_names":["rafiqdevhub/langchain-with-node.js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rafiqdevhub/Langchain-With-Node.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2FLangchain-With-Node.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2FLangchain-With-Node.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2FLangchain-With-Node.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2FLangchain-With-Node.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rafiqdevhub","download_url":"https://codeload.github.com/Rafiqdevhub/Langchain-With-Node.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2FLangchain-With-Node.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263076959,"owners_count":23410164,"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","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":["generative-ai","langchain","nodejs","typescript"],"created_at":"2025-07-02T04:37:56.953Z","updated_at":"2025-07-02T04:37:57.867Z","avatar_url":"https://github.com/Rafiqdevhub.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Code Review Agent with LangChain \u0026 Google Gemini\n\nA production-ready RESTful API for AI-powered code review and chatbot services using LangChain and Google's Gemini AI model. This backend service provides comprehensive code analysis, security vulnerability detection, and intelligent conversation capabilities.\n\n## Features\n\n### Core Functionality\n\n- **AI Code Review** with detailed analysis and suggestions\n- **Multi-file code analysis** supporting 25+ programming languages\n- **Security vulnerability detection** and best practices enforcement\n- **Code quality assessment** with readability and maintainability scores\n- **LangChain integration** with Google Gemini AI\n- **Conversation memory/history** support with thread tracking\n- **File upload support** (up to 10 files, 5MB each)\n- **RESTful API** with structured JSON responses\n\n### Security \u0026 Performance\n\n- **Helmet.js** for security headers\n- **CORS** protection with configurable origins\n- **Compression** middleware for response optimization\n- **Payload size limits** (1MB for JSON, 5MB for files)\n- **Multi-tier rate limiting**:\n  - General API: 100 requests per 15 minutes per IP\n  - AI endpoints: 20 (production) / 50 (development) requests per 15 minutes per IP\n  - Daily AI limit: 50 requests per day per IP\n- **Graceful shutdown** handling\n- **Robust error handling** with environment-aware responses\n\n### Production Ready\n\n- **Environment-based configuration** via `.env` files\n- **TypeScript** for type safety\n- **Vercel deployment** optimized\n- **Health check endpoint** with rate limit status\n- **Comprehensive API documentation**\n\n## Quick Start\n\n### Prerequisites\n\n- Node.js (v16 or higher)\n- npm or yarn\n- Google AI API key ([Get one here](https://makersuite.google.com/app/apikey))\n\n## API Reference\n\n### Health Check\n\n```http\nGET /\n```\n\nReturns API status, available endpoints, and rate limit information.\n\n**Response:**\n\n```json\n{\n  \"status\": \"API is running\",\n  \"version\": \"2.0.0\",\n  \"description\": \"AI-powered code review and chatbot service\",\n  \"endpoints\": [\n    \"/api/ai/chat\",\n    \"/api/ai/review-text\",\n    \"/api/ai/review-files\",\n    \"/api/ai/languages\",\n    \"/api/ai/guidelines\"\n  ],\n  \"features\": [\n    \"AI Chatbot with conversation memory\",\n    \"Code review for text input\",\n    \"Multi-file code analysis\",\n    \"Security vulnerability detection\",\n    \"Code quality assessment\",\n    \"Support for 25+ programming languages\"\n  ]\n}\n```\n\n### Code Review - Text Input\n\n```http\nPOST /api/ai/review-text\n```\n\nSubmit code as text for AI-powered review and analysis.\n\n**Request Body:**\n\n```json\n{\n  \"code\": \"function divide(a, b) { return a / b; }\",\n  \"filename\": \"math.js\",\n  \"threadId\": \"optional-thread-id\"\n}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"summary\": \"Brief overview of the code analysis\",\n    \"issues\": [\n      {\n        \"type\": \"warning\",\n        \"severity\": \"medium\",\n        \"line\": 1,\n        \"description\": \"Division by zero not handled\",\n        \"suggestion\": \"Add check for b === 0\"\n      }\n    ],\n    \"suggestions\": [\"General improvement suggestions\"],\n    \"securityConcerns\": [\"Security vulnerabilities found\"],\n    \"codeQuality\": {\n      \"readability\": 8,\n      \"maintainability\": 7,\n      \"complexity\": \"Low\"\n    },\n    \"threadId\": \"conversation-thread-id\"\n  }\n}\n```\n\n### Code Review - File Upload\n\n```http\nPOST /api/ai/review-files\nContent-Type: multipart/form-data\n```\n\nUpload code files for comprehensive analysis.\n\n**Form Data:**\n\n- `files`: Code files (up to 10 files, 5MB each)\n- `threadId`: Optional thread ID for conversation continuity\n\n**Supported File Types:**\n\n- JavaScript: `.js`, `.jsx`\n- TypeScript: `.ts`, `.tsx`\n- Python: `.py`\n- Java: `.java`\n- C/C++: `.c`, `.cpp`, `.h`, `.hpp`\n- And 20+ more languages\n\n### Get Supported Languages\n\n```http\nGET /api/ai/languages\n```\n\nReturns list of supported programming languages and file types.\n\n### Get Review Guidelines\n\n```http\nGET /api/ai/guidelines\n```\n\nReturns code review criteria, severity levels, and best practices.\n\n### Chat with AI\n\n```http\nPOST /api/ai/chat\n```\n\nSend a message to the AI chatbot with optional conversation continuity.\n\n**Request Body:**\n\n```json\n{\n  \"message\": \"Your message here\",\n  \"threadId\": \"optional-thread-id\"\n}\n```\n\n**Rate Limits:**\n\n- **General**: 100 requests per 15 minutes per IP\n- **AI Endpoint**: 20 (prod) / 50 (dev) requests per 15 minutes per IP\n- **Daily AI Limit**: 50 requests per day per IP\n\n**Error Responses:**\n\nRate limit exceeded:\n\n```json\n{\n  \"error\": \"AI rate limit exceeded\",\n  \"message\": \"Too many AI requests from this IP, please try again later.\"\n}\n```\n\nDaily limit exceeded:\n\n```json\n{\n  \"error\": \"Daily AI limit exceeded\",\n  \"message\": \"You have exceeded your daily limit of 50 AI requests. Please try again tomorrow or contact support for additional quota.\",\n  \"dailyLimit\": 50,\n  \"resetTime\": \"24 hours from first request\"\n}\n```\n\nValidation error:\n\n```json\n{\n  \"error\": \"Validation Error\",\n  \"message\": \"Message is required\"\n}\n```\n\n## Deployment\n\nThis is a backend-only API with no frontend or static file dependencies. It's designed for deployment on various platforms:\n\n- **Vercel** (recommended for serverless)\n- **Heroku**\n- **Railway**\n- **Render**\n- **DigitalOcean App Platform**\n- **Docker** (any container platform)\n\n### Quick Vercel Deployment\n\n1. Connect your GitHub repository to Vercel\n2. Set environment variables:\n   - `GOOGLE_API_KEY`\n   - `CORS_ORIGIN` (your frontend URL)\n   - `NODE_ENV=production`\n3. Deploy automatically via git push\n\nThe included `vercel.json` configuration ensures proper API-only deployment.\n\n### Common Deployment Issues\n\n❌ **\"public directory not found\"** - This is an API-only project with no frontend. Use the provided `vercel.json` configuration.\n\n❌ **CORS errors** - Set `CORS_ORIGIN` to your frontend domain in production.\n\n❌ **Build failures** - Ensure all dependencies are installed: `npm install`\n\n✅ **Solution**: Use the deployment configurations provided in `vercel.json`, `Dockerfile`, and `Procfile`.\n\nSee [`DEPLOYMENT.md`](./DEPLOYMENT.md) for detailed deployment instructions.\n\n### Docker Deployment\n\n```bash\n# Build and run with Docker\ndocker build -t langchain-api .\ndocker run -p 5000:5000 --env-file .env langchain-api\n\n# Or use docker-compose\ndocker-compose up -d\n```\n\n### Platform Deployment\n\nThe project includes configuration files for popular hosting platforms:\n\n- **Heroku**: `Procfile` included\n- **Railway/Render**: Works out of the box\n- **Vercel/Netlify**: Serverless deployment ready\n- **AWS/GCP**: Container deployment ready\n\nSee [`DEPLOYMENT.md`](./DEPLOYMENT.md) for detailed deployment instructions.\n\n### Environment Variables for Production\n\n```env\nNODE_ENV=production\nPORT=5000\nGOOGLE_API_KEY=your_production_api_key\nCORS_ORIGIN=https://yourdomain.com\n\n# Optional rate limiting overrides\nRATE_LIMIT_GENERAL_MAX=200\nRATE_LIMIT_AI_MAX_PROD=30\nRATE_LIMIT_AI_DAILY_MAX=100\n```\n\n## Configuration\n\nAll configuration is handled through environment variables with sensible defaults:\n\n| Variable                  | Default       | Description                   |\n| ------------------------- | ------------- | ----------------------------- |\n| `PORT`                    | `5000`        | Server port                   |\n| `NODE_ENV`                | `development` | Environment mode              |\n| `GOOGLE_API_KEY`          | _required_    | Google AI API key             |\n| `CORS_ORIGIN`             | `*` (dev)     | Allowed CORS origins          |\n| `RATE_LIMIT_WINDOW_MS`    | `900000`      | Rate limit window (15 min)    |\n| `RATE_LIMIT_GENERAL_MAX`  | `100`         | General requests per window   |\n| `RATE_LIMIT_AI_MAX_PROD`  | `20`          | AI requests per window (prod) |\n| `RATE_LIMIT_AI_MAX_DEV`   | `50`          | AI requests per window (dev)  |\n| `RATE_LIMIT_AI_DAILY_MAX` | `50`          | AI requests per day           |\n\n## Architecture\n\n```\nsrc/\n├── config/\n│   └── env.ts              # Environment configuration\n├── routes/\n│   └── ai.routes.ts        # AI chat endpoints\n└── index.ts                # Main server file\n```\n\n**Key Design Decisions:**\n\n- **Stateless API**: No database required, conversation state managed by client\n- **Rate limiting**: Multi-tier protection against abuse\n- **Error boundaries**: Graceful error handling with detailed logging\n- **Security first**: Helmet, CORS, payload limits, and input validation\n- **Environment aware**: Different behavior for development vs production\n\n## Technologies Used\n\n- **Runtime**: Node.js with TypeScript\n- **Framework**: Express.js\n- **AI Integration**: LangChain + Google Gemini\n- **Security**: Helmet.js, CORS, express-rate-limit\n- **Performance**: Compression middleware\n- **Development**: tsx, nodemon for hot reload\n- **Deployment**: Docker, multi-platform support\n\n## Documentation\n\n- [`API_DOCS.md`](./API_DOCS.md) - Detailed API documentation\n- [`DEPLOYMENT.md`](./DEPLOYMENT.md) - Production deployment guide\n- [Environment variables](#configuration) - Configuration reference\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafiqdevhub%2Flangchain-with-node.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafiqdevhub%2Flangchain-with-node.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafiqdevhub%2Flangchain-with-node.js/lists"}