{"id":24777008,"url":"https://github.com/bhuvantenguria/workindia-irctc-assignment-","last_synced_at":"2025-03-24T01:36:31.380Z","repository":{"id":266973437,"uuid":"899913910","full_name":"Bhuvantenguria/WorkIndia-IRCTC-Assignment-","owner":"Bhuvantenguria","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-07T11:22:49.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T07:49:02.050Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Bhuvantenguria.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}},"created_at":"2024-12-07T11:10:22.000Z","updated_at":"2024-12-07T11:22:53.000Z","dependencies_parsed_at":"2024-12-07T12:29:21.579Z","dependency_job_id":null,"html_url":"https://github.com/Bhuvantenguria/WorkIndia-IRCTC-Assignment-","commit_stats":null,"previous_names":["bhuvantenguria/workindia-irctc-assignment-"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhuvantenguria%2FWorkIndia-IRCTC-Assignment-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhuvantenguria%2FWorkIndia-IRCTC-Assignment-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhuvantenguria%2FWorkIndia-IRCTC-Assignment-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bhuvantenguria%2FWorkIndia-IRCTC-Assignment-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bhuvantenguria","download_url":"https://codeload.github.com/Bhuvantenguria/WorkIndia-IRCTC-Assignment-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245195802,"owners_count":20575936,"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":[],"created_at":"2025-01-29T07:49:02.635Z","updated_at":"2025-03-24T01:36:31.361Z","avatar_url":"https://github.com/Bhuvantenguria.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚆 IRCTC Railway Management System API\n\nWelcome to the **IRCTC Railway Management System API**!  \nThis project simulates a real-world railway booking platform like IRCTC, providing functionalities for both **users** and **admins** to manage train schedules, seat bookings, and availability.\n\n---\n\n## 🌟 **API Workflow in Action**\n\n![API Workflow](https://media.giphy.com/media/Ll22OhMLAlVDb8UQWe/giphy.gif)  \n*Above is a representation of API workflows for user registration, train booking, and seat availability checks.*\n\n---\n\n## 🎯 **Problem Statement**\n\nYour task is to design an **API** to:  \n1. **Check Train Availability**: Retrieve train schedules and seat availability between two stations.  \n2. **Book Seats**: Ensure concurrent booking with optimized race-condition handling.  \n3. **Role-Based Access**: Secure admin operations and user bookings.  \n\nKey Features:\n- **Real-Time Traffic Handling**: Optimized to handle multiple simultaneous bookings.\n- **Role Access**: Admin vs. User functionalities.\n- **Secure Admin Endpoints**: Protected using API keys.\n- **User Authentication**: JWT-based login system.\n\n---\n\n## 🛠️ **Tech Stack**\n\n- **Backend Framework**: [Node.js](https://nodejs.org/) with [Express.js](https://expressjs.com/)  \n- **Database**: [MySQL](https://www.mysql.com/)  \n- **Authentication**: [JWT](https://jwt.io/) for secure session handling  \n- **Encryption**: [bcrypt](https://www.npmjs.com/package/bcrypt) for passwords  \n- **Environment Management**: [dotenv](https://www.npmjs.com/package/dotenv)  \n\n---\n\n## ⚙️ **Setup and Installation**\n\n### Prerequisites\nEnsure you have the following installed:\n- **Node.js** (v14+)\n- **MySQL** (or PostgreSQL)\n\n### Step 1: Clone the Repository\n```bash\ngit clone https://github.com/your-repo/IRCTC_API.git\ncd IRCTC_API\n```\n\n### Step 2: Install Dependencies\n```bash\nnpm install\n```\n\n### Step 3: Configure the Environment\nCreate a `.env` file and add the following variables:\n```env\nPORT=3000\nDB_HOST=localhost\nDB_USER=root\nDB_PASSWORD=yourpassword\nDB_NAME=irctc_db\nJWT_SECRET=your_jwt_secret\nAPI_KEY=your_admin_api_key\n```\n\n### Step 4: Set Up the Database\nRun the following SQL commands to create the necessary tables:\n```sql\nCREATE DATABASE irctc_db;\nUSE irctc_db;\n\nCREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(255) NOT NULL,\n    email VARCHAR(255) UNIQUE NOT NULL,\n    password VARCHAR(255) NOT NULL,\n    role ENUM('user', 'admin') DEFAULT 'user'\n);\n\nCREATE TABLE trains (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    train_number VARCHAR(50) NOT NULL,\n    source VARCHAR(255) NOT NULL,\n    destination VARCHAR(255) NOT NULL,\n    total_seats INT NOT NULL,\n    available_seats INT NOT NULL\n);\n\nCREATE TABLE bookings (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    user_id INT,\n    train_id INT,\n    seats INT NOT NULL,\n    FOREIGN KEY (user_id) REFERENCES users(id),\n    FOREIGN KEY (train_id) REFERENCES trains(id)\n);\n```\n\n### Step 5: Start the Server\n```bash\nnpm start\n```\n\u003e The API will be live at `http://localhost:3000`.\n\n---\n\n## 🔗 **API Endpoints**\n\n### User Routes\n1. **Register**: `POST /user/register`  \n2. **Login**: `POST /user/login`  \n3. **Train Availability**: `GET /user/availability`  \n4. **Book Seat**: `POST /user/book`  \n5. **Get Booking Details**: `GET /user/getAllbookings`\n\n### Admin Routes\n1. **Add Train**: `POST /admin/addTrain`  \n   \u003e Requires `x-api-key` in headers.  \n2. **Update Seats**: `PUT /admin/update-seats/:id`  \n\n---\n\n## 🚀 **Future Enhancements**\n\n- Add a front-end using React.js for a seamless UI.\n- Implement payment gateways for ticket purchases.\n- Introduce train seat selection during booking.\n- Add email notifications for booking confirmations.\n\n---\n\n## 🤝 **Contributing**\n\n- Fork the repo  \n- Create a new branch (`git checkout -b feature-name`)  \n- Commit changes (`git commit -m \"Add feature\"`)  \n- Push the branch (`git push origin feature-name`)  \n- Create a Pull Request  \n\n---\n\n![API Flow GIF](https://media.giphy.com/media/L4FjRxANoi8LUxSDYx/giphy.gif)  \n\n_**Happy Coding!**_ 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhuvantenguria%2Fworkindia-irctc-assignment-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhuvantenguria%2Fworkindia-irctc-assignment-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhuvantenguria%2Fworkindia-irctc-assignment-/lists"}