Hol English lo’lu’.
ghItlh
Why my portfolio has a hexagonal architecture
A personal site is a small app, but it is also a public code sample. Here is how ports and adapters keep it easy to change and easy to read.
A portfolio is usually the smallest app an engineer owns. That makes it tempting to throw everything into a couple of components and move on. Mine is also a public code sample, though, so I wanted it to show how I structure the systems I build at work.
The shape
The code follows ports and adapters, sometimes called hexagonal architecture:
- The core holds the rules. Which language a visitor gets, how translations fall back, which posts are listed. It is plain TypeScript with no framework imports.
- Ports are interfaces the core needs from the outside world, such as "give me every case study" or "turn this Markdown into HTML".
- Adapters implement those ports. Today the content comes from Markdown files bundled into a Cloudflare Worker. Tomorrow it could come from a CMS, and only one adapter would change.
A test reads every import in src/ and fails the build when a layer reaches somewhere it should not. The rule lives in code, not in a wiki page.
Why bother on a small site
Three reasons:
- Testing is cheap. The rules that decide locales and translations run in milliseconds against fictional domains, with no server or browser.
- Change stays local. Swapping the Markdown renderer or the content source touches one adapter and the composition root.
- It reads like the systems I build. If you want to know how I think about frontend platforms, the repository is a better answer than a bullet point.
What it costs
A few more files and one more level of folders. For a project that is meant to be read, that is a fair trade.