the sentence does not violate the phrase structure second rule (introduced by noam chomsky) because noun phrases consist of a determiner such as a, the or every, and a noun. in the sentence, the noun phrase the cake includes a determiner (the) and a noun (cake).
on the other hand, the first rule indicates that a sentence encloses a noun phrase, followed by a verb phrase. the example sentence can be analysed as follows:
john (n) + ate (v) + the (det) + cake (n).