What is the basis of grammaticality?

Accepted usage. Grammar of any language is based on how a native speaker uses a particular language to communicate. From sounds to mechanics all elements must be acceptable.