How rmahsanfaraz/url-shortner works
Project type and purpose
• This is a monolithic, full-stack web application: a PHP-based URL shortener with a MySQL database.
• It provides both a user-facing UI (shorten URLs, copy/share, QR code) and a management UI (list, delete, analytics).
File structure
• Top-level files:
• index.php & manage.html → two entry points (main UI and management UI)
• config.php → central database configuration
• shorten.php, redirect.php, analytics.php, list.php, delete.php, qrcode.php → backend “API” endpoints
• style.css, scripts.js, manage.js → front-end assets
• database.sql, migration.sql → schema creation and migration
• No separate “frontend” or “backend” directories—but logically we can group by UI vs. API vs. data.
Examining the README
• Confirms MVC-style separation: UI pages call JavaScript, which issues HTTP requests to PHP endpoints.
• Describes all features, API contracts, and external dependency (Google Charts for QR codes).
a. Main components
1. Client (Web Browser)
• Renders index.php or manage.html
• Hosts JavaScript (scripts.js, manage.js) and CSS
2. Web Server / PHP Runtime
• Serves static assets and executes PHP scripts
• Houses all “controllers” (shorten.php, redirect.php, analytics.php, list.php, delete.php, qrcode.php)
• Uses config.php to connect to the database
3. MySQL Database
• Single table urls with columns for code, original URL, created_at, expires_at, last_accessed, visit_count
4. External Service
• Google Charts API (via qrcode.php) for QR code generation
b. Relationships and interactions
• Browser → HTTP GET/POST → Web Server
• index.php loads HTML/CSS/JS → JS calls shorten.php (POST), list.php (GET), delete.php (DELETE), analytics.php (GET), qrcode.php (GET)
• redirect.php is invoked by any visitor clicking the short URL → queries DB → issues HTTP redirect
• PHP endpoints ↔ MySQL over standard TCP (port 3306)
• qrcode.php → HTTP call to Google Charts → returns QR image URL
c. Architectural patterns and principles
• Monolithic, single-tier architecture deployed on one host
• Logical separation:
• Presentation layer (HTML/CSS/JS)
• Application/API layer (PHP scripts)
• Data layer (MySQL)
• REST-style endpoints for CRUD operations
• Configuration centralization in config.php
d. Key technologies
• Frontend: HTML5, CSS3, vanilla JavaScript
• Backend: PHP 7.x+ on Apache/Nginx
• Database: MySQL/MariaDB
• External: Google Charts API for QR
Detail
• PHP endpoint as its own sub-component
• Config.php as the single source of DB connection properties
• Optional expiration logic and visit_count update in the redirect flow
• Don’t overcomplicate: the goal is clarity of how browsers, PHP scripts, the DB, and the QR service interact