How raahthor/url-shortener works
Project type and purpose
• This is a full-stack URL Shortener application built on the PERN stack (PostgreSQL, Express.js, React, Node.js).
• Its core purpose is to allow users (guests or registered) to shorten long URLs, track click statistics, and manage links via a web interface.
File structure
• Top-level directories:
• Backend – Express.js server with subdirectories for Controllers, DB, Models, and Routes.
• Frontend – React application with Tailwind CSS, Vite build, and component structure under src.
• Backend follows an MVC-style pattern:
• Controllers handle request logic (authenticator, URL storage, user storage).
• Models define ORM schemas for users and URLs (syncModels, users.model.js, urls.model.js).
• DB contains database initialization (database.js).
• Routes file (routes.js) maps HTTP endpoints to controllers.
• Frontend uses component-driven design:
• src/components holds UI pieces (forms, buttons, cards, routing pages).
• Utility functions (src/lib/utils.js) and Tailwind configuration manage styling.
• Config and deployment artifacts:
• Frontend/vite.config.js and Backend/package.json for builds.
• Frontend/vercel.json for Vercel deployment.
Extract insights from README
• Tech stack: React + Tailwind CSS on the client; Node + Express + JWT + bcrypt on the server; PostgreSQL as the persistent layer.
• Key functional areas: URL shortening API, user authentication (JWT, bcrypt), click-tracking analytics, guest versus registered modes.
a. Main components
• Client (React SPA)
• API Server (Node.js + Express.js)
• PostgreSQL Database
• Authentication subsystem (JWT issuance/verification, bcrypt hashing)
• Optional: External deployment platform (e.g., Vercel for frontend, Heroku/AWS for backend)
b. Relationships and data flows
• The React client issues HTTP(S) requests to Express endpoints:
– POST /signup, /login → handles user creation and token issuance
– POST /shorten → saves a new shortened URL
– GET /:shortId → redirects to original URL and increments click counter
– GET /stats → returns click statistics (authorized)
• Express communicates with PostgreSQL via an ORM or raw queries (database.js + syncModels).
• JWT tokens are generated by the authenticator controller and validated on protected routes.
c. Architectural patterns and principles
• MVC on the server: clear separation between routing (routes.js), business logic (controllers), and data models.
• Single-page application on the client: React components handle routing and UI state.
• RESTful API endpoints for CRUD operations on URLs and user sessions.
• Stateless authentication with JWT to allow horizontal scaling of the API.
d. Key technologies and libraries
• Frontend: React, Vite, Tailwind CSS, utility components (button, input, card).
• Backend: Express.js, pg or Sequelize/ORM layer (syncModels), jsonwebtoken, bcrypt.
• Database: PostgreSQL, with connection pooling in database.js.