Create middleware layer and define structure