How yuvii-b/url-shortener works
Project Type and Purpose
• This is a C++-based URL Shortening service with two front-ends:
• A terminal/console application (app.cpp)
• A lightweight HTTP server with web UI (using Crow-CPP)
• Core goal: take long URLs, generate short numeric codes, store/retrieve them in SQLite, and redirect browser requests.
File Structure
• Top level:
• Makefile, run.sh – build and orchestrate processes
• app.cpp – console UI launcher
• README.md – user/developer guide
• db/ – database module
• db.cpp/.hpp – SQLite wrapper
• libs/ – static libsqlite3.a + headers
• shortener/ – core business logic
• url_shortener.cpp/.hpp – hashing, code generation, lookup
• server/ – HTTP server
• http_server.cpp/.hpp – Crow routes for shortening & redirect
• server_test.cpp – unit tests for server functionality
• frontend/ – web UI assets
• main.cpp – entry to spin up web UI (if separate) or client code
• templates/index.html – user-friendly form
README for Architectural Clues
• Two executables: “server” (Crow HTTP service) and the CLI tool.
• Shared dependency on the core URL shortener library and SQLite DB.
• run.sh starts both processes and monitors for crashes.
a. Main Components
1. Users & Clients
– CLI user (terminal)
– Web browser
2. Applications
– Console App (app.cpp)
– HTTP Server (http_server.cpp + Crow)
3. Core Service Layer
– URL Shortener Library (shortener/url_shortener.cpp)
4. Data Store
– SQLite Database (db/db.cpp + libsqlite3.a)
5. Orchestration Script
– run.sh (process manager)
b. Relationships & Interactions
– CLI App → URL Shortener → SQLite (CREATE/READ)
– Browser → HTTP Server → URL Shortener → SQLite (LOOKUP)
– HTTP Server serves static files (templates/index.html)
– run.sh launches & supervises CLI App & HTTP Server
c. Architectural Patterns & Principles
– Layered Architecture: Presentation (CLI/HTTP) → Business Logic (Shortener) → Persistence (SQLite)
– Single Responsibility: distinct modules for DB access, core logic, HTTP handling, UI
– Dependency Injection (linking shared library code into both server and CLI at build time)
d. Key Technologies & Frameworks
– C++17
– Crow-CPP (HTTP server & routing)
– SQLite (embedded RDBMS)
– Makefile for build automation
– run.sh for process orchestration