This. And I recently found out you can also use includes
in compose v2.20+, so if your stack complexity demands it, you can have a small top-level docker-compose.yml with includes to smaller compose files, per service or any other criteria you want.
https://docs.docker.com/compose/multiple-compose-files/include/
This looks about right, I have a similar setup for unauthenticated services here, with the difference that I'm using NGINX Proxy Manager instead of Caddy. The things I would try/check are:
code.test.example.com
entry to point directly to Authentik's IP and port (in other words, both entries would look the same). In the config your posted, it seems like Caddy is redirecting through itself.