6 ms·
Ask HN: Best codebases to study to learn software design?
I’m working on improving my software design skills, and it was recommended that I study existing well designed codebases. What are some publicly accessible codebases you would consider gold standards for software design?
- iphone_elegance 1y agohttps://aosabook.org/en/ https://aosabook.org/en/
- sprobertson 1y agoIt's been asked a few times, here are some links to get you started: * https://news.ycombinator.com/item?id=36370684 https://news.ycombinator.com/item?id=36370684 * https://news.ycombinator.com/item?id=30752540 https://news.ycombinator.com/item?id=30752540 * https://news.ycombinator.com/item?id=9896369 https://news.ycombinator.com/item?id=9896369 (Python specific)
- pixelworm 1y agoThank you!
- riffraff 1y agoI am not qualified enough to answer, but some ~15 years ago I enjoyed going through the book Code Reading[0], which is about this exact topic. I think there was another one with a similar name but I can't think of it's name. 0: https://www.spinellis.gr/codereading/ https://www.spinellis.gr/codereading/, check the TOC https://www.spinellis.gr/codereading/toc.html https://www.spinellis.gr/codereading/toc.html
- rgovostes 1y agoThese are several years old at this point, but many open source project leaders contributed to the series "The Architecture of Open Source Applications", which is free to read online: https://aosabook.org/en/index.html https://aosabook.org/en/index.html
- pixelworm 1y agoThank you!
- userbinator 1y agoUNIXv6 and the BSDs.
- belZaah 1y agoMy experience (30 years in software, 25 in practicing architecture, MIT system architecture masters) tells me there is no such thing as abstractly “good” design. There are designs with negative consequences for sure, but “good” depends on the context: what are you building, safety/security requirements etc. Probably most importantly on the implementation team and it’s structure. A team of juniors will butcher your intricate design and Conway’s Law makes your software reflect the team.
- pixelworm 1y agoYeah, as I've been learning more about software design, it's become pretty clear there is no silver bullet. It would be nice though. I find it a bit overwhelming to try to find the best solution for a problem when there are so many different architectures and programming paradigms. That being said, taking into account the requirements does eliminate quite a few of the options. Right now, I work on safety-critical embedded systems which requires us to make some decisions that would most likely be way different in other environments.
- peterfirefly 1y agoIt's about having most compromises be Not Totally Stupid and have the worst ones only be locally stupid. There is a big universe out there of compromises that fulfill those criteria. As you imply, a lot of the time it's more about constantly fighting for Less-Bad-and-avoiding-Dumb than about architecture as such.
- pfannkuchen 1y agoMaybe I’m just not good enough at paying attention, but for me it seems like you have to actually run into problems over and over and figure out how to avoid the problems. Then you end up being able to mentally simulate what problems you will run into, and design is basically all about avoiding future problems of various kinds (and balancing tradeoffs about which future problems to avoid and how much effort to put into each, whether you can solve multiple with one design play, etc).
- teekert 1y agoI have this too, I have never been able to "do exercises" or "study a codebase". I need to be making something that I am excited about, then I'll learn, from examples, from wanting to be thorough and correct. But sometimes I think I'm just not their yet, if I become able to read code like a book and really understand what happens, which often I don't, then perhaps I'll enjoy the process more.
- estimator7292 1y agoThat's how I learn as well. I've found that reading code is a completely different thing from learning. Not even tangentially related. I can read a codebase and run simulations in my head. But this almost never results in learning anything. I can study code and see how a particular task is done, but I don't learn it until I put it into practice. Just about the only thing I get from reading other people's code is the most egregious ways to not do something. This is a pretty common thing, a plurality of humans learn this way. We just have different standards for software, for some reason. We like to pretend books teach you something more "real" than just getting your hands dirty and writing some real fucked up code. But the reality is that figuring out why your disaster code doesn't work, and then fixing it is one of the most educational experiences a programmer can have.
- pixelworm 1y agoThis is pretty much how I've learned up to this point (and will of course continue). Trying to learn from real world code will be a new experience for me. Not sure how valuable it will be but should be fun either way.
- crystal_revenge 1y agoMy immediate reaction to this question is: "your team's". Nothing will teach you more about how to design software then really understanding why good and bad solutions were adapted to solve a certain real problem. Software exists precisely because there is still a messy layer connecting user requirements to actions on a computer. If there was not messiness then we could just automate it all. Approaching software from some sort of Platonic ideal of what software should be will frequently lead to bad decisions on it's own. When you start to see how certain pressures lead to certain paths you learn to recognize the wrong decisions that are often good at the time, and avoid them. At the same time, you need to learn to develop methods that work quickly and effectively. By far the biggest real challenge in real world software is time constraints. This is almost never discussed in theoretical views of software, but the truth is you're always going to be writing code under pressure to ship. You will come across situations where you do not have time to do what you want to do or think is best. Good software is software that runs and solves the user need, but you will come to realize that there are design solutions that will make successfully running happen more often. The best way to find these is to study the real software you're writing.
- teiferer 1y agoWhat if the question is born out of the insight that his team's software is poorly designed, motivating the desire to get outside input? What if the question is asked by a college student?
- lukan 1y agoThen it still matters a lot what kind of codebase he is working on. A web project is differently structured and done than the codebase for a embedded operating system. There are differend standards and practices in the industry. I learned a lot by just stepping through the code with the debugger of libaries I used. That brought more practical insight while learning about design patterns etc. In the end, it is all about patterns. Finding the right pattern for a given problem.
- pixelworm 1y agoI would be interested in recommendations for those who have a poor example or no examples In my case, I'm a junior engineer that has recently been given more responsibility designing aspects of our product. I'm just trying to learn all I can so my designs will be good!
- shahzaibmushtaq 1y agoMy suggestion is to search for open-source codebases in your favorite languages, study them, and start practicing them.
- pixelworm 1y agoI'm definitely going to do that. I asked because I wanted to start off with some that I'd knew would be well designed. However, it would probably be more interesting to see a wide variety of quality than just the good ones. Or maybe open source projects are all usually well designed. I haven't looked at many in depth. The only one I've really looked into was Clang to try to figure out why clang format ignored my style rules when styling files of certain names. (Turns out there is a list of file names that automatically are considered Objective-C rather than C++)
- shahzaibmushtaq 1y agoYou understood what I was trying to convey. Yes, all open-source projects are well designed with documentation and to-dos, otherwise open-source contribution becomes difficult.
- zvr 1y agoOne of the best is actually the implementation of the Tcl language. It's highly readable C code, very well structured (it was initially by Ousterhout, after all).
- musicale 1y agoI also found the Tcl implementation to be easy to read and understand.
- BlackFly 1y agoI can recommend reading about postfix architecture if you want to learn a bit about what would nowadays be called a microservice architecture: https://www.postfix.org/OVERVIEW.html https://www.postfix.org/OVERVIEW.html You might need to know a bit about how email servers work to appreciate it though.
- pixelworm 1y agoWell maybe I'll take some time to learn about email servers then. I use email everyday so I suppose it'll be good to know a little more about how it works.
- ben30 1y agoWhile studying well-designed codebases is incredibly valuable, there's an important "tip of the iceberg" effect to consider: much of good software design lives in the "negative space" - what's deliberately not there. The decisions to exclude complexity, avoid premature abstractions, or reject certain patterns are often just as valuable as the code you can see. But when you're studying a codebase, you're essentially seeing the final edit without the editor's notes - all the architectural reasoning that shaped those choices is invisible. This is why I've started maintaining Architectural Decision Records (ADRs) in my projects. These document the "why" behind significant technical choices, including the alternatives we considered and rejected. They're like technical blog posts explaining the complex decisions that led to the clean, simple code you see. ADRs serve as pointers not just for future human maintainers, but also for AI tools when you're using them to help with coding. They provide readable context about architectural constraints and compromises - "we've agreed not to do X because of Y, so please adhere to Z instead." This makes AI assistance much more effective at respecting your design decisions rather than suggesting patterns you've deliberately avoided. When studying codebases for design patterns, I'd recommend looking for projects that also maintain ADRs, design docs, or similar decision artifacts. The combination of clean code plus the architectural reasoning behind it - especially the restraint decisions - provides a much richer learning experience. Some projects with good documentation of their design decisions include Rust's RFCs, Python's PEPs, or any project following the ADR pattern. Often the reasoning about what not to build is more instructive than the implementation itself.
- pixelworm 1y agoOooh I like that idea. I may steal it. I'll be on the lookout for documents like that. It'll be interesting to see what patterns/designs were avoided. There are so many ways to accomplish the same thing it might be nice to set some limits.
- vogelke 1y agoI'd recommend the book "Beautiful Code: Leading Programmers Explain How They Think". Published by O'Reilly, ISBN-10 : 0596510047
- pixelworm 1y agoI'll check it out, thanks!
- ChrisArchitect 1y agohttps://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=Ask%20hn%3A%20codebases&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
- pixelworm 1y agoWhoa, I didn't know something like this existed. Thank you so much! This will make it way easier to check if something has already been asked.
- tmoravec 1y agoThere's a free book on this topic: The Architecture of Open Source Applications https://aosabook.org/en/index.html https://aosabook.org/en/index.html Maybe that would be a good start. You can then pick a project to dive in. As a more specific tip, I've done some hacks in Nginx long time ago and found it quite nice.
- rc_kas 1y agoFor website/web server learning I recommend the laravel code-base. It's a beauty. https://www.instagram.com/reel/C2x4Ge5RtNC/ https://www.instagram.com/reel/C2x4Ge5RtNC/
- pydry 1y agoI dont think this is a good idea, actually. Good design is about making good trade offs at the right point in time. A code base with excellent design will show you the end state but not how it got there but probably not the trade offs and decisions involved. Practicing refactoring on subpar code bases and dealing with the consequences of your decisions is a better way to improve.
- pixelworm 1y agoAre there any books or websites you'd recommend I read to learn more about design instead? I 100% need to learn by doing, but wouldn't it also be good to learn what has already been discovered so I don't have to reinvent the wheel? Or is it best to discover good design on your own?
- pydry 1y agoI learned on my own. If I were to recommend anything to read it would be to find a good book on refactoring or dealing with legacy code. I read design patterns books when i was younger but in retrospect that was a hindrance more than a help.
- SonOfLilit 1y agoTo answer your actual question: The codebases I learned from the most are Git, Postgres, CPython. Not saying they are perfect designs, but they are well maintained, solve hard problems, have seen many years of evolution, and are very easy to get your hands on.
- chickenzzzzu 1y agoYour own. Everyone else's is trash. Never understand someone else's code-- the whole point is that there should be just a handful of functions of yours I can call, and shouldn't ever care to see how the sausage is made. Otherwise, your abstraction sucks
- pixelworm 1y agoI agree that the internals of my code should be abstracted away from my users. But don't I still want the internals to be well designed so they are maintainable and extendable?
- chickenzzzzu 1y agoThe design will reveal itself to you the more you wrestle with the data and logic of the problem you are trying to solve. Full stop-- nobody on Earth would be more qualified than you at that point to say, unless they've already solved your problem
- koliber 1y agoTrying to learn software design by looking at code is kind of like trying to learn about architecture looking at the bricks that make up a building. To learn about design you need a wider perspective. You can theoretically learn it from code but it won’t be most effective. Look at great documentation and literature about design instead.
- pixelworm 1y agoYeah, I guess without the context I wouldn't really understand why it was designed that way. Or know what situations a design like that would be good for. Is there any documentation or literature that has helped you?
- koliber 1y agoOnce upon a time there was an email MTA (email server) called qmail. It had an architecture that was surprising and Daniel Bernstein documented his philosophy. It left an impact on me by showing me how we can rely on the OS-supplied facilities to accomplish a lot. I don't think qmail is some shining star that will teach you everything you need to know about software design. It is an interesting case study to add to your repertoire. See https://en.wikipedia.org/wiki/Qmail https://en.wikipedia.org/wiki/Qmail
- RossBencina 1y agoI think there is value in groking entire code bases. It's not just about whether or not they are well designed though. It is an important skill to be able to analyze and see the big picture of how things work together in large systems. For me it often involves drawing diagrams (sometimes UML) to map things out. Being able to view systems in this way is a pre-requisite to intentionally designing your own systems at this level. And yes, once you can work at this level you can learn from good designs, but also see problems with bad ones. EDIT: and to answer your question, if you're working on something that is "like X but different" then read the source code for X. You could also look at source code for software that you use from day to day: software where you already know what it does. For example, if you're in web, maybe the web framework, or web server, if you write python, maybe a core library that you use, or maybe the python interpreter, or if you use vscode ..., if you use android ..., you get the idea. At the start I would suggest smaller programs, and programs where you already know the domain (e.g. cpython might not be the best place to start if you never implemented an interpreter before, you may spend more time learning about interpreters than the design of this one, still a good thing to learn of course.)
- artpar 1y agoI made a small list long while ago, but it still holds today https://medium.com/@012parth/what-source-code-is-worth-studying-8755f88f8de5 https://medium.com/@012parth/what-source-code-is-worth-study...
- pixelworm 1y agoThanks! I appreciate it!
- revskill 1y agoThere's no. Most of production codebase outthere is result of hacks.
- sim7c00 1y agostudy modern code bases of language you want to learn, and look first at their history to see if they are mature, came from a company, academics etc. you should not only study 'good' code... how will you know what is bad code? study code that does similar things to what u want (client/server/game/ai/datacrunching etc.) and study lot of it..different qualities, ages, and sources
- CraigJPerry 1y agoI've done this for years and swear by it. Top 5 codebases for changing my mind about things: Wietse Venema's Postfix mail server. Taught me tons about security posture, the architecture i'd describe as microservices before microservices was a thing, but contrary to the modern take on microservices (it's mostly a tool for decomposing work across large semi-isolated groups) this was primarily about security and simplicity. Spring framework - this opened my eyes to ways of working that i hadn't really thought enough about before, the developers on that project have a culture of deeply considering the needs of their users (who are java developers often in an enterprise environment). Git - the thing i like about the git code base is that once you've covered the objects database (e.g. blobs, trees and commits) and the implementation of refs, everything else just feels like additional incremental features. With those core concepts, everything else is kinda harmoniously built on top. Varnish by Poul Henning-Kamp is another one - feels like he went to great lengths to make that code base a teaching tool despite the fact it's also a top tier reverse proxy. Last one isn't a code base - but it will help with software design in the large; studying how the lieutenants model works in the linux kernel. Thinking about my answers, i think i've highlighted something subtly different than "well designed codebases" it's more a list of codebases that left a notable long lasting impression on me because of design decisions they made.
- drysine 1y ago>well designed codebases One thing to keep in mind is that what was well-designed 30, 20 or 10 years ago may not be considered such now. Hardware changes and so do the design decisions involving performance. For example, if you are looking at C++ networking libraries, learning from ACE or even Asio may not be the best idea - better look at "thread per core, share nothing" Seastar[0]. Another thing is that it may be better to read design docs, not the code. For example, the rationale for the mold linker design[1]. [0] https://docs.seastar.io/master/tutorial.html#asynchronous-programming https://docs.seastar.io/master/tutorial.html#asynchronous-pr... [1] https://github.com/rui314/mold/blob/main/docs/design.md https://github.com/rui314/mold/blob/main/docs/design.md
- goodthink 1y agohttps://github.com/newspeaklanguage https://github.com/newspeaklanguage https://newspeaklanguage.org https://newspeaklanguage.org https://blog.bracha.org https://blog.bracha.org
- mamcx 1y agoThis has 2 key things: * "well designed": What was the objectives and ideas... * "codebases": How well that was implemented They are a lot of lofty claims saying how this or that is "fast, secure, etc" but don't end like that in the actual implementation. But most of the time, that could be seen in the "design claims" already! Good design is not just full of adjectives and nice sounding goals, but the concrete considerations, what was the trade-offs, false-starts, and reasons behind the decisions. You can see some examples reading about the design of Erlang, early pascal, most RDBMS, etc. So, you first mid/long term goal is to learn to distinguish what good design actual look like. then, in relation with codebases then to be kinda easier: It actually follow the design? A good example is the 'std' library of Rust. It has a lot of lofty claims about security and such things that could sound alarms, but then you dive in the code of it and see is there A LOT of care about it, and a lot of docs comments discussing this stuff and then the code match. P.D: The "std" or equivalent of the lang is one of the most important codebases you need to learn and study, and the MAJOR way to judge how truly good is it.
- NoahZuniga 1y agocodemirror 6 is the product of a bunch of redesigns, and this most recent version seems to have had a lot of thought put into its structure.
- ramesh31 1y agoDoom 3: https://github.com/id-Software/DOOM-3 https://github.com/id-Software/DOOM-3
- simon_acca 1y agoredis
- alphazard 1y agoThe codebase is not where the design usually lives. It's where the implementation lives. You could imagine a rewrite into another programming language which would preserve the design but completely replace the implementation. You should practice writing design docs. Don't worry about what the doc is supposed to look like, and definitely don't work off of a template. The most important thing about the doc is that another human could do the implementation if you gave it to them. The doc can also function as a "proof of consideration". If you choose to do something one way, but there are other possible ways to do it, you can acknowledge the other possible ways, and say why they are worse. By preemptively acknowledging an alternative, you have proved to readers that you considered it. All a "good" system designer is doing is considering a larger design space than most, and consistently finding good points in the space. Pick a problem, sample points in the design space, tell me why some points are better than others, and write it all down.
- djmips 1y agoBitsquid didn't prevail but personally I thought the software design was spot on. If you're into this kind of project. (Game engine) https://bitsquid.blogspot.com/2009/09/welcome-to-bitsquid-blog.html https://bitsquid.blogspot.com/2009/09/welcome-to-bitsquid-bl...
- austin-cheney 1y ago> that I study existing well designed codebases. Proceed with extreme caution. This is highly subjective and often results in a blind leading the blind scenario. For example how do you determine which code bases are well designed if you yourself are not comfortable determining such? Instead, heed the guidance of some of the other comments and just start building things. Plan on failing and solving for the failure. That’s called practice. With enough practice you will know what works well for you. If you are measuring things along the way you will also know what’s slow.
- rekoros 1y agoOne way is to become an apprentice with an experienced plumber - ideally skilled in hydronic heating.
- BobbyTables2 1y agoGo the other way. Study and fix shitty code. Find college students who wrote a web server and put it on GitHub for the world to see. Find all the bugs and then see how many integer overflow vulnerabilities can be exploited to crash it … or worse.
- commandersaki 1y agoAs far as cryptography libraries are concerned, Monocypher.
- vismit2000 1y agopytudes: https://github.com/norvig/pytudes https://github.com/norvig/pytudes
- tariqshams 1y agoHighly recommend you read this book series (all free online) The Architecture of Open Source Applications https://aosabook.org/en/ https://aosabook.org/en/ Then afterwards diving into a repo based on the map given to you by the textbook.
- brainzap 1y agoI should do this more too, specially the complete auth/multi tenant solutions. Go code is easiest to read.
- mindwok 1y agoThe MIT course for Operating Systems has a teaching OS called xv6. There's some nifty implementations in there. I'm not sure I'd comment on the codebase itself, but I think more importantly it teaches you good abstractions which Unix is all about: https://pdos.csail.mit.edu/6.1810/2024/xv6.html https://pdos.csail.mit.edu/6.1810/2024/xv6.html
- DriftRegion 1y agoStart with the question: what is the problem that you want to solve? Next, find codebases that solve that problem and study how they do it. Good design is so deeply tied to the domain details. Wonham's Internal Model Principle applies to code. Example: I wanted to solve the problem of unit testing for embedded targets. I found open source projects that do this and read the code critically to see how and why it is written. As I build my own approach, I revisit theirs to learn more as my understanding of the domain deepens.
- soursopfarm 1y ago[dead]
- atleastoptimal 1y agoYanderedev source code
- VirusNewbie 1y agoOnes I like: Spark, Cassandra, Beam.
- deafpolygon 1y agoFirst do, then look.