  We present a method to find anomaly-free gauged Froggatt-Nielsen type models
using results from algebraic geometry. These methods should be of general
interest for model building beyond the Standard Model (SM) when rational
charges are required. We consider models with a gauged $U(1)$ flavor symmetry
with one flavon and two Higgs doublets and three right-handed SM singlets to
provide three model examples based on different physical assumptions. The
models we study are: anomaly-free with no SM neutral heavy chiral fermions,
anomaly-free with SM neutral heavy chiral fermions, and supersymmetric with SM
neutral heavy chiral fermions where the anomalies cancel via the Green-Schwarz
mechanism. With these different models we show how algebraic methods may be
used in model building; both to reduce the charge constraints by calculation of
Gr\"obner bases, and to find rational solutions to cubic equations using
Mordell-Weil generators.
  Using these tools we find three phenomenologically viable models explaining
the observed flavor structure.
