def check(self, dsm, **kwargs):
        """
        Check layered architecture.

        Args:
            dsm (:class:`DesignStructureMatrix`): the DSM to check.

        Returns:
            bool, str: True if layered architecture else False, messages
        """
        layered_architecture = True
        messages = []
        categories = dsm.categories
        dsm_size = dsm.size[0]

        if not categories:
            categories = ['appmodule'] * dsm_size

        for i in range(0, dsm_size - 1):
            for j in range(i + 1, dsm_size):
                if (categories[i] != 'broker' and
                        categories[j] != 'broker' and
                        dsm.entities[i].split('.')[0] != dsm.entities[j].split('.')[0]):  # noqa
                    if dsm.data[i][j] > 0:
                        layered_architecture = False
                        messages.append(
                            'Dependency from %s to %s breaks the '
                            'layered architecture.' % (
                                dsm.entities[i], dsm.entities[j]))

        return layered_architecture, '\n'.join(messages)