{"id":50892993,"url":"https://github.com/manojkp08/url-shortner","last_synced_at":"2026-06-15T22:01:59.426Z","repository":{"id":306481352,"uuid":"1026099091","full_name":"manojkp08/url-shortner","owner":"manojkp08","description":"A lightweight, Flask-based URL shortener service with analytics and thread-safe operations.","archived":false,"fork":false,"pushed_at":"2026-06-02T03:14:57.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-02T05:09:23.245Z","etag":null,"topics":["flask","pytest","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/manojkp08.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-25T09:57:04.000Z","updated_at":"2026-06-02T03:15:01.000Z","dependencies_parsed_at":"2025-07-26T01:08:16.454Z","dependency_job_id":"481c7800-8653-4b63-aefd-32b7a1ec9241","html_url":"https://github.com/manojkp08/url-shortner","commit_stats":null,"previous_names":["manojkp08/url-shortner_retainsuresde-intern","manojkp08/url-shortner"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/manojkp08/url-shortner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojkp08%2Furl-shortner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojkp08%2Furl-shortner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojkp08%2Furl-shortner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojkp08%2Furl-shortner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manojkp08","download_url":"https://codeload.github.com/manojkp08/url-shortner/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojkp08%2Furl-shortner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34381762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"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":["flask","pytest","python"],"created_at":"2026-06-15T22:01:56.322Z","updated_at":"2026-06-15T22:01:59.418Z","avatar_url":"https://github.com/manojkp08.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener API\n\nA lightweight, Flask-based URL shortener service with analytics and thread-safe operations.\n\n## Features\n\n- **URL Shortening**: Generate 6-character alphanumeric short codes for long URLs\n- **Redirect Service**: Fast O(1) lookup and redirect to original URLs  \n- **Click Analytics**: Track and view click statistics for shortened URLs\n- **Thread Safety**: Concurrent request handling with proper synchronization\n- **URL Validation**: Input validation for proper URL format\n- **In-Memory Storage**: Simple, fast storage without external database dependencies\n\n## Technical Stack\n\n- **Python**: 3.8+\n- **Framework**: Flask 2.3.2\n- **Testing**: pytest 7.4.0\n- **Concurrency**: Threading with locks for thread safety\n\n## Installation\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/manojkp08/url-shortner_retainsureSDE-intern.git\ncd url-shortner_retainsureSDE-intern\n```\n\n2. Install dependencies:\n```bash\npip install -r requirements.txt\n```\n\n3. Start the server:\n```bash\npython -m flask --app app.main run\n```\n\nThe API will be available at `http://localhost:5000`\n\n## API Endpoints\n\n### Shorten URL\nCreate a short URL from a long URL.\n\n```http\nPOST http://localhost:5000/api/shorten\nContent-Type: application/json\n\n{\n  \"url\": \"https://www.nvidia.com/en-us/geforce/campaigns/back-to-school/?nvid=nv-int-drvr-637258\"\n}\n```\n\n**Response:**\n```json\n{\n  \"short_code\": \"xyh635\",\n  \"short_url\": \"http://localhost:5000/xyh635\"\n}\n```\n\n### Redirect\nRedirect to the original URL using the short code.\n\n```http\nGET http://localhost:5000/\u003cshort_code\u003e\nexample:\nGET http://localhost:5000/xyh635\n```\n\nReturns a 302 redirect to the original URL.\n\n### Get Statistics\nView click analytics for a shortened URL.\n\n```http\nGET http://localhost:5000/api/stats/\u003cshort_code\u003e\nexample:\nGET http://localhost:5000/api/stats/xyh635\n```\n\n**Response:**\n```json\n{\n  \"short_code\": \"xyh635\",\n  \"original_url\": \"https://www.nvidia.com/en-us/geforce/campaigns/back-to-school/?nvid=nv-int-drvr-637258\",\n  \"click_count\": 15\n}\n```\n\n## Usage Examples\n\n# URL Shortener API Commands\n\n## For Mac/Linux\n\n### Step 1: Shorten a URL\n```bash\ncurl -X POST http://localhost:5000/api/shorten \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"url\":\"https://www.nvidia.com/en-us/geforce/campaigns/back-to-school/?nvid=nv-int-drvr-637258\"}'\n```\n\n### Step 2: Follow redirect (browser or CLI)\n```bash\ncurl -L http://localhost:5000/\u003cshort-code\u003e\n```\n**NOTE:** Replace `\u003cshort-code\u003e` with the actual code from Step 1 (e.g., `xyh635`)\n\n### Step 3: Get click statistics\n```bash\ncurl http://localhost:5000/api/stats/xyh635\n```\n\n---\n\n## For Windows (Command Prompt)\n\n### Step 1: Shorten a URL\n```cmd\ncurl -X POST http://localhost:5000/api/shorten ^\n  -H \"Content-Type: application/json\" ^\n  -d \"{\\\"url\\\":\\\"https://www.nvidia.com/en-us/geforce/campaigns/back-to-school/?nvid=nv-int-drvr-637258\\\"}\"\n```\n\n### Step 2: Follow redirect (browser or CLI)\n```cmd\ncurl -L http://localhost:5000/\u003cshort-code\u003e\n```\n**NOTE:** Replace `\u003cshort-code\u003e` with the actual code from Step 1 (e.g., `xyh635`)\n\n### Step 3: Get click statistics\n```cmd\ncurl http://localhost:5000/api/stats/xyh635\n```\n\n---\n\n## For Windows (PowerShell)\n\n### Step 1: Shorten a URL\n```powershell\nInvoke-WebRequest -Uri http://localhost:5000/api/shorten -Method POST -ContentType \"application/json\" -Body '{\"url\":\"https://www.example.com\"}'\n\n# Example:\n\n#Request\nInvoke-WebRequest -Uri http://localhost:5000/api/shorten -Method POST -ContentType \"application/json\" -Body '{\"url\":\"https://www.nvidia.com/en-us/geforce/campaigns/back-to-school/?nvid=nv-int-drvr-637258\"}'\n\n#Response:\n{\"clicks\":1,\"created_at\":\"2025-07-26T22:01:11.850290\",\"url\":\"https://www.nvidia.com/en-us/geforce/c                     ampaigns/back-to-school/?nvid=nv-int-drvr-637258\"}\n\n```\n\n### Step 2: Follow redirect (browser or CLI)\n```powershell\nInvoke-WebRequest -Uri http://localhost:5000/\u003cshort-code\u003e\n\n#Example:\n\n#Request:\nInvoke-WebRequest -Uri http://localhost:5000/Wml1y3\n\n#Response:\nWebpage will be visible on your browser once you visit through the short url !\n```\n**NOTE:** Replace `\u003cshort-code\u003e` with the actual code from Step 1 (e.g., `xyh635`) and open the link in your browser.\n\n### Step 3: Get click statistics\n```powershell\nInvoke-WebRequest -Uri http://localhost:5000/api/stats/\u003cshort-code\u003e\n\n#Example:\n\n#Request:\nInvoke-WebRequest -Uri http://localhost:5000/api/stats/Wml1y3\n\n#Response\n{\"short_code\":\"Wml1y3\",\"short_url\":\"http://localhost:5000/Wml1y3\"}\n```\n\n**NOTE:** Replace `\u003cshort-code\u003e` with the actual code from Step 1 \n---\n\n## Key Differences\n\n- **Mac/Linux**: Uses backslash `\\` for line continuation and single quotes for JSON\n- **Windows CMD**: Uses caret `^` for line continuation and escaped double quotes `\\\"` for JSON\n- **Windows PowerShell**: Uses backtick `` ` `` for line continuation and single quotes for JSON (similar to Mac/Linux)\n\n\n```\n\n## Testing\n\nRun the test suite:\n\n```bash\npytest\n```\n\n### Test Coverage\n\nThe project includes comprehensive tests covering:\n\n- **Health Check**: API status verification\n- **URL Shortening**: Core shortening functionality\n- **Redirect**: URL redirection behavior\n- **Error Handling**: Invalid URL validation\n- **Analytics**: Click statistics accuracy\n- **Concurrency**: Thread-safe operations\n\n## Architecture\n\n### Data Structures\n\n- `url_mappings`: Dictionary storing short_code → URLMapping objects\n- `click_counts`: Dictionary tracking visit counts per short code\n\n### Thread Safety\n\nCritical operations are protected using Python's threading.Lock:\n\n```python\nfrom threading import Lock\n\nlock = Lock()\n\nwith lock:\n    # Thread-safe operations\n    click_counts[short_code] += 1\n```\n\n### Performance\n\n- **O(1) lookup time** for all operations\n- **Thread-safe increments** for click tracking\n- **Minimal memory footprint** with in-memory storage\n\n## Error Handling\n\n- **400 Bad Request**: Invalid URL format\n- **404 Not Found**: Short code does not exist\n- **500 Internal Server Error**: Server-side errors\n\n## Design Decisions\n\n### Simplicity First\n- In-memory storage for MVP deployment\n- Minimal external dependencies\n- Clear separation of concerns\n\n### Scalability Considerations\n- Thread-safe operations for concurrent requests\n- Efficient data structures for fast lookups\n- Modular design for easy extension\n\n## Development Notes\n\n- **Development Time**: Approximately 2.5 hours\n- **Primary Challenge**: Thread safety implementation\n- **Code Quality**: Clean, well-documented code with comprehensive tests\n\n## Requirements\n\nSee `requirements.txt` for complete dependency list:\n\n```\nFlask==2.3.2\npytest==7.4.0\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests for new functionality\n5. Ensure all tests pass\n6. Submit a pull request\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojkp08%2Furl-shortner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanojkp08%2Furl-shortner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojkp08%2Furl-shortner/lists"}