# Looking for Best Practices for Structuring Slim 4 Apps with Middleware and Route Groups?

**URL:** <https://discourse.slimframework.com/t/looking-for-best-practices-for-structuring-slim-4-apps-with-middleware-and-route-groups/6144>\
**Category:** Questions\
**Created:** [June 16, 2025, 9:01am UTC](https://discourse.slimframework.com/t/looking-for-best-practices-for-structuring-slim-4-apps-with-middleware-and-route-groups/6144 "2025-06-16T09:01:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelosalas](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/marcelosalas/32/1667_2.png) [@marcelosalas](https://discourse.slimframework.com/u/marcelosalas)\
**Post date:** [June 16, 2025, 9:01am UTC](https://discourse.slimframework.com/t/looking-for-best-practices-for-structuring-slim-4-apps-with-middleware-and-route-groups/6144/1 "2025-06-16T09:01:57Z")

</div>

Hi all,

I am currently working on a mid-sized API using Slim 4 and wanted to get some input on how others are organizing their projects — especially regarding middleware and route groups.

Right now, I have global middleware set in AppFactory, and I am grouping routes by resource (e.g., /users, /posts, etc.). However.., as the project grows, I am unsure if I should be breaking things down more granularly — maybe using custom middleware within route groups or splitting controllers further: ??

Are there any recommended practices or community-adopted patterns for keeping things clean and scalable in Slim 4: ?? Also, how are you handling dependencies and container bindings in larger apps: ??

I have checked the docs and examples.., but would really appreciate some real-world insight from those who have built production apps with Slim. I have also gone through this thread [https://discourse.slimframework.com/t/models-middleware-philosophy-architecture-](https://discourse.slimframework.com/t/models-middleware-philosophy-architecture/1020)[sap-fico-course-in-pune](https://www.igmguru.com/erp-training/sap-fico-training-in-pune) but still need more help.

Thanks in advance for any tips, suggestions, or resources !!

With Regards,  
Marcelo Salas

---

<div class="post-metadata">

**Author:** ![discourse\_ai\_spam](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@discourse\_ai\_spam](https://discourse.slimframework.com/u/discourse_ai_spam)\
**Post date:** [June 16, 2025, 9:02am UTC](https://discourse.slimframework.com/t/looking-for-best-practices-for-structuring-slim-4-apps-with-middleware-and-route-groups/6144/2 "2025-06-16T09:02:39Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/1X/c9e53cd374be6aa3306027f61b1a01d3ab78bb56.png) [@system](https://discourse.slimframework.com/u/system)\
**Post date:** [June 18, 2025, 10:17am UTC](https://discourse.slimframework.com/t/looking-for-best-practices-for-structuring-slim-4-apps-with-middleware-and-route-groups/6144/3 "2025-06-18T10:17:58Z")

</div>



---

<div class="post-metadata">

**Author:** ![EugeneM](https://avatars.discourse-cdn.com/v4/letter/e/3be4f8/32.png) [@EugeneM](https://discourse.slimframework.com/u/EugeneM)\
**Post date:** [June 26, 2025, 5:45am UTC](https://discourse.slimframework.com/t/looking-for-best-practices-for-structuring-slim-4-apps-with-middleware-and-route-groups/6144/4 "2025-06-26T05:45:31Z")

</div>

Hi. You may look this [GitHub - slimphp/Slim-Skeleton: Slim Framework 4 Skeleton Application](https://github.com/slimphp/Slim-Skeleton) and this [Samuel Gfeller - Docs](https://samuel-gfeller.ch/docs). All in all specific package structure of specific projects may depends on development context, but in general it adheres to general principles. Regards, Eugene.
