ticket:3 database and middleware implementation