Keep your project structure simple!

2024 ж. 4 Мам.
12 880 Рет қаралды

What should your project structure look like? How should you structure and organize your HTTP APIs? Here's one way by Jono Williams and my thoughts and insights about some misconceptions about Domain Driven Design.
🔗 EventStoreDB
eventsto.re/codeopinion
🔔 Subscribe: / @codeopinion
💥 Join this channel to get access to a private Discord Server and any source code in my videos.
🔥 Join via Patreon
/ codeopinion
✔️ Join via KZhead
/ @codeopinion
📝 Blog: codeopinion.com
👋 Twitter: / codeopinion
✨ LinkedIn: / dcomartin
📧 Weekly Updates: mailchi.mp/63c7a0b3ff38/codeo...
Original Video: • How to structure your ...

Пікірлер
  • Distributed "architecture review" is such a fun format

    @capability-snob@capability-snob10 күн бұрын
  • Hey great video! Really enjoyed hearing your thoughts on things mentioned in my video. I definitely agree people try to force DDD because it's what they have been told. I did want to clarify the "I've done DDD and it was too complicated and didnt work". I didnt include this in my video but the project where we used DDD was a large project with well over 150 endpoints and was more of an RPC API since each endpoint was pretty much an individual business rule. The domain for the project was handling the government regulations around greenhouse gas emissions calculating and reporting to the Australian government, so definitely not just simple CRUD. Once we ripped out DDD and went to using a more procedural approach with the endpoints and just letting data be data, the code was much simpler

    @jonowilliams26@jonowilliams2610 күн бұрын
    • "ripped out DDD" or ripped out DDD tactical design patterns? That's a huge difference and it was one of the most important points of this video.

      @piotrkowalski3460@piotrkowalski34609 күн бұрын
    • @@piotrkowalski3460 exactly. DDD != using tactical elements of DDD.

      @Kakaranish@Kakaranish9 күн бұрын
    • Totally agree! I have great dev experience because of this in current company. I feel many companies overcomplicate things which should be simple

      @alphaios7763@alphaios77638 күн бұрын
  • I love this, start simple and add complexity. If you start with a complex solution and it fails, it's really hard to figure out what went wrong or where it fell short.

    @lorcaranr@lorcaranr10 күн бұрын
  • Really great and deep understanding of things, really appreciated.

    @haythambaidda6045@haythambaidda604510 күн бұрын
  • I just love all your videos Derek.. Wish to have in my team persons like you. Already learned a lot from your channel!

    @gds03_@gds03_10 күн бұрын
  • Thanks a lot for a great video with the essential wisdom 👍

    @raymondyoo5461@raymondyoo546110 күн бұрын
  • The only word - Great! Much appreciated!

    @user-ev9jg6ts6e@user-ev9jg6ts6e10 күн бұрын
  • My thoughts on this topic: As always, there's simply no "one size fits all". Each and every software has its own requirements, architecture, and therefore its own project structure. You can have blueprints or templates as starting point, for sure, but don't let them dictate everything. Adhere to common principles like simplicity, consistency, readability, maintainability-they should be more valuable than any prescriptive structure.

    @krccmsitp2884@krccmsitp28849 күн бұрын
  • I watched the video from the other guy when he released it and I couldn't finish it (I disagreed too much). Those types of videos work well for beginners but ultimately sends them down a path of confusion. Senior devs understand that the architecture evolves with the project and "it depends" is usually the right answer to what type of architecture they should use or recommend.

    @MayronDev@MayronDev10 күн бұрын
    • Simple solutions to simple problems. Complexity adds up so will the solutions.

      @CodeOpinion@CodeOpinion10 күн бұрын
    • How can you disagree with a particular approach in a vacuum, yet recognize in a following sentence that these decisions depend on the problem context? I would say the opposite is true, smaller code bases, with minimal abstractions are in general easier to navigate and make sense of.

      @WolfieVenturi@WolfieVenturi10 күн бұрын
    • Same.

      @PaulSebastianM@PaulSebastianM10 күн бұрын
  • It all starts with the question of what is defined as complexity. Is it the complexity of familiarizing yourself as a new, inexperienced developer with established structures and frameworks and understanding their principles and abstractions? Ok, that's not easy. But it makes me faster, more consistent and more productive later on. And then it's even easier to always follow the same consistent approach, even for simple parts of the company software, which also works for the more complex problems.

    @marcom.@marcom.10 күн бұрын
  • Great video! But one thing that I didn't quite understand was the handling of DTOs. In the video he just adds them as Request and Response classes to the specific endpoint. But what if your domain models are way bigger and your endpoints duplicate those (like your create and update endpoint)? Wouldn't it make more sense to have a general PostDto, CommentDto, etc? He probably didn't do this because his features were simple still.

    @st3llarcod3r@st3llarcod3r10 күн бұрын
  • Simple is always best. One problem though is that one person's definition of simple is not always the same as another person's definition of simple. Thus why there are so many different architecture styles and ways to organize the code.

    @rhtservicestech@rhtservicestechКүн бұрын
  • 🎯 Key Takeaways for quick navigation: 00:00 *🏗️ Structuring HTTP API Projects* - Different folder structures for organizing HTTP API projects. - Common approaches include organizing by technical concerns, clean architecture, domain-driven design (DDD) with vertical slice architecture. - Templates often lack indicators of actual DDD implementation. 01:24 *🗂️ Adopting a Simpler Approach* - Emphasizing simplicity in project structure over strict adherence to domain-driven design (DDD) patterns. - Advocating for vertical slice architecture for grouping features. - Introducing an endpoints file for a clear overview of API surface. 02:21 *📁 Folder Structure Overview* - Overview of the proposed folder structure: endpoints, common, feature, data. - Explanation of the purpose of each folder in the structure. - Focus on simplicity and ease of navigation. 03:32 *🔄 Endpoint Structure and Contracts* - Explanation of endpoint structure: mapping, request and response contracts, logic. - Importance of defining clear request and response contracts for each endpoint. - Simplifying endpoint handling using static methods in minimal APIs. 07:15 *🧩 Handling Complexity Over Time* - Discussion on managing complexity as projects evolve. - Example of handling denormalized data and maintaining consistency. - Evolution from simple transaction scripts to more complex patterns like repository pattern and event-driven architecture. 09:23 *🛠️ Balancing Simplicity and Complexity* - Balancing simplicity with the need for more complex patterns as projects scale. - Highlighting the importance of understanding coupling and applying solutions judiciously. - Emphasizing the iterative nature of architectural decisions based on evolving project requirements. Made with HARPA AI

    @adoobi055@adoobi0555 күн бұрын
  • I wonder if there's an ever simpler, better way? I've created a few plugins (well, only 2) for my code editor and the pattern and project structure that I applied there makes me wonder if I should apply them in my professional backend projects too. The idea revolves around user discoverability: 1. The outer layer of the project exposes the external surface of the program, i.e. the APIs and the main executable. 'Clutters' like git and docker files are unavoidable, but it's okay for me (after a while your eyes will be trained to ignore those things). 2. Going 1 layer deeper (a service directory) is about serving each of the exposed APIs, 1 directory per exposed API. If the entire program is simple (like most of my stuff turned out to be), opt for collapsing the directories into 1, separating concerns into files with meaningful names in the same directory. Shared functions will be put in one 'common' level 1 directory. 3. The layer 2 directory concerns itself with dependencies (same as "infrastructures" in the Clean architecture, but decentralized). IMO it's more meaningful for project watchers and maintainers to see this last; the pub-sub, cache, and database files are in the same directory per level 1 directory. Shared functions in this level across different level 1 directories should be in itself an imported dependency. Creating the 'utils' directory for all shared dependency functions in the level 1 'common' directory is acceptable too. 4. No level 3+ directories. Nested directories and small files are the enemy of code comprehension (I see you, Java devs). Naming conventions and other language idiomatics can only help so much.

    @maf_aka@maf_aka10 күн бұрын
    • you always may use minimal api with a single program.cs file for a simple rest api application

      @timur2887@timur28875 күн бұрын
    • @@timur2887 yeah but that doesn't scale. My "simple" plugin is already ~10 kLoC long and it's still WIP.

      @maf_aka@maf_aka5 күн бұрын
  • I generally like this idea, but the problem I have is that all of these videos always use very simple projects. Try this with an application that has millions of lines of code.

    @PbPomper@PbPomper9 күн бұрын
  • Talking about VSA, what can we say is a feature? Is it a specific method that users have available (for example, to like a post)? Is it a DDD domain or subdomain? Is it an aggregate? I know "it depends," but still, what could be an initial approach or heuristic to create those features?

    @ruekkart@ruekkart10 күн бұрын
    • One suggestion I like is creating features around bounded contexts.

      @michaldivismusic@michaldivismusic10 күн бұрын
    • A feature is something that, from the user's point of view.

      @dsindun7224@dsindun72246 күн бұрын
  • How do you prevent your team from adding db calls directly from endpoints in a single project structure?

    @randalvc@randalvc5 күн бұрын
  • I am not fan of this approach. I think it is more a trend just came with minimal APIs. There are 2 reasons i don't like this: 1) You mix different areas (models, validations, mapping, endpoints etc) in one class 2) Having a separate class per endpoint "GetByA,B,C,D..." can easily make your project spaghetti and complex for no reason.

    @lolyasuo1235@lolyasuo12357 күн бұрын
  • Just a few seconds in, I saw the video in question a few days ago and he had me for a few minutes then lost me when he made recommendations

    @awright18@awright1810 күн бұрын
    • What specifically about the recommendations?

      @CodeOpinion@CodeOpinion10 күн бұрын
    • ​​@CodeOpinion I rewatched your video and the original. The thing the turned me off was his suggested folder structure which it seems he didn't fully use in the sample. When I saw "common", "services" , and "data" it immediately made me think there are shared/coupled things here, this could lead to problems in the future. In the Endpoint example he went out of the way to make specific request/response classed but failed to do that in those other scenarios. That frankly was slightly disappointing. I know it feels like EF have has a gravitational pull and it's hard to have more than one context and it kind of forces people down that path and why I try to avoid using it, and common things tend to evolve into specific things that end up breaking things that depend on them. Otherwise, I did like the simple design, and as always appreciated your perspective and insights.

      @awright18@awright1810 күн бұрын
  • But this is basically REPR design pattern by ardalis? (I'm not in C# so may miss the difference, but the Endpoint idea is pretty much there?) Afterwards you incrementally add layers as required

    @vlakarados@vlakarados9 күн бұрын
    • It's a transaction script built around HTTP at the end of the day, call it whatever you want.

      @CodeOpinion@CodeOpinion9 күн бұрын
  • User type and puts a tape of both are in the same folder that's not ddD, obviously, The two do not belong the same bounder context. No bundled that the in the structure.

    @dsindun7224@dsindun72246 күн бұрын
  • I recently started looking into functional programming, where we only have immutable data and functions. According to object-oriented programming (OOP), this is essentially an anemic model. Given that the anemic model is considered an anti-pattern, does this mean that functional programming is an anti-pattern for implementing Domain-Driven Design (DDD)? Or is it considered an anti-pattern only within the context of OOP? Sorry if this question might sound stupid, but with all this terminology and anti patterns it becomes confusing .

    @nikcimaskevic6415@nikcimaskevic641510 күн бұрын
    • As mentioned, I don't think its an anti-pattern at all. I think what makes it an antipattern in on context of OOP is when you *think* you have a rich domain model encapsulating behavior and in reality is you don't.

      @CodeOpinion@CodeOpinion10 күн бұрын
    • It's not a stupid question. In FP, any function that would mutate the aggregate would return the new state of the aggregate. The original aggregate would remain untouched. I hope that makes sense to you?

      @shadowsir@shadowsir10 күн бұрын
    • Implementing DDD using FP... Hmmm, interesting and masochistic way to put the ball into square hole smaller than the ball 😂

      @sanhomealex@sanhomealex9 күн бұрын
  • That clean architecture (CA) sample he showed... Was not clean architecture. One of the key components of CA is screaming architecture, which means... Grouping by features. Only when you do that you can then use the rest of CA. How does everyone miss that chapter in the book? 😢

    @Timelog88@Timelog8810 күн бұрын
  • 5 years of "experience" here.... I don't think i understand what they both are talking about. Although i watched a lot of architecture videos(Ardalis, CodeOpinion). I have practiced all this on my own, but still can't get really into it :(. I really admire Derek videos, as i see him as great professional. But the videos i watch, almost every time leaves more questions than answers. As the videos are short with already existing logic, and even pauses don't really help. I wish i could get into what Derek says quickly. There is Tim Corey, who explains things really slow and in understandable manner. But he covers only beginner stuff without diving into architecture subject.

    @markgrindcore4935@markgrindcore493510 күн бұрын
  • Everything works fine when it is pretty clear and simple with few line of code. But when it gets super complex people got stuck and that’s approach not working in real life scenarios!

    @sergeykichuk2586@sergeykichuk258610 күн бұрын
  • That guy doesn't understand DDD. I got that sense immediately as he mentioned it as he explains it and shows an example that is not DDD. 😅

    @PaulSebastianM@PaulSebastianM10 күн бұрын
    • Watch video once again, he said he's not using ddd.

      @RaZziaN1@RaZziaN19 күн бұрын
  • It’s probably worth just spending some time mocking up a few approaches and just trying one that sucks less than the others.

    @Kyriaeus@Kyriaeus10 сағат бұрын
  • .NET evolved to be very cool tech stack in recent years. Unfortunately, .NET devs are still stuck in 2000s.

    @IvanRandomDude@IvanRandomDude3 күн бұрын
  • Don't agree. That Like() method on the Post doesn't scale in terms of development. The Post class enforces consistency, but also introduces strong coupling. With increasing number of requirements, the post class will become a bottleneck. Imagine we want to react to posts, report a post, share a post, upvote/downvote a post etc. You'll keep adding those methods and counts to that Post class? Probably, you'll have a different stakeholder for each of those features, so now every time there is a change or a bug in one of those requirements, you'll need to touch the class which might affect other features as well. The transaction script approach will stay simple. New feature for a post is just a new transaction script, a change or a bug in that feature affects only that code.

    @robster101@robster1015 күн бұрын
  • Do not kill all those dreams, let them make DDD just creating some folders. Why someone will want to make things complicated adding things like ubiquitous language, a domain expert and all that stuff... let the data be transformed as is it to DTOs.

    @dlcardozo@dlcardozo10 күн бұрын
    • If you think DDD makes things harder you haven't been doing it nor applying design patterns to solve domain problems.

      @EldenFiend@EldenFiend8 күн бұрын
    • @@EldenFiend my comment was ironic, but I appreciate yours.

      @dlcardozo@dlcardozo7 күн бұрын
    • @@dlcardozo Ironic or srcastic? Either way, just sounded like it was for real. If not, I apologize.

      @EldenFiend@EldenFiend6 күн бұрын
  • Use a DB Trigger on the Likes table which increments on insert and decrements on delete. Done. Don't know why you want to put this into your application code

    @kaizen8808@kaizen880810 күн бұрын
    • That's right there with sprocs, SQL Server programmability is alot easier to debug and find problems than your app code. Right?

      @leftjabrighthook@leftjabrighthook10 күн бұрын
    • Absolutely a solution (trigger). I was making up an example to illustrate consistency concerns, don't take it all to literally on solution to a made up problem.

      @CodeOpinion@CodeOpinion10 күн бұрын
    • All weird stuff begins with such a small pieces of logic spread through different system's layers. This a sooo cool journey to find where the problem is, starting with the presentation layer and going down the road to the db trigger.

      @sanhomealex@sanhomealex9 күн бұрын
    • it's good solutions when you don't have to react on the event inside your buisness layer.. but what if you have to?

      @timur2887@timur28875 күн бұрын
  • Dude what you’re talking about ??? You are one of the problems here. Always overengineering everything !!!! I just want to f build a simple api dude Hahaha

    @devrub623@devrub6236 күн бұрын
KZhead