Moderated communities already exist and are implementedin Amethyst
https://github.com/nostr-protocol/nips/blob/master/72.md
Unmoderated communities would be relatively easy as just putting a tag to identify a community and filtering by it.
(it's called hashtags)