Where i should put my DTOs in clean architecture?

This looks like a single application. So in that case, I place my DTOs as close to where they are used as possible. If it's MVC, then my DTOs are right next to my views:

  • Views
    • Account
    • Index.cshtml
    • IndexModel.cs

Or if it's Razor Pages, then the DTOs are simply inner classes. See my ContosoUniversity examples for a working example:

MVC example

Razor Pages example

It's not "clean architecture" but "vertical slice architecture" but that shouldn't matter. Put the classes close to where they're actually used.


As we already know, Dtos can be of different types that does not have any behaviour and are only used for transporting data eg a Model in the MVC pattern or a class that probably is named with a suffix 'classNameDto'

In your case, it really depends on what context you are using the Application layer. Some Devs understand that 'Application Services' are more specific to the application, meaning they are tied closely to the UI.

If this is the case then, this is a good place to have the Dtos where the data is mapped to and from the domain model.

Else if the mapping is done at the Web layer then Dtos need to go there.

In simple terms as @Jimmy Bogard said "Put the classes close to where they're actually used."

I would also suggest to readup more on the clean architecture and see if you are headed in the right direction.

Hope this helps :)