well to generate the templates for policies/middlewares you can use yarn strapi generate or npm run strapi generate
It’s an interactive CLI to build out cookie-cutter templated code.
As for the documentation:
Policies: Policies - Backend customization - Strapi Developer Docs
Middlewares: Backend customization - Middlewares - Strapi Developer Docs
Routes (which has info on policies/middlewares also): Routes - Strapi Developer Docs