Help Needed with Routing and Middleware in Slim 4

Hi everyone,

I’m currently learning Slim Framework (using version 4), and I’m really enjoying how lightweight and flexible it is. However, I’ve run into a bit of confusion when it comes to properly setting up routing and middleware.

I’ve been able to create basic routes that return simple responses, but I’m not sure how to organize things when the app grows. For example, what’s the best way to group routes or apply middleware only to certain routes without affecting the whole application?

I came across this website:https://discourse.slimframework.com/t/about-addroutingmiddleware-generative-AI-course\routing-middleware-slim-4/3957 but still need help.

Also, I’m curious about how Slim handles route-specific middleware compared to global middleware. I’ve read the docs, but I’d really appreciate an example or explanation from someone who’s already used Slim in a real-world project.

If there are best practices for keeping things clean and maintainable as the project grows, I’d love to hear them.

Thank you in advance for your assistance! This is a fantastic community and I am looking forward to hearing more from you all.

Best,
mathew