I am assuming no authentication requirements, anyone with access to the website is able to shorten a link.
The api should have 2 main methods: one to add a link to the url shortner, and a second one to get the original link from a shortened link
/shorten/ POST - body: {originalLink: string}, result: {shortLink: string}
/original-link/$shortLink GET - query: {shortLink: string}, result: {originalLink: string}
In addition, an administration page should view all current links and their shortcuts, edit them, as well as remove any they'd like. That implies the following:
/links/ GET/filter - query: {page: integer, filter: string}, result: { mapping: {shortLink: string, originalLink: string}[] }
/links/ DELETE - body: {shortLink: string}
/links/ PUT - body: {shortLink: string, newShortLink: string, originalLink: string, newOriginalLink: string}
The admin page needs some sort of auth, which we will implement using DB authentication levels and a localhosted website that is unavailable to the public. That means the 3 additional API's nested under links are not available from the server.
3 main components: Server, Client and Database.
Database keeps track of the links and their shortcuts. 1 relational DB table should suffice, with the shortLink as the primary key to ensure quick searching for the link its a shortcut for.
Server for interacting with the DB, implementing the API, and for encapsulation.
Client for creation of links and renavigation when using them. Will have a page for adding links, and will route every shortlink request to its destination.
Additional client for the admin page, not deployed publiclly.
# Deep dive to the DB
Choosing Postgres out of familiarity.
1 Table for the shortcuts and their destinations. An index on both rows (default index on the primary key)
3 users, SUPERUSER that is unused in the application, SERVER with write and read auth, ADMIN with full auth to the table.
The server has access to the SERVER user, and will implement the 2 api calls to add and follow a link.
The client has no access to any DB user, will only use API calls.
The localhosted admin page will have access to the ADMIN user.
# Deep dive to the client
Simple web page, no room for expanding much, can be done with pure html and javascript to avoid bloat.
Main route will be composed with an input for the link you want shortened. After pressing submit, loading will occur until the result comes back, after which it is displayed and copyable.
The shortened links will be accessed through the /link/$shortlink route. Each time the website gets a request, it will first check if the route matches the shorturl regex, then if it does it will send an api call to get the originalLink from the server, and reroute there.
If the server returns a Not Found result, reroute to a special 404 page.