How shreyasganesh911/swifturl works
Main Components
• Client/External User: Initiates URL shortening requests and analytics lookups.
• API Gateway/Server: The Node.js/Fastify web server handling incoming HTTP requests.
• Middleware Components:
• Rate Limiter (Redis based)
• JWT Authentication (auth middleware)
• Controllers: Handle the logic for API endpoints (e.g., user, URL, and analytics).
• Routes: Map endpoints to controllers (organized under /src/routes).
• Models & Database Layer:
• MongoDB for storing user and URL details
• Redis for caching (fast URL lookup) and implementing rate limiting.
• Utilities:
• Cloudinary integration for QR code generation.
• QR Code Generation Utility.
• Asynchronous request handling (error wrapper).
• External Services:
• MongoDB and Redis instances
• Cloudinary for media storage
Relationships and Interactions
• User Requests hit the Node.js/Fastify server through API endpoints (as defined in the routes).
• Requests are first processed by middleware (e.g., “rateLimiter” to check for abuse, “auth” for secure endpoints).
• If allowed, controllers process the request:
• They may call the caching utility to check if the URL is already in Redis.
• In case of a cache miss, the controller will interact with the MongoDB layer (using models and db modules) and then populate the Redis cache.
• For QR code functionalities, the utility handling Cloudinary integration is invoked.
• The README flowchart specifically illustrates how a request is checked against Redis first. If the data is present (cache hit), cached data is returned. Otherwise, the system queries MongoDB, updates Redis, and sends the response.
• Additionally, authentication-related endpoints use JWT tokens for managing sessions.
Architectural Patterns and Design Principles
• Modular Pattern: Clear separation of concerns (controllers, routes, middleware, db services).
• Caching Pattern: Use of Redis to improve response times and offload MongoDB queries.
• API Layer Abstraction: Cleanly defined RESTful endpoints.
• Security: JWT-based user authentication and rate limiting to mitigate abuse.
• Utility/Helper Functions: Centralized error and asynchronous handling as well as integration services (Cloudinary).
Diagramming Tools and Detail
• Including a side note or zoomed-in portion for the caching flow (as per the README’s flowchart) demonstrating how a URL shortening request is processed step-by-step.