{"id":30560189,"url":"https://github.com/huseynovvusal/url-shortener-microservices","last_synced_at":"2025-08-28T10:16:53.893Z","repository":{"id":302614042,"uuid":"1004469431","full_name":"huseynovvusal/url-shortener-microservices","owner":"huseynovvusal","description":"🚀 A modern, scalable URL shortening platform built using microservices architecture.","archived":false,"fork":false,"pushed_at":"2025-07-20T18:02:05.000Z","size":326,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-27T18:47:57.050Z","etag":null,"topics":["api-gateway","clean-architecture","dependency-injection","docker","expressjs","jest","microservices","mongodb","nodejs","postgresql","prisma","rabbitmq","redis","typescript"],"latest_commit_sha":null,"homepage":"","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/huseynovvusal.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-18T17:08:41.000Z","updated_at":"2025-08-16T06:21:19.000Z","dependencies_parsed_at":"2025-07-03T10:38:54.008Z","dependency_job_id":null,"html_url":"https://github.com/huseynovvusal/url-shortener-microservices","commit_stats":null,"previous_names":["huseynovvusal/url-shortener-microservices"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/huseynovvusal/url-shortener-microservices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huseynovvusal%2Furl-shortener-microservices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huseynovvusal%2Furl-shortener-microservices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huseynovvusal%2Furl-shortener-microservices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huseynovvusal%2Furl-shortener-microservices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huseynovvusal","download_url":"https://codeload.github.com/huseynovvusal/url-shortener-microservices/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huseynovvusal%2Furl-shortener-microservices/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272481835,"owners_count":24941816,"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","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"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":["api-gateway","clean-architecture","dependency-injection","docker","expressjs","jest","microservices","mongodb","nodejs","postgresql","prisma","rabbitmq","redis","typescript"],"created_at":"2025-08-28T10:16:48.787Z","updated_at":"2025-08-28T10:16:53.871Z","avatar_url":"https://github.com/huseynovvusal.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 URL Shortener Microservices\n\nA modern, scalable URL shortening platform built using microservices architecture. This project demonstrates my skills and best practices in building distributed systems with Node.js, TypeScript, Docker, Redis caching, and RabbitMQ event-driven communication.\n\n## 📋 Overview\n\nThis robust URL shortener service provides:\n\n- ✅ Fast URL shortening with custom or auto-generated codes\n- ✅ User authentication and management\n- ✅ Comprehensive analytics and tracking\n- ✅ Scalable microservices architecture with distributed data stores\n- ✅ High-performance caching using Redis\n- ✅ Event-driven architecture with RabbitMQ\n- ✅ Containerized deployment with Docker\n\n## 🏗️ Architecture\n\n```mermaid\n%%{init: {'theme': 'base', 'themeVariables': { 'darkMode': true, 'background': '#333', 'primaryTextColor': '#fff' }}}%%\ngraph TD\n    Client([Client/Browser]) --\u003e Gateway[API Gateway]\n\n    subgraph \"URL Shortener System\"\n        Gateway --\u003e |Auth Requests| UserService[User Service]\n        Gateway --\u003e |URL Requests| URLService[URL Service]\n        Gateway --\u003e |Analytics Requests| AnalyticsService[Analytics Service]\n\n        URLService --\u003e |Publishes Events| RabbitMQ{RabbitMQ}\n        RabbitMQ --\u003e |Consumes Events| AnalyticsService\n\n        URLService --\u003e MongoDB[(MongoDB)]\n        URLService --\u003e Redis[(Redis Cache)]\n        UserService --\u003e PostgreSQL[(PostgreSQL)]\n        AnalyticsService --\u003e MongoDB\n\n        subgraph \"User Service\"\n            UserService --\u003e UserController[Controller]\n            UserController --\u003e UserService_Service[Service]\n            UserService_Service --\u003e UserRepository[Repository]\n            UserRepository --\u003e PostgreSQL\n        end\n\n        subgraph \"URL Service\"\n            URLService --\u003e URLController[Controller]\n            URLController --\u003e URLService_Service[Service]\n            URLService_Service --\u003e URLRepository[Repository]\n            URLRepository --\u003e MongoDB\n            URLService_Service --\u003e URLCache[Cache]\n            URLCache --\u003e Redis\n        end\n\n        subgraph \"Analytics Service\"\n            AnalyticsService --\u003e AnalyticsController[Controller]\n            AnalyticsController --\u003e AnalyticsService_Service[Service]\n            AnalyticsService_Service --\u003e AnalyticsRepository[Repository]\n            AnalyticsRepository --\u003e MongoDB\n            RabbitMQ --\u003e AnalyticsConsumer[Consumer]\n            AnalyticsConsumer --\u003e AnalyticsService_Service\n        end\n    end\n\n    class Client,Gateway,UserService,URLService,AnalyticsService,RabbitMQ,MongoDB,Redis,PostgreSQL,UserController,UserService_Service,UserRepository,URLController,URLService_Service,URLRepository,URLCache,AnalyticsController,AnalyticsService_Service,AnalyticsRepository,AnalyticsConsumer nodeStyle\n\n    %% Styles that work in both light and dark modes\n    classDef nodeStyle fill:#f9f9f9,stroke:#333,stroke-width:1px,color:#333\n    classDef microservice fill:#d1f0fd,stroke:#0078d4,stroke-width:2px,color:#333\n    classDef database fill:#e7f5d7,stroke:#5ca53a,stroke-width:2px,color:#333\n    classDef messagebroker fill:#fde7c7,stroke:#ff8c00,stroke-width:2px,color:#333\n    classDef gateway fill:#e7d1fd,stroke:#7b2cbf,stroke-width:2px,color:#333\n    classDef client fill:#f5f5f5,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5,color:#333\n\n    class UserService,URLService,AnalyticsService microservice\n    class MongoDB,PostgreSQL,Redis database\n    class RabbitMQ messagebroker\n    class Gateway gateway\n    class Client client\n```\n\n## 🧩 Architectural Patterns \u0026 Design Principles\n\nThis project implements several industry-standard architectural patterns and design principles:\n\n### Clean Architecture\n\n- **Separation of Concerns**: Each service is organized into layers with clear boundaries\n- **Domain-Driven Design**: Business logic is isolated from infrastructure concerns\n- **Use Cases**: Business rules are defined as use cases in service layers\n- **Dependency Rule**: Dependencies point inward, with inner layers unaware of outer layers\n\n### Dependency Injection (DI)\n\n- **Inversion of Control**: Using TypeScript-based DI containers for service instantiation\n- **Testability**: Dependencies can be easily mocked for unit testing\n- **Loose Coupling**: Components interact through abstractions rather than concrete implementations\n\n### Repository Pattern\n\n- **Data Access Abstraction**: Repository interfaces isolate business logic from data access\n- **Persistence Ignorance**: Business logic remains independent of specific database implementations\n- **Interchangeable Data Sources**: Ability to swap MongoDB, PostgreSQL, or other datastores with minimal code changes\n\n### SOLID Principles\n\n- **Single Responsibility**: Each class and module has one clear responsibility\n- **Open/Closed**: Entities are open for extension but closed for modification\n- **Liskov Substitution**: Interfaces are designed to ensure subtypes can be substituted for base types\n- **Interface Segregation**: Small, focused interfaces prevent unnecessary dependencies\n- **Dependency Inversion**: High-level modules depend on abstractions, not concrete implementations\n\n### Event-Driven Architecture\n\n- **Message Brokers**: RabbitMQ facilitates loose coupling between services\n- **Asynchronous Communication**: Services communicate through events without direct dependencies\n- **Eventual Consistency**: Data is synchronized across services asynchronously\n- **Fault Tolerance**: Services can continue to operate despite failures in other services\n\n### API Gateway Pattern\n\n- **Single Entry Point**: Unified API interface for all client communications\n- **Cross-Cutting Concerns**: Centralized handling of authentication, logging, and monitoring\n- **Request Routing**: Dynamic routing of requests to appropriate microservices\n- **API Composition**: Aggregation of data from multiple services for client requests\n\nThe system consists of four main microservices:\n\n### 1. API Gateway\n\n- Entry point for all client requests\n- Handles request routing to appropriate services\n- Implements rate limiting, security headers, and request validation\n- Authentication middleware for protected endpoints\n\n### 2. URL Service\n\n- Core service for URL shortening functionality\n- Creates and stores short URLs with MongoDB\n- Uses Redis for caching frequently accessed URLs\n- Publishes analytics events to RabbitMQ\n\n### 3. User Service\n\n- Manages user registration and authentication\n- Stores user data in PostgreSQL with Prisma ORM\n- Handles JWT token generation and validation\n- Password encryption with bcrypt\n\n### 4. Analytics Service\n\n- Processes URL access events from RabbitMQ\n- Tracks and stores analytics data in MongoDB\n- Provides detailed analytics on URL performance\n- Captures data on geographic location, referrers, browsers, devices, and OS\n\n## 💾 Data Storage\n\n- **PostgreSQL**: User accounts and related data\n- **MongoDB**: URL mappings and analytics information\n- **Redis**: High-performance caching for frequent URL lookups\n- **RabbitMQ**: Message broker for event-driven communication between services\n\n## 🔧 Tech Stack\n\n- **Backend**: Node.js, Express, TypeScript\n- **Databases**: PostgreSQL, MongoDB, Redis\n- **Message Queue**: RabbitMQ\n- **ORM/ODM**: Prisma (PostgreSQL), Mongoose (MongoDB)\n- **Authentication**: JWT, bcrypt\n- **Containerization**: Docker, Docker Compose\n- **Testing**: Jest\n- **Code Quality**: ESLint, Prettier\n\n## 🛠️ Setup \u0026 Installation\n\n### Prerequisites\n\n- Docker and Docker Compose\n- Node.js (for local development)\n\n### Quick Start\n\n1. Clone the repository\n\n```bash\ngit clone https://github.com/yourusername/url-shortener-microservices.git\ncd url-shortener-microservices\n```\n\n2. Create `.env` files for each service (see `.env.example` in each service directory)\n\n3. Start all services using Docker Compose\n\n```bash\ncd volumes\ndocker-compose up -d\n```\n\n4. The services will be available at:\n   - API Gateway: http://localhost:3000\n   - User Service: http://localhost:3001\n   - URL Service: http://localhost:3002\n   - Analytics Service: http://localhost:3003\n\n### Local Development\n\nEach service can be run independently for development:\n\n```bash\ncd \u003cservice-directory\u003e\nnpm install\nnpm run dev\n```\n\n## 📊 API Documentation\n\n### URL Service\n\n- `POST /api/urls` - Create a new short URL\n- `GET /api/urls` - Get all URLs for authenticated user\n- `GET /:shortCode` - Redirect to the original URL\n\n### User Service\n\n- `POST /api/users/register` - Register a new user\n- `POST /api/users/login` - Login and get token\n- `GET /api/users/me` - Get current user details\n\n### Analytics Service\n\n- `GET /api/analytics/:urlId` - Get analytics for a specific URL\n\n## 🚀 Future Improvements\n\n- Web dashboard for user management and analytics\n- Custom domain support\n- Advanced analytics visualizations\n- QR code generation for short URLs\n- Expiration dates for links\n- API rate limiting tiers\n- ELK Stack (Elasticsearch, Logstash, Kibana) for centralized logging and monitoring\n\n## 👤 Author\n\nCreated by Vusal Huseynov as a demonstration of microservices architecture best practices using modern web technologies.\n\n---\n\n⭐ If you find this project useful, please consider giving it a star!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuseynovvusal%2Furl-shortener-microservices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuseynovvusal%2Furl-shortener-microservices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuseynovvusal%2Furl-shortener-microservices/lists"}