This has been well discussed before, for example in this book: https://ifanyonebuildsit.com/