code and diagram