How wtrbtl03/url-shortner works
Project type and purpose
• This is a Django-based full-stack web application that provides URL shortening functionality.
• The README points to a “getPico.Link” project, confirming this is an open-source URL shortener built on Django.
File structure
• Top-level Django project folder: URLShortner/ (contains settings, ASGI/Wsgi, urls).
• Two Django apps:
• home/ – likely handles the landing page, index view, basic templates.
• maps/ – contains models for URL ↔ code mapping, forms (input_field_form), resolve logic.
• Static assets: static/script.js, static/style.css.
• Templates: index.html, test.html, 404.html.
• Database: db.sqlite3.
• manage.py – entry point for dev commands.
Key insights from the README
• Uses Django’s built-in server stack (ASGI/Wsgi), SQLite for persistence.
Main components
a. Client Browser (User Interface)
– Renders HTML templates, runs script.js for dynamic form behavior, uses style.css.
b. Load Balancer / Web Server (optional in prod)
– Could be NGINX or Gunicorn/uvicorn to serve ASGI/Wsgi endpoints.
c. Django Application Layer
– URLShortner project module (settings, URL router)
– home app (views.index, views.test)
– maps app (views.create_short_url, views.resolve_short_url, input_field_form)
– Django Admin interface (home/admin.py, maps/admin.py)
d. Persistence Layer
– SQLite (db.sqlite3) storing URL mappings via maps.models
e. Static Asset Server or CDN
– Serves static/script.js, static/style.css
f. External Services (optional/extension)
– Could add caching (Redis) or analytics services
Relationships and data flows
1. Client → HTTP POST /create/short/ via maps app → Django views → maps.models.save(original_url, code) → DB insert.
2. Django → returns short URL in JSON or HTML response → Client displays it.
3. Client (or any user) → HTTP GET // → maps.resolve view → DB lookup → HTTP 302 redirect to original URL.
4. home/index view serves landing page (HTTP GET /).
5. Static files served either by Django’s staticfiles or external server.
6. Django Admin → HTTP requests to /admin/ for CRUD management of URL entries.
Architectural patterns and design principles
• MVC/MVT pattern (Django’s Model-View-Template)
• Separation of concerns:
• home app for generic pages
• maps app for core URL mapping logic
• static/templates separated from Python code
• Single-database design (SQLite) – easy to swap to PostgreSQL in production.
• RESTful endpoints for create and resolve operations.