frontend | ||
new_backend | ||
.envrc | ||
.gitignore | ||
flake.lock | ||
flake.nix | ||
README.md |
Url Shortener
Implementation Details
I used Dart/Flutter to write the entire stack. Frontend is flutter compiled to web. Backend uses the dart_frog framework.
Architecture is a simple server that serves the static frontend files on /
and requests to create shortened urls as well as the redirects.
Dart frog does file-based routing similar to Next.js. However, I was unable to get the static content served on /
and get shortened urls to route to /[slug]
so I added them to a sub-route /u/[slug]
.
How to Run
Running with Docker (Simpler)
With docker installed, cd
into the new_backend/build/
directory where the Dockerfile
is located. Build the docker image with
docker build -t <image_name> ./
Once built, run it with:
docker run -d -p 8080:8080 <image_name>
The container port is hard-coded, so you have to use the internal port 8080, the host can be whichever port.
Running the local dev server
Then run the backend with:
cd new_backend/ && dart pub get && dart_frog dev
Testing
I wrote some unit tests to get the url shortening to work, and everything else was tested manually. I also include some asserts in the code to verify the various assumptions I made in the code.
Tools Used
I used various documentation sites, like the one for the dart_frog web framework, as well as the MDN docs for response codes.
I discovered from asking an LLM that I could use the redirection status codes to do the url resolving, but otherwise referenced the docs to decide to use 308.