I would like to make nice games with good architecture that are easy to support and extend. But when i write code it all gets messy and hardcoded, so when I want to add a feature it becomes a huge pain. Is there any book that teaches me how to design my game upfront, so I will know what classes I will want, how to do certain features etc.
I would recommend Game Coding Complete.
It has a large focus on the design of each part of the game, and how they work together. Most books that deal with programming games try to dumb everything down into small demos that break or become messy when you try to extend them. Instead, this book spends the time to break each part up into extendable pieces of a framework.
It's authors have experience working on large projects with many people, and the book reflects that.
I know exactly what you mean when you say " it all gets messy and hardcoded, so when I want to add a feature it becomes a huge pain." Reading this book really helped me solve this problem.
I believe that the book recently released it's fourth edition. Here is the amazon link http://www.amazon.com/Game-Coding-Complete-Fourth-Edition/dp/1133776574/ref=dp_ob_title_bk.
To see what I mean you can use Amazon's preview to read the first part of Chapter 2 "What's in a Game?" This chapter describe the architecture that the rest of the book implements.
It seems like what you're looking for is a more informed outlook on software architecture and software design in general, which are more along the lines of software engineering topics than game development topics. My suggestion is to dig through the architectures of several other existing games, and see how they are structured; in addition, pick up a copy of Head-First Design Patterns, and that might help. The above comment about Dave Eberly's Game Engine Design book is also spot-on.