{"id":29876402,"url":"https://github.com/hari31416/connections_backend","last_synced_at":"2026-05-09T03:39:37.664Z","repository":{"id":295356320,"uuid":"989675880","full_name":"Hari31416/connections_backend","owner":"Hari31416","description":"A comprehensive full-stack MERN application for efficiently managing and tracking your professional and personal connections, companies, and employment positions. ","archived":false,"fork":false,"pushed_at":"2025-06-01T11:23:44.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-31T03:59:13.988Z","etag":null,"topics":["backend","crm","express","networking","nodejs","professional"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hari31416.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-05-24T15:39:44.000Z","updated_at":"2025-06-01T11:23:48.000Z","dependencies_parsed_at":"2025-05-25T05:40:28.841Z","dependency_job_id":"e25eec86-f5b3-4bb9-bc85-c3f3d7d8125e","html_url":"https://github.com/Hari31416/connections_backend","commit_stats":null,"previous_names":["hari31416/connections_backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Hari31416/connections_backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hari31416%2Fconnections_backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hari31416%2Fconnections_backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hari31416%2Fconnections_backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hari31416%2Fconnections_backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hari31416","download_url":"https://codeload.github.com/Hari31416/connections_backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hari31416%2Fconnections_backend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32806544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"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":["backend","crm","express","networking","nodejs","professional"],"created_at":"2025-07-31T03:09:06.212Z","updated_at":"2026-05-09T03:39:37.658Z","avatar_url":"https://github.com/Hari31416.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Connections Tracker - Backend API\n\nA robust Node.js/Express REST API for managing professional and personal connections, companies, and employment positions. Features JWT authentication, MongoDB integration, and comprehensive logging.\n\n## ⚠️ Experimental Project Disclaimer\n\n**This is an experimental project** - the result of an experiment to understand whether \"vibe coding\" can be used to generate end-to-end web applications.\n\n**Important Notes:**\n\n- The bulk of this code is AI-generated\n- This code is **NOT optimized for production use**\n- This project serves as a proof-of-concept and learning exercise\n- Use at your own risk and review thoroughly before any production deployment\n\n## 🚀 Technology Stack\n\n- **Runtime**: Node.js\n- **Framework**: Express.js (v5.1.0)\n- **Database**: MongoDB with Mongoose ODM (v8.15.0)\n- **Authentication**: JWT (JSON Web Tokens)\n- **Security**: bcryptjs for password hashing\n- **CORS**: Cross-origin resource sharing enabled\n- **Environment**: dotenv for configuration management\n\n## 📋 Prerequisites\n\n- Node.js (v16 or higher)\n- MongoDB Atlas account or local MongoDB installation\n- npm or yarn package manager\n\n## 🛠️ Installation \u0026 Setup\n\n1. **Clone and navigate to backend directory**:\n\n   ```bash\n   cd backend\n   ```\n\n2. **Install dependencies**:\n\n   ```bash\n   npm install\n   ```\n\n3. **Environment Configuration**:\n   Create a `.env` file in the backend root:\n\n   ```env\n   # Database Configuration\n   MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/connections\n\n   # JWT Secret (use a strong, random string in production)\n   JWT_SECRET=your_super_secure_jwt_secret_key_here\n\n   # Server Configuration\n   PORT=4000\n   NODE_ENV=development\n   ```\n\n4. **Start the development server**:\n\n   ```bash\n   npm run dev\n   ```\n\n   Or for production:\n\n   ```bash\n   npm start\n   ```\n\n## 📚 API Documentation\n\n### Base URL\n\n- Development: `http://localhost:4000/api`\n- Production: `https://your-backend-domain.com/api`\n\n### Health Check\n\n- **GET** `/health` - Check server status\n\n### Authentication Endpoints\n\n#### Check System Status\n\n- **GET** `/api/users/exists`\n- **Response**: `{ \"hasUsers\": boolean }`\n\n#### Initialize First Admin User\n\n- **POST** `/api/initialize`\n- **Body**: `{ \"email\": \"admin@example.com\", \"password\": \"password\" }`\n- **Note**: Only works when no users exist in the system\n\n#### User Login\n\n- **POST** `/api/login`\n- **Body**: `{ \"email\": \"user@example.com\", \"password\": \"password\" }`\n- **Response**: `{ \"token\": \"jwt_token\", \"user\": {...} }`\n\n#### Register New User (Admin Only)\n\n- **POST** `/api/register`\n- **Headers**: `Authorization: Bearer \u003cadmin_jwt_token\u003e`\n- **Body**: `{ \"email\": \"newuser@example.com\", \"password\": \"password\" }`\n\n### Connections Endpoints\n\n#### Get All Connections\n\n- **GET** `/api/connections`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Get Connection by ID\n\n- **GET** `/api/connections/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Response**: Includes connection details and associated positions\n\n#### Create New Connection\n\n- **POST** `/api/connections`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Body**:\n  ```json\n  {\n    \"name\": \"John Doe\",\n    \"email\": \"john@example.com\",\n    \"phone\": \"+1234567890\",\n    \"linkedinUserId\": \"johndoe\",\n    \"githubUserId\": \"johndoe\",\n    \"notes\": \"Met at tech conference\"\n  }\n  ```\n\n#### Update Connection\n\n- **PUT** `/api/connections/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Body**: Same as create, with updated fields\n\n#### Delete Connection\n\n- **DELETE** `/api/connections/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Note**: Also deletes all associated positions\n\n#### Get Connections by Company\n\n- **GET** `/api/connections/bycompany/:companyId`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Search Connections\n\n- **GET** `/api/connections/search/:query`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Description**: Search connections across name, email, phone, LinkedIn/GitHub usernames\n- **Example**: `/api/connections/search/john` - finds all connections matching \"john\"\n- **Note**: Search is case-insensitive and supports partial matches\n\n### Companies Endpoints\n\n#### Get All Companies\n\n- **GET** `/api/companies`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Get Company by ID\n\n- **GET** `/api/companies/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Response**: Includes company details and associated positions\n\n#### Create New Company\n\n- **POST** `/api/companies`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Body**:\n  ```json\n  {\n    \"name\": \"Tech Corp Inc\",\n    \"industry\": \"Technology\",\n    \"website\": \"https://techcorp.com\"\n  }\n  ```\n\n#### Update Company\n\n- **PUT** `/api/companies/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Body**: Same as create, with updated fields\n\n#### Delete Company\n\n- **DELETE** `/api/companies/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Note**: Also deletes all associated positions\n\n#### Get Companies by Connection\n\n- **GET** `/api/companies/byconnection/:connectionId`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Search Companies\n\n- **GET** `/api/companies/search/:query`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Description**: Search companies across name, industry, and website fields\n- **Example**: `/api/companies/search/tech` - finds all companies matching \"tech\"\n- **Note**: Search is case-insensitive and supports partial matches\n\n### Positions Endpoints\n\n#### Get All Positions\n\n- **GET** `/api/positions`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Get Position by ID\n\n- **GET** `/api/positions/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Create New Position\n\n- **POST** `/api/positions`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Body**:\n  ```json\n  {\n    \"connectionId\": \"connection_object_id\",\n    \"companyId\": \"company_object_id\",\n    \"title\": \"Software Engineer\",\n    \"startDate\": \"2023-01-15\",\n    \"endDate\": \"2024-01-15\",\n    \"current\": false,\n    \"notes\": \"Full-stack development role\"\n  }\n  ```\n\n#### Update Position\n\n- **PUT** `/api/positions/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n- **Body**: Same as create, with updated fields\n\n#### Delete Position\n\n- **DELETE** `/api/positions/:id`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Get Positions by Connection\n\n- **GET** `/api/positions/connection/:connectionId`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n#### Get Positions by Company\n\n- **GET** `/api/positions/company/:companyId`\n- **Headers**: `Authorization: Bearer \u003cjwt_token\u003e`\n\n## 🗄️ Database Models\n\n### User Model\n\n```javascript\n{\n  _id: ObjectId,\n  email: String (required, unique),\n  password: String (required, hashed),\n  isAdmin: Boolean (default: false),\n  createdAt: Date,\n  updatedAt: Date\n}\n```\n\n### Connection Model\n\n```javascript\n{\n  _id: ObjectId,\n  userId: String (required),\n  name: String (required),\n  email: String,\n  phone: String,\n  linkedinUserId: String,\n  githubUserId: String,\n  notes: String,\n  createdAt: Date,\n  updatedAt: Date\n}\n```\n\n### Company Model\n\n```javascript\n{\n  _id: ObjectId,\n  userId: String (required),\n  name: String (required),\n  industry: String,\n  website: String,\n  createdAt: Date,\n  updatedAt: Date\n}\n```\n\n### Position Model\n\n```javascript\n{\n  _id: ObjectId,\n  userId: String (required),\n  connectionId: ObjectId (ref: 'Connection', required),\n  companyId: ObjectId (ref: 'Company', required),\n  title: String (required),\n  startDate: Date,\n  endDate: Date,\n  current: Boolean (default: false),\n  notes: String,\n  createdAt: Date,\n  updatedAt: Date\n}\n```\n\n## 🔐 Security Features\n\n- **JWT Authentication**: Secure token-based authentication\n- **Password Hashing**: bcryptjs with salt rounds\n- **User Isolation**: All data is user-scoped via userId\n- **Admin Controls**: User registration restricted to admin users\n- **Request Logging**: Comprehensive logging with sensitive data protection\n- **CORS Configuration**: Cross-origin request handling\n\n## 📝 Scripts\n\n```json\n{\n  \"start\": \"node src/index.js\",\n  \"dev\": \"nodemon src/index.js\",\n  \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n}\n```\n\n## 🚀 Deployment\n\n### Render Deployment (Recommended)\n\n1. **Create Render Web Service**:\n\n   - Connect your GitHub repository\n   - Set build command: `npm install`\n   - Set start command: `npm start`\n   - Set environment to `Node`\n\n2. **Environment Variables**:\n\n   ```env\n   MONGODB_URI=mongodb+srv://...\n   JWT_SECRET=your_production_jwt_secret\n   NODE_ENV=production\n   PORT=4000\n   ```\n\n3. **MongoDB Atlas Setup**:\n   - Create a MongoDB Atlas cluster\n   - Add your Render service IP to IP whitelist (or use 0.0.0.0/0 for all IPs)\n   - Create a database user with read/write permissions\n\n### Alternative Deployment Options\n\n- **Heroku**: Compatible with Heroku's Node.js buildpack\n- **Railway**: Direct GitHub integration\n- **Vercel**: Serverless functions (requires restructuring)\n- **DigitalOcean App Platform**: Container-based deployment\n\n## 🔧 Development\n\n### Adding New Routes\n\n1. Create route file in `src/routes/`\n2. Import and use in `src/index.js`\n3. Follow existing authentication middleware pattern\n\n### Database Migrations\n\n- No formal migration system\n- Use MongoDB Compass or Atlas UI for data management\n- Consider implementing seeds for development data\n\n### Logging\n\nThe application includes comprehensive request logging:\n\n- All requests are logged with timestamp and IP\n- Sensitive data (passwords, emails, etc.) is hidden in logs\n- Error logging includes stack traces for debugging\n\n## 🐛 Troubleshooting\n\n### Common Issues\n\n1. **MongoDB Connection Error**:\n\n   - Verify MONGODB_URI in .env\n   - Check Atlas IP whitelist\n   - Ensure database user has correct permissions\n\n2. **JWT Authentication Fails**:\n\n   - Verify JWT_SECRET is set\n   - Check token format in Authorization header\n   - Ensure token hasn't expired\n\n3. **CORS Issues**:\n\n   - Configure CORS_ORIGIN for production\n   - Verify frontend URL matches CORS settings\n\n4. **Port Already in Use**:\n   - Change PORT in .env file\n   - Kill existing process: `lsof -ti:4000 | xargs kill -9`\n\n## 📄 License\n\nMIT License - see LICENSE file for details\n\n## 👨‍💻 Author\n\n**Harikesh Kushwaha**\n\n---\n\nFor frontend documentation, see [Frontend README](https://github.com/Hari31416/connections_frontend/blob/main/README.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhari31416%2Fconnections_backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhari31416%2Fconnections_backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhari31416%2Fconnections_backend/lists"}