Poker Trainer / Logic and Optimization

Hello, I am about to create a poker game, in theory I know how to create the game in a very basic way, the problem I find is that I continue using my method to create it, the game would have a very large amount of code since each time I want to add a new hand I am creating new code for the community cards, the user’s hand and the actions of the user and the villain.

I have some doubts or questions.

  1. Is there a way to create a system that recognizes the hand ranking of the players (Pair, 2 pair, set, straight, flush etc.)?

  2. It is possible to use a database to save all the game code (in case I have no other alternative).

  3. Is there a way to add a previously developed javascript poker game, something like open source?

Thanks in advance.