API gateway
One front door that checks who is calling, limits how often, and routes the call on.
The CityScript
This is all there is to it. Change it in the editor and the city redraws.
%% A · API gateway
%% Every request meets the gateway first: it checks the token, applies the rate limit, then routes.
city 48x32
district front "Front door" 3,3..13,12
district services "Services" 19,3..45,16
building gateway tower in front "API gateway"
floor gw.edge "Edge"
room gw.proxy proxy "Kong" port=8000
room gw.limits cache "Rate limits" port=6379
room gw.auth service "Token check" port=9001 secret=jwt-signing-key
building orders factory in services "Orders"
floor orders.app "Orders"
room orders.api service "Orders API" port=8080
room orders.db database "Orders DB" port=5432
building catalog factory in services "Catalog"
floor catalog.app "Catalog"
room catalog.api service "Catalog API" port=8080
room catalog.index storage "Search index" port=9200
building payments factory in services "Payments"
floor payments.app "Payments"
room payments.api service "Payments API" port=8080
room payments.db database "Payments DB" port=5432
gate main at 0,8 port=443 "api.shop.example"
road main -> gateway
link gw.proxy -> gw.auth "verify token" variant=security
link gw.proxy -> gw.limits "count calls"
link gw.proxy -> orders.api "REST" variant=emphasis
link gw.proxy -> catalog.api "REST"
link gw.proxy -> payments.api "REST"
link orders.api -> orders.db "SQL"
link payments.api -> payments.db "SQL" variant=security