A terror attack plot on a school in Stuttgart has been foiled by German police who found knives, explosives and bullets in a 15-year-old boy's home.

He is also reported to have had contact online with Ali Sonboly, the teenager who shot dead nine people in Munich on Friday.

The plan to carry out a deadly assault comes as Germany remains in a state of high alert following a series of deadly attacks in the last fortnight.

The boy was arrested after the arsenal of weapons were found in the Ludwigsburg district of Stuttgart.

The boy was arrested in Stuttgart (pictured). Police believe he was plotting a massacre, possibly using explosives, in the city, possibly on a school

The teenager in Stuttgart is believed to have been in contact online with Ali Sonboly (pictured), who perpetrated a shocking massacre in Munich last week

The German magazine Der Spiegel said a search of the boy's flat, where he lived with his parents, found 'extensive evidence, including small-calibre cartridges, several knives and daggers, escape plans for several schools and a large amount of chemicals, materials and instructions for making explosives'.

The boy is understood to have been taken into custody in a secure psychiatric unit for young people.

There is no suggestion at this point that he had any contact with ISIS or other Islamist groups.

According to media reports the boy was betrayed to the authorities by someone he boasted to of his plans.

Police quickly established a link to Sonboly through his Internet footprints and the youngster's home was raised late on Tuesday night.

Police said during the course of his interrogation he confessed 'to preparing an outrage against the background of personal and academic problems.'

The boy in Ludwigsburg apparently looked up to Sonboly as a figure to admire and emulate.

Germans have been left in a state of shock after several violent incidents in recent weeks.

On 19 July a 17-year-old Afghan refugee attacked several Hong Kong tourists on a train in southern Germany with an axe before being shot dead by police.

Four days later Sonboly killed several children and teenagers in a McDonald's restaurant and in a nearby shopping centre with a gun which he had managed to buy on the 'dark web'.

Sonboly had been bullied for years and was obsessed with spree killers like Anders Breivik.

Then on Sunday a failed asylum seeker from Syria, Mohammad Daleel, 27, blew himself in the town of Ansbach after being refused entry to a sold-out concert in a 2,500 capacity venue.

The blast injured 15 people - four seriously, and killed Daleel, who had links to ISIS.