The concept of a "church" in the Writings is both complex and beautifully organic, linked with teachings on the nature of the Lord and the resulting nature of mankind.
The Writings say that the Lord, in His essence - His actual substance - is perfect, infinite love, a love that powered creation, that is the ultimate source of reality, and that sustains reality constantly. That love is expressed in form as perfect, infinite wisdom, which gave form to creation and gives form to reality.
Deep stuff! You can read more about that elsewhere, but what matters here is that all of creation, from the smallest elements to the whole of the universe, reflects that same structure. It's present in nature itself, powered by the heat (love) and light (wisdom) of the sun. It's present in the essential forms of life, with plants (which are rooted; which change little; which are unfeeling; which are powered by light) representing elements of wisdom and animals (warm, feeling, mobile, ever-changing, powered by heat) representing forms of love. It's present in the near-universal division into male (wisdom) and female (love) aspects of plants and animals alike.
That structure is also in each of us. In common language we might call these our hearts and our minds - what we want and what we think. The Writings commonly talk of them as good (love; what we want in our hearts) and truth (wisdom; what we know in our minds) or as will (heart) and understanding (mind). Not only do these elements define us, they are also key to our spiritual fates. We can use them to accept the Lord's love, come into the good of life and ultimately go to heaven. We can also use them to reject the Lord's love and trot off to hell.
And there are further layers. The Writings say that all human societies are in human form, with functions analogous to the human body. This is true from small groups like families to large companies to entire nations and ultimately to both the entire human race in this world and the entirety of heaven in the next.
Among the most important human societies are, naturally, churches. Since the concept of a "church" is based on the human form, though, churches as referred to in the Writings can take many forms. At one end of the scale, any one person who has true ideas of right and wrong and lives by them is a church himself or herself. At the other end of the scale, all those in the whole world who believe in love of the neighbor – and act from that belief – collectively make up one church.
Many other varieties lie between those two extremes, but most references to "church" in the Writings mean the community of those who have the Word, know the Lord, and follow His commandments. These people have access to the best possible truth and deepest possible understanding about the nature of the Lord and what He wants from us.
Such a church plays a vital role: The Lord works through it to get ideas about being good into people's minds and the desire to be good into the inner recesses of their hearts, reaching far beyond that church itself to touch everyone in the world. In fact, the Writings say there is in essence a marriage between the Lord and the church, with the church in the role of the bride and wife, producing true ideas and good desires the way a wife produces children.
To protect this function, the Lord has made sure that throughout history (and a good bit of prehistory) there has always been a church filling this role.
The first of these was the Most Ancient Church, represented by Adam; it was inspired by love of the Lord. The second was the Ancient Church, represented by Noah; it was inspired by love of the neighbor and knowledge of the Lord. The third was the Israelitish Church, which had no interior love of good but preserved ideas of the Lord. The fourth was the primitive Christian church, which had a new, more direct understanding based on the Lord's teachings. The fifth, according to the Writings, is to be based on the deeper understanding offered through the Writings and their explanations of the Bible.
There is much more that could be said, but we'll just emphasize one other point:
We as individuals are who we are based on what we love, not what we know. We will go to heaven or to hell based on what we love, not what we know. Knowing, thinking and seeking truth are important things, but their purpose is to shape, guide and serve our loves; love is ultimately what matters. The Writings make it abundantly and repeatedly clear that it is the same with churches: They are ultimately based on love, not knowledge, on their determination to serve the neighbor, not their external forms of worship. And if churches share that common purpose of serving the neighbor then they are in essence one, with doctrinal variations being of little consequence.
(References: Apocalypse Revealed 533; Arcana Coelestia 407, 768, 1799 [3-4], 2048, 2853 [2-3], 2910, 2982, 3310, 3773, 3963 , 4292, 4672, 4723, 5826 [2-3], 6637, 6648, 8152, 9256 [4-5], 9276 ; Conjugial Love 116; Heaven and Hell 57; Teachings about the Sacred Scripture 99, 104; The Word 8)