refactoryng the chat architecture