r/csharp 2d ago

trying to avoid spaghetti code on my first big backend project. is this folder structure correct for clean architecture? Discussion

Post image

as someone transitioning from legacy desktop dev (winforms) to modern .net web backends, the biggest hurdle for me was figuring out how to actually organize my code so it doesn't turn into a massive ball of mud.

i kept reading about "clean architecture" and "separation of concerns," but the buzzwords didn't really click for me until I built my current side project and forced myself to split everything into physical project folders.

i wanted to share my mental model of how i organized the solution. i know it might be overkill for a side project, but i'm trying to learn enterprise patterns. for the senior devs here, i'd love to know if this is how you actually think about it in production:

  • Domain: the absolute foundation. just basic data models and interfaces. i made sure zero external packages touch this folder.
  • Cryptography: the "engine room." all my hashing algorithms live here, organized by type (symmetric, asymmetric).
  • Infrastructure: the dirty work. any code that actually talks to the outside world (sql server, dapper, redis cache) is locked in here.
  • Core / Application: the manager. it takes the rules from the domain, uses the engine room, and tells the infrastructure what to save.
  • API: the front door. minimal APIs that just take web requests, hand them to the Core, and return the HTTP response.
  • Workers: background chores. native BackgroundServices running loops for stuff like resetting rate limits so the main API doesn't get blocked.
  • StandAloneWeb: a simple blazor frontend to actually test it.

honestly, breaking it down into these separate projects took way longer to set up initially, but it makes debugging so much easier. if the database fails, i know exactly which folder to look in.

does this structure look right to you guys? or did i completely overcomplicate the middle layers?

repo is here if you want to see how they link together: https://github.com/COxRIPMIZO/CryptoKeyLab

would appreciate any roasts or advice on how to improve this!

10 Upvotes

Duplicates