How does the divisibility graphs work? I came across this graphic method for checking divisibility by $7$. 
$\hskip1.5in$ 

Write down a number $n$.
    Start at the small white node at the bottom
  of the graph. For each digit $d$ in $n$, follow $d$ black arrows in a
  succession, and as you move from one digit to the next, follow $1$
  white arrow.   
For example, if $n = 325$, follow $3$ black arrows, then
  $1$ white arrow, then $2$ black arrows, then $1$ white arrow, and
  finally $5$ black arrows.
If you end up back at the white node, $n$ is divisible by $7$.

This method indeed works, I was wondering why this work and how could we generate such graph for an  arbitrary integer $k$?

Yes, you can find such graphs for divisibility by any number in any base.
This is a finite-state machine representation of the number, similar to what you would get if you performed long division but ignored the quotient so far. (This particular one may have simplifications that obscure that connection.)
