{"id":25065851,"url":"https://github.com/arvindk2025/irctc_backend_workindia","last_synced_at":"2026-04-04T21:32:46.878Z","repository":{"id":285392643,"uuid":"934386422","full_name":"arvindk2025/IRCTC_Backend_WorkIndia","owner":"arvindk2025","description":"This system allows users to register, search for trains, check seat availability, and book train seats securely. It includes features like JWT-based authentication for user login, race condition handling during seat booking to prevent overbooking, and admin functionalities to manage train data.","archived":false,"fork":false,"pushed_at":"2025-07-06T06:08:00.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-03T16:21:56.715Z","etag":null,"topics":["expressjs","jwt-authentication","mysql-database","nodejs","race-conditions","rest-api"],"latest_commit_sha":null,"homepage":"","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/arvindk2025.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":"2025-02-17T18:37:57.000Z","updated_at":"2025-07-20T20:27:16.000Z","dependencies_parsed_at":"2025-03-31T14:04:04.529Z","dependency_job_id":"fb31277c-ee78-4e46-b50f-bf673aa1ef06","html_url":"https://github.com/arvindk2025/IRCTC_Backend_WorkIndia","commit_stats":null,"previous_names":["arvindk2025/irctc_backend_workindia"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arvindk2025/IRCTC_Backend_WorkIndia","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvindk2025%2FIRCTC_Backend_WorkIndia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvindk2025%2FIRCTC_Backend_WorkIndia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvindk2025%2FIRCTC_Backend_WorkIndia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvindk2025%2FIRCTC_Backend_WorkIndia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arvindk2025","download_url":"https://codeload.github.com/arvindk2025/IRCTC_Backend_WorkIndia/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvindk2025%2FIRCTC_Backend_WorkIndia/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31415110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["expressjs","jwt-authentication","mysql-database","nodejs","race-conditions","rest-api"],"created_at":"2025-02-06T19:45:12.477Z","updated_at":"2026-04-04T21:32:46.851Z","avatar_url":"https://github.com/arvindk2025.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IRCTC_API WorkIndia_Assignment\n---\n\n## Features That I have implemented according to the given task\n\nTask-1) **User Registration**\n   - Users can register with a name, email, and password.\n   - The password is securely hashed using `bcrypt`.\n\nTask-2) **JWT-based Authentication**\n   - Users log in with their credentials, and a JWT token is issued for secure access to protected routes.\n   - The token must be included in the `Authorization` header (Bearer Token) for any protected actions like booking trains, adding trains, etc.\n\nTask-3) ** Get Seat Availability**\n   - Users can search for trains between a source and destination.\n   - Trains with available seats are displayed, along with their details.\n\nTask-4) **Book Train Seats with Race Condition Handling**\n   - Users can book seats on available trains.\n   - The system handles potential race conditions by ensuring that seat availability is updated atomically, preventing overbooking.\n\nTask-5) **Admin Functionalities ( Add New Train \u0026 Update Seat availability**\n   - Admins can add new trains, including the total number of seats.\n   - Admins can update seat availability for existing trains.\n   - Only admins have access to routes that modify train data.\n\nTask-6) **Get Booking Details**\n   - Users can retrieve their booking details.\n   - The API returns information on the booked train, including the source, destination, and number of seats booked.\n\nTask-7) **Error Handling and Input Validation**\n   - All API requests are validated for correct input.\n   - Descriptive error messages are returned when invalid or incomplete data is provided.\n   - Graceful handling of edge cases such as unavailable seats or missing fields.\n\n---\n\n## Project Setup\n\n### Requirement\n\nTo run this project, ensure you have following installed:\n\n1) Node.js\n2) MySQL\n3) Postman\n\n\n\n### Installation\n\n1. Clone the repository to your local machine:\n   ```bash\n   git clone https://github.com/arvindk2025/IRCTC_Backend_WorkIndia.git\n   cd IRCTC_Backend_WorkIndia\n   ```\n\n2. You need to create a `.env` file in the root of your project with the following environment variables:\n\n``` bash\nPORT=3000\nDB_HOST=localhost\nDB_USER=root\nDB_PASSWORD=yourpassword\nDB_NAME=irctc_db\nJWT_SECRET=your_own_jwt_secret\nAPI_KEY=your_own_choice_admin_api_key\n```\n   \n   \n3. Install all necessary dependencies using npm:\n   \n   ```bash\n    npm install\n   ```\n4. Set up your MySQL database:\n  * Create a MySQL database named irctc_db.\n\n For Example:\n ``` bash\n CREATE 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   created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\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   created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\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\nSELECT * FROM users;\nSELECT * FROM trains;\n\n```\n\n### Starting the Server\nOnce the setup is complete, start the server using npm:\n\n```bash\nnpm start\n\n```\n\n--- \n\n# All =\u003e API Endpoints for API Testing in Postman \n## You can access the API at http://localhost:3000.\n\n## API Routes \n    1). For SignUp new user \n       * HTTP Method :- POST\n       * API Endpoint :- http://localhost:3000/user/register\n       * Request Body:\n       \n``` bash\n       {\n  \"name\": \"arvind_kumar_2\",\n  \"email\": \"arvind_kumar_2@gmail.com\",\n  \"password\": \"your_own_paswword\"\n      }\n\n```\n    2). Login\n       * HTTP Method :- POST\n       * Endpoint :- http://localhost:3000/user/login\n       * Request Body:\n       \n``` bash\n    {\n  \"email\": \"arvind_kumar_2@gmail.com\",\n  \"password\": \"your_own_paswword\"\n    }\n ```\n\n\n    3. For Checking Seat availability\n       * HTTP Method :- GET\n       * Endpoint :- http://localhost:3000/user/availability?source=Banglore\u0026destination=Hyderabad\n       * Query Parameters\n          * source: Source station (e.g., \"Banglore\")\n          * destination: Destination station (e.g., \"Hyderabad\")\n          * Request Body: Not needed \n       * Response:\n``` bash\n{\n    \"available\": true,\n    \"availableTrainCount\": 1,\n    \"trains\": [\n        {\n            \"trainNumber\": \"12345\",\n            \"availableSeats\": 120\n        }\n    ]\n}\n\n```\n\n    4. For Booking Seats\n       * HTTP Method :- POST\n       * Endpoint :- http://localhost:3000/user/book\n       * Request Body:\n       \n``` bash\n  {\n  \"trainId\": 1,\n  \"seatsToBook\": 2\n}\n\n```\n * Response:\n\n```bash\n{\n  \"message\": \"Seats booked successfully\"\n}\n```\n\n#### Note :- Requires JWT authentication.\n\n    5. For Getting Booking Details\n\n       * HTTP Method :- GET\n       * Endpoint :- http://localhost:3000/user/getAllbookings\n\n       * Response:\n  \n    \n```bash\n[\n    {\n        \"booking_id\": 1,\n        \"number_of_seats\": 50,\n        \"train_number\": \"1234\",\n        \"source\": \"Banglore\",\n        \"destination\": \"Hyderabad\"\n    }\n]\n\n```\n\n### Admin Routes\n\n    6.   Add a new train\n\n       * HTTP Method :- POST\n       * Endpoint :- http://localhost:3000/admin/addTrain\n       * Request Body:\n```bash\n{\n  \"trainNumber\": \"12345\",\n  \"source\": \"Banglore\",\n  \"destination\": \"Hyderabad\",\n  \"totalSeats\": 400\n}\n```\n       * Response:\n    \n```bash\n{\n    \"message\": \"Trains added successfully\",\n    \"trainIds\": [\n        {\n            \"trainNumber\": \"172622\",\n            \"trainId\": 21\n        }\n    ]\n  }\n\n    * Headers :\n             * x-api-key: Your admin API key which is stored in .env file\n```\n\n\n    7. Update seat availability\n       * HTTP Method :- PUT\n       * Endpoint :- http://localhost:3000/admin/update-seats/10\n       * Request Body:\n```bash\n {\n  \"totalSeats\": 200,\n  \"availableSeats\": 150\n }\n```\n       * Response:  \n```bash\n{\n  \"message\": \"Seats updated successfully\"\n}\n        \n    * Headers:\n            * x-api-key:  Your admin API key which is stored in .env file\n```\n\n\n## Technologies Used\n\n* Node.js: For backend \n* Express.js: Web framework for building the RESTful API\n* MySQL: Database for storing Train, User, and Booking data\n* JWT: For authentication and authorization\n* bcrypt: For hashing the passwords\n* dotenv: For managing environment variables\n\n\n### Contributing\nFeel free to fork the repository and make your contributions via pull requests. Any enhancements, bug fixes, or suggestions are welcome!\n\n\n\n\n      \n\n      \n\n\n      \n\n\n\n\n\n\n\n\n\n   \n   \n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farvindk2025%2Firctc_backend_workindia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farvindk2025%2Firctc_backend_workindia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farvindk2025%2Firctc_backend_workindia/lists"}