  In this article we investigate in detail the possibility of accounting for
the $b\to s\ell^+\ell^-$ and $(g-2)_\mu$ anomalies via loop contributions
involving with new scalars and fermions. For this purpose, we first write down
the most general Lagrangian which can generate the desired effects and then
calculate the generic expressions for all relevant $b\to s$ Wilson
coefficients. Here we extend previous analysis by allowing that the new
particles can also couple to right-handed Standard Model (SM) fermions as
preferred by recent $b\to s\ell^+\ell^-$ data and the anomalous magnetic moment
of the muon. In the second part of this article we illustrate this generic
approach for a UV complete model in which we supplement the Standard Model by a
$4^{\rm th}$ generation of vector-like fermions and a real scalar field. This
model allows one to coherently address the observed anomalies in $b\to
s\ell^+\ell^-$ transitions and in $a_\mu$ without violating the bounds from
other observables (in particular $B_s -\bar B_s$ mixing) or LHC searches. In
fact, we find that our global fit to this model, after the recent experimental
updates, is very good and prefers couplings to right-handed SM fermions,
showing the importance of our generic setup and calculation performed in the
first part of the article.
