Foundations of topological electrodynamics