{"id":29631025,"url":"https://github.com/devsafix/library-management-api","last_synced_at":"2025-07-21T11:07:59.836Z","repository":{"id":300371485,"uuid":"1005694634","full_name":"devsafix/library-management-api","owner":"devsafix","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-02T03:45:42.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-02T04:33:56.319Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://library-management-api-by-safi.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/devsafix.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-20T16:43:31.000Z","updated_at":"2025-07-02T03:45:45.000Z","dependencies_parsed_at":"2025-06-21T10:26:05.132Z","dependency_job_id":"2cc242e1-9c06-4517-a20d-b0dfa59cc934","html_url":"https://github.com/devsafix/library-management-api","commit_stats":null,"previous_names":["devsafix/library-management-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devsafix/library-management-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsafix%2Flibrary-management-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsafix%2Flibrary-management-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsafix%2Flibrary-management-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsafix%2Flibrary-management-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devsafix","download_url":"https://codeload.github.com/devsafix/library-management-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsafix%2Flibrary-management-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266287824,"owners_count":23905461,"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-07-21T11:07:59.142Z","updated_at":"2025-07-21T11:07:59.797Z","avatar_url":"https://github.com/devsafix.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Library Management API\n\nA full-featured Library Management System REST API built with **Express.js**, **TypeScript**, **Mongoose**, and **MongoDB**.\n\n---\n\n## Features\n\n- **Book Management:**\n  - Create, Read, Update, Delete books\n  - Genre filtering and sorting\n  - Proper schema validation with strict rules (required fields, enum, min values, unique ISBN)\n\n- **Borrow Management:**\n  - Borrow books with quantity control\n  - Business logic to check available copies\n  - Automatic stock update after borrowing\n  - Availability flag auto-updates based on remaining copies\n\n- **Aggregation Pipeline:**\n  - Summary report of borrowed books with total quantity borrowed per book\n\n- **Mongoose Instance Methods \u0026 Middleware:**\n  - Instance method for updating stock and availability\n  - Middleware to enforce business rules during borrow creation\n\n- **Filtering \u0026 Sorting:**\n  - Filter books by genre\n  - Sort by any field (ascending or descending)\n  - Limit results\n\n- **Centralized Error Handling:**\n  - Follows generic error response format as specified in assignment\n  - Validation errors, 404 errors, and server errors handled gracefully\n\n---\n\n## Technologies Used\n\n- **Node.js** (Express.js)\n- **TypeScript**\n- **MongoDB** (via Mongoose ODM)\n- **Mongoose Middleware, Aggregation \u0026 Instance Methods**\n- **RESTful API Design**\n\n---\n\n## Getting Started\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/devsafix/library-management-api\ncd library-management-api\n````\n\n### Install Dependencies\n\n```bash\nnpm install\n```\n\n### Create `.env` File\n\nCreate a `.env` file in the root directory and provide your MongoDB connection string:\n\n```bash\nPORT=5000\nDATABASE_URL=mongodb://127.0.0.1:27017/library-management\n```\n\n### Run the Project\n\nFor development mode:\n\n```bash\nnpm run dev\n```\n\nFor production build:\n\n```bash\nnpm run build\nnpm start\n```\n\n---\n\n## API Endpoints\n\n### Books API\n\n| Method | Endpoint         | Description                             |\n| ------ | ---------------- | --------------------------------------- |\n| POST   | `/api/books`     | Create new book                         |\n| GET    | `/api/books`     | Get all books (filter \u0026 sort supported) |\n| GET    | `/api/books/:id` | Get book by ID                          |\n| PATCH  | `/api/books/:id` | Update book                             |\n| DELETE | `/api/books/:id` | Delete book                             |\n\n#### Query Example:\n\n```bash\nGET /api/books?filter=FANTASY\u0026sortBy=createdAt\u0026sort=desc\u0026limit=5\n```\n\n---\n\n### Borrow API\n\n| Method | Endpoint      | Description                                        |\n| ------ | ------------- | -------------------------------------------------- |\n| POST   | `/api/borrow` | Borrow a book (quantity deduction handled)         |\n| GET    | `/api/borrow` | Borrowed books summary (aggregation pipeline used) |\n\n---\n\n## Business Logic Rules\n\n* When borrowing:\n  * System checks available copies using **Mongoose pre-save middleware**\n  * If not enough copies → Error thrown\n  * After successful borrow:\n    * Instance method decreases stock and updates availability\n\n---\n\n## Author\n\n**Kawser Ferdous Safi** – [devsafix.vercel.app](https://devsafix.vercel.app)\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevsafix%2Flibrary-management-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevsafix%2Flibrary-management-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevsafix%2Flibrary-management-api/lists"}