Keep your project structure simple!

  Рет қаралды 14,649

CodeOpinion

CodeOpinion

Күн бұрын

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 KZbin
/ @codeopinion
📝 Blog: codeopinion.com
👋 Twitter: / codeopinion
✨ LinkedIn: / dcomartin
📧 Weekly Updates: mailchi.mp/63c7a0b3ff38/codeo...
Original Video: • How to structure your ...

Пікірлер: 58
@jonowilliams26
@jonowilliams26 Ай бұрын
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
@piotrkowalski3460
@piotrkowalski3460 Ай бұрын
"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.
@Kakaranish
@Kakaranish Ай бұрын
@@piotrkowalski3460 exactly. DDD != using tactical elements of DDD.
@alphaios7763
@alphaios7763 Ай бұрын
Totally agree! I have great dev experience because of this in current company. I feel many companies overcomplicate things which should be simple
@cas818028
@cas818028 2 күн бұрын
This could be a dumb question, but when devs, like yourself our facing this massive 150 endpoints type of problem why not take a step back ask the question “Is it time to switch to GraphQL?”
@capability-snob
@capability-snob Ай бұрын
Distributed "architecture review" is such a fun format
@lorcaranr
@lorcaranr Ай бұрын
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.
@haythambaidda6045
@haythambaidda6045 Ай бұрын
Really great and deep understanding of things, really appreciated.
@gds03_
@gds03_ Ай бұрын
I just love all your videos Derek.. Wish to have in my team persons like you. Already learned a lot from your channel!
@user-ev9jg6ts6e
@user-ev9jg6ts6e Ай бұрын
The only word - Great! Much appreciated!
@MayronDev
@MayronDev Ай бұрын
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.
@CodeOpinion
@CodeOpinion Ай бұрын
Simple solutions to simple problems. Complexity adds up so will the solutions.
@WolfieVenturi
@WolfieVenturi Ай бұрын
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.
@PaulSebastianM
@PaulSebastianM Ай бұрын
Same.
@raymondyoo5461
@raymondyoo5461 Ай бұрын
Thanks a lot for a great video with the essential wisdom 👍
@PbPomper
@PbPomper Ай бұрын
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.
@krccmsitp2884
@krccmsitp2884 Ай бұрын
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.
@st3llarcod3r
@st3llarcod3r Ай бұрын
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.
@adoobi055
@adoobi055 29 күн бұрын
🎯 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
@ruekkart
@ruekkart Ай бұрын
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?
@michaldivismusic
@michaldivismusic Ай бұрын
One suggestion I like is creating features around bounded contexts.
@dsindun7224
@dsindun7224 Ай бұрын
A feature is something that, from the user's point of view.
@marcom.
@marcom. Ай бұрын
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.
@maf_aka
@maf_aka Ай бұрын
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.
@timur2887
@timur2887 29 күн бұрын
you always may use minimal api with a single program.cs file for a simple rest api application
@maf_aka
@maf_aka 29 күн бұрын
@@timur2887 yeah but that doesn't scale. My "simple" plugin is already ~10 kLoC long and it's still WIP.
@nikcimaskevic6415
@nikcimaskevic6415 Ай бұрын
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 .
@CodeOpinion
@CodeOpinion Ай бұрын
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.
@shadowsir
@shadowsir Ай бұрын
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?
@sanhomealex
@sanhomealex Ай бұрын
Implementing DDD using FP... Hmmm, interesting and masochistic way to put the ball into square hole smaller than the ball 😂
@Timelog88
@Timelog88 Ай бұрын
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? 😢
@vlakarados
@vlakarados Ай бұрын
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
@CodeOpinion
@CodeOpinion Ай бұрын
It's a transaction script built around HTTP at the end of the day, call it whatever you want.
@awright18
@awright18 Ай бұрын
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
@CodeOpinion
@CodeOpinion Ай бұрын
What specifically about the recommendations?
@awright18
@awright18 Ай бұрын
​​@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.
@lolyasuo1235
@lolyasuo1235 Ай бұрын
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.
@randalvc
@randalvc 29 күн бұрын
How do you prevent your team from adding db calls directly from endpoints in a single project structure?
@rhtservicestech
@rhtservicestech 25 күн бұрын
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.
@CodeOpinion
@CodeOpinion 24 күн бұрын
Eye of the beholder. Often simple and familiar play an odd role together in perception of simplicity.
@dsindun7224
@dsindun7224 Ай бұрын
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.
@Kyriaeus
@Kyriaeus 24 күн бұрын
It’s probably worth just spending some time mocking up a few approaches and just trying one that sucks less than the others.
@sergeykichuk2586
@sergeykichuk2586 Ай бұрын
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!
@IvanRandomDude
@IvanRandomDude 28 күн бұрын
.NET evolved to be very cool tech stack in recent years. Unfortunately, .NET devs are still stuck in 2000s.
@PaulSebastianM
@PaulSebastianM Ай бұрын
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. 😅
@RaZziaN1
@RaZziaN1 Ай бұрын
Watch video once again, he said he's not using ddd.
@markgrindcore4935
@markgrindcore4935 Ай бұрын
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.
@robster101
@robster101 29 күн бұрын
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.
@dlcardozo
@dlcardozo Ай бұрын
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.
@EldenFiend
@EldenFiend Ай бұрын
If you think DDD makes things harder you haven't been doing it nor applying design patterns to solve domain problems.
@dlcardozo
@dlcardozo Ай бұрын
@@EldenFiend my comment was ironic, but I appreciate yours.
@EldenFiend
@EldenFiend Ай бұрын
@@dlcardozo Ironic or srcastic? Either way, just sounded like it was for real. If not, I apologize.
@brainforest88
@brainforest88 Ай бұрын
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
@leftjabrighthook
@leftjabrighthook Ай бұрын
That's right there with sprocs, SQL Server programmability is alot easier to debug and find problems than your app code. Right?
@CodeOpinion
@CodeOpinion Ай бұрын
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.
@sanhomealex
@sanhomealex Ай бұрын
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.
@timur2887
@timur2887 29 күн бұрын
it's good solutions when you don't have to react on the event inside your buisness layer.. but what if you have to?
@devrub623
@devrub623 Ай бұрын
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
Web-Queue-Worker Architecture Style for Scaling
8:47
CodeOpinion
Рет қаралды 10 М.
5 Rules For DTOs
17:56
Ardalis
Рет қаралды 36 М.
顔面水槽がブサイク過ぎるwwwww
00:58
はじめしゃちょー(hajime)
Рет қаралды 124 МЛН
Ну Лилит))) прода в онк: завидные котики
00:51
WHY DOES SHE HAVE A REWARD? #youtubecreatorawards
00:41
Levsob
Рет қаралды 29 МЛН
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 38 МЛН
This Is The BEST Way To Structure Your GO Projects
11:08
Melkey
Рет қаралды 59 М.
Enums aren't evil. Conditionals everywhere are
11:04
CodeOpinion
Рет қаралды 16 М.
Clean Architecture IS about Vertical Slicing, actually!
15:24
About Clean Code
Рет қаралды 31 М.
Testcontainers have forever changed the way I write tests
12:11
Dreams of Code
Рет қаралды 103 М.
What are Business Rules? It's not this.
10:58
CodeOpinion
Рет қаралды 27 М.
How to (and how not to) design REST APIs
14:28
CodeOpinion
Рет қаралды 46 М.
Swagger is Going Away in .NET 9!
10:48
Nick Chapsas
Рет қаралды 75 М.
The New Extensions EVERYTHING Feature of C# 13!
10:32
Nick Chapsas
Рет қаралды 60 М.
Goodbye long procedural code! Fix it with workflows
9:05
CodeOpinion
Рет қаралды 21 М.
Что еще за Smartisan?
0:49
Не шарю!
Рет қаралды 370 М.
IPad Pro fix screen
1:01
Tamar DB (mt)
Рет қаралды 9 МЛН
ПРОБЛЕМА МЕХАНИЧЕСКИХ КЛАВИАТУР!🤬
0:59
Корнеич
Рет қаралды 3,1 МЛН
Xiaomi Note 13 Pro по безумной цене в России
0:43
Простые Технологии
Рет қаралды 1,9 МЛН
👎Главный МИНУС планшета Apple🍏
0:29
Demin's Lounge
Рет қаралды 449 М.