okay, rule number 1: adjectives agree with the nouns they modify in case, number, and gender.
What this means:
You correctly recognized that there are different endings for different cases. To make things complicated, however, there is more than one set of endings. (These are what we mean when we talk about '1st declension, 2nd declension, etc)
So - some nouns will follow the pattern of -a in the nominative, -ae in the genitive, while others will have a patter of -us, -i or -um, -i. This is fairly arbitrary. There's no inherent reason in the meaning of the word why it should end in -a rather than -us.
1st declension nouns are (almost always) feminine in gender. 2nd declension nouns are masculine or neuter. Again, the gender is arbitrary, but the declension patterns are associated with certain grammatical genders.
Adjectives, however, have no inherent gender. They borrow the grammatical gender -- and hence their endings -- from the gender of the noun they are used with.
'Porta' is a feminine noun. Therefore, when you use the adjective magnus/a/um with it, it uses the form 'magna'. 'Amicus' is masculine, so the adjective form is 'magnus'.
IPHIGENIE: Kann uns zum Vaterland die Fremde werden?
ARKAS: Und dir ist fremd das Vaterland geworden.
IPHIGENIE: Das ist's, warum mein blutend Herz nicht heilt.
(Goethe, Iphigenie auf Tauris)