Hexagonal architecture

육각형 아키텍처

Business logic exposes ports; external technologies connect through adapters.

···
html
<div class="scene"><div class="title">DOMAIN PORTS & ADAPTERS</div><div class="row hex"><div class="tile">HTTP<br>ADAPTER</div><div class="ring"><div>INPUT PORT</div><strong>ORDER RULES</strong><div>STORE PORT</div></div><div class="tile" id="adapter">SQL<br>ADAPTER</div></div><div class="muted" id="swap">Core stays the same when adapters change</div></div>
css
.scene{width:min(94vw,760px);height:min(86vh,320px);padding:clamp(10px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);font:500 clamp(11px,1.3vw,16px)/1.25 "Pretendard Variable",Pretendard,-apple-system,sans-serif;display:flex;flex-direction:column;gap:clamp(7px,1.6vmin,12px);overflow:hidden}.scene *{box-sizing:border-box}.title{font-weight:750;color:var(--accent)}.muted{color:var(--muted)}.mono{font-family:ui-monospace,monospace}.row{display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.4vmin,12px);flex:1;min-height:0}.tile{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(6px,1.6vmin,12px);text-align:center;min-width:0}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 12%,var(--surface))!important}.pulse{animation:pulse 1.6s infinite alternate}@keyframes pulse{to{border-color:var(--accent);transform:translateY(-3px)}}.hex .tile{flex:1}.ring{border:3px solid var(--accent);border-radius:40%;padding:clamp(7px,2vmin,16px);text-align:center;display:grid;gap:5px;min-width:42%}.ring strong{color:var(--accent)}.ring div{font-size:1em;color:var(--muted)}
js
let memory=false;function tick(){memory=!memory;document.getElementById('adapter').innerHTML=memory?'MEMORY<br>ADAPTER':'SQL<br>ADAPTER';document.getElementById('adapter').classList.toggle('on',memory);document.getElementById('swap').textContent=memory?'Tests use an in-memory adapter':'Production uses a SQL adapter'}tick();setInterval(tick,1500)

Hexagonal architecture keeps domain logic independent of HTTP or a particular database. The domain defines ports that input and output adapters implement.

The demo swaps SQL and in-memory storage while order rules stay unchanged. For simple CRUD, extra abstractions may add more complexity than value.

When to use

Use it when business rules need testing apart from external systems or replaceable storage.

Open as page ↗