How deep0902/url-shortner works
Project Type and Purpose
• This is a modern, full-stack URL shortener application.
• Frontend: React + TypeScript + Vite, served on Vercel.
• Backend: Node.js + Express + MongoDB (using Mongoose), deployed on Vercel.
• Purpose: allow users to register/login, shorten URLs, redirect short URLs, track statistics, and generate QR codes.
High-Level Architecture & Main Components
• Frontend Application
• React components (src/components, Reactbits)
• ThemeContext, shared utilities (lib/utils.ts)
• Service worker (dev-dist/registerSW.js) for PWA features
• Vite build and config (vite.config.ts)
• Backend API
• Express server (backend/index.js)
• Routing layer (routes/…)
• Controller logic (controllers/…)
• Middlewares (auth, rate limiting, compression)
• Data models (Mongoose schemas in models/…)
• Database
• MongoDB Atlas cluster (environment-configured)
• External Services
• Vercel for hosting frontend and backend
• MongoDB Atlas
• Optional: third-party QR code generation library
Component Relationships and Data Flow
• User interacts with React UI ➔ React component calls Axios against REST API (backend).
• Frontend HTTP requests hit Express routes:
• /api/register, /api/login ➔ loginController.js / userController.js
• /api/shorten ➔ urlController.js
• /api/stats ➔ urlController.js
• /:shortUrl ➔ redirectRoutes ➔ urlController.js
• Controllers talk to Mongoose models (users.model.js, url.model.js).
• Models read/write to MongoDB Atlas.
• On protected routes, auth middleware validates JWT / API key.
• Express uses other middlewares (rate limiter, compression).
• Responses (JSON, redirect status) return to frontend for rendering.
Architectural Patterns and Key Principles
• MVC-like separation: Routes → Controllers → Models.
• RESTful API design for CRUD operations.
• JWT and API-key based authentication and authorization.
• Environment-based configuration (.env, VERCEL env).
• Component-based UI in React; context for theme & shared state.
• Progressive enhancement via service worker.