{"id":17551071,"url":"https://github.com/ttu/chat-server","last_synced_at":"2025-04-12T04:03:47.275Z","repository":{"id":139968138,"uuid":"152716307","full_name":"ttu/chat-server","owner":"ttu","description":"Small implementation of a server for a chat application for testing Docker","archived":false,"fork":false,"pushed_at":"2018-11-25T14:47:31.000Z","size":395,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T23:34:55.457Z","etag":null,"topics":["asp-net-core","csharp","docker","docker-compose","rabbitmq","react","redis"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ttu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-12T08:10:58.000Z","updated_at":"2024-04-14T08:05:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe3bb103-bca5-4536-a572-331052cd2910","html_url":"https://github.com/ttu/chat-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Fchat-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Fchat-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Fchat-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttu%2Fchat-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttu","download_url":"https://codeload.github.com/ttu/chat-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514228,"owners_count":21116903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","csharp","docker","docker-compose","rabbitmq","react","redis"],"created_at":"2024-10-21T04:44:47.448Z","updated_at":"2025-04-12T04:03:47.268Z","avatar_url":"https://github.com/ttu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chat Server\n\n\u003e Note: This project is for my own testing and a reference for Docker scripts\n\nServer for a chat application.\n\n## Diagram\n\n![diagram](./docs/chat-server.png)\n\n* ChatServer\n  * _.NET Core Web API_\n* ChatBroker\n  * _.NET Core Web API_\n  * Handles new messages from RabbitMQ\n* Client\n  * _React application_\n  * Send and receive messages\n* RabbitMQ\n  * Queue for new messages \n* Redis\n  * Client register\n  * Has information on which server user is logged on\n* __TODO__ Postgres\n  * Messages that are not delivered to offline users  \n* __TODO__ Authentication\n* __TODO__ User Service\n  * _Node.js Express_ \n  * Search users\n  * Uses status\n  * Share message history between clients\n\n## Getting Started\n\n### Run with Docker Compose\n\n```sh\n# Developemnt\n$ docker-compose build\n$ docker-compose up\n\n# Production\n$ docker-compose -f docker-compose-prod.yml build\n$ docker-compose -f docker-compose-prod.yml up\n```\n\n### Run development environment\n\nInstall required containers:\n\n```sh\n# Create network\n$ docker network create --attachable chat\n\n# Redis\n$ docker run -d --name chat-redis --network=chat -p 6379:6379 redis\n\n# RabbitMQ\n$ docker run -d --name chat-rabbit --network=chat -p 5672:5672 -p 15672:15672 rabbitmq:3-management\n\n# Quick start/stop\n$ docker start chat-redis \u0026\u0026 docker start chat-rabbit\n$ docker stop chat-redis \u0026\u0026 docker stop chat-rabbit\n```\n\nStart project from _Visual Studio_.\n\n### Run projects with Docker\n\nStart debuggable projects in _containers_.\n\n```sh\n# Build image\n$ docker build -t chatserver:dev .\n\n# Start container\n$ docker run --rm -it -e \"Connections__Redis=chat-redis\" -e \"Connections__RabbitMQ=chat-rabbit\" -e \"DOTNET_RUNNING_IN_CONTAINER=true\" -p 5000:5000 -p 10222:22 --name chat-server --network=chat -v C:\\src\\GitHub\\chat-server\\src\\ChatServer:/app/ -w /app chatserver:dev\n\n# Login to container\n$ docker exec -it chat-server /bin/bash\n\n# Start SSH server (TODO: should be always on)\n$ service ssh start\n\n# Debug -\u003e Attach to process -\u003e SSH (localhost:10222 root:Docker!) \n# Attach to dotnet exec process\n# Select Managed Managed (.NET Core for Unix)\n```\n\n\nIf you don't care about debugging from container, just start clean image with `dotnet watch`\n```sh\n$ docker run --rm -it -e \"Connections__Redis=chat-redis\" -e \"Connections__RabbitMQ=chat-rabbit\" -e \"DOTNET_RUNNING_IN_CONTAINER=true\" -p 5000:5000 --name chat-server --network=chat -v C:\\src\\GitHub\\chat-server\\src\\ChatServer:/app/ -w /app microsoft/dotnet:2.1-sdk dotnet watch run\n$ docker run --rm -it -e \"Connections__Redis=chat-redis\" -e \"Connections__RabbitMQ=chat-rabbit\" -e \"DOTNET_RUNNING_IN_CONTAINER=true\" -p 5000:5000 --name chat-server --network=chat -v C:\\src\\GitHub\\chat-server\\src\\ChatBroker:/app/ -w /app microsoft/dotnet:2.1-sdk dotnet watch run\n```\n\n##### Debug chat-app React application with VS Code\n\n`sourceMapPathOverrides` in `launch.json`must override folder structure in Docker container.\n\n```json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"type\": \"chrome\",\n      \"request\": \"attach\",\n      \"name\": \"Attach to Chrome\",\n      \"port\": 9222,\n      \"webRoot\": \"${workspaceFolder}/src\",\n      \"sourceMapPathOverrides\": {\n        \"/app/src/*\": \"${webRoot}/*\"\n      }\n    }\n  ]\n}\n```\n\n### Production\n\n```sh\n# Build image\n$ docker build -f Dockerfile-prod -t chatapp:prod .\n\n# Start prod React app\n$ docker run -it -p 800:80 --rm --name chat-app-prod chatapp:prod\n```\n\n## TODO\n\n* Docker doesn't set ASPNETCORE_ENVIRONMENT correctly on development compose\n* Authorization\n* Save messages temporarily to DB\n* When user logs in send not sent messages to him immediately\n* Handle same user with multiple clients on multiple servers\n\n## Notes\n \n#### Redis Commander\n\nhttps://www.npmjs.com/package/redis-commander\n\n```sh\n$ npm install -g redis-commander\n$ redis-commander\n```\n\nOpen: http://localhost:8081/\n\n##### ChatServer\n\n...\n\n##### ChatBroker / RabbitMQ\n\n...\n\n##### ClientRegister / Redis\n\n...\n\n##### Authentication\n\n...\n\n\n### Flow\n\n```\n# Client logs in\n\nChatServer: Login\n Authenticate\n Send update to client register\n Check if there is waiting messages for the client in the sent_queue\n\n# Client sends a new message\n\nChatServer: New message /api/send\n Validate\n Send update to client register\n Send message to RabbitMQ\n\nChatBroker: New message from RabbitMQ\n Get receiver server from client register\n Save message to sent_queue\n Send to correct server /api/receive\n  Success\n   Remove message from sent_queue\n  Fail\n   Update message status to sent_queue_\n\nChatServer: New message /api/receive\n Send to receiver with WebSocket\n Send status to broker (success/fail)\n```\n\n### Links\n\n#### Routing\n\n* Routes: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.1#id7\n* Route constraints: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.1#route-constraint-reference\n\n#### Performance\n\n* https://medium.com/@tampajohn/net-core-2-and-golang-797566350095\n\n#### RabbitMQ life cycle\n\n* https://www.rabbitmq.com/dotnet-api-guide.html#connection-and-channel-lifspan\n\n#### Integration tests\n\n* https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.1#customize-webapplicationfactory\n\n### Docker networking\n\n* https://runnable.com/docker/docker-compose-networking\n* https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/multi-container-microservice-net-applications/multi-container-applications-docker-compose\n\n### Docker\n\n* https://mherman.org/blog/dockerizing-a-react-app/#production\n* https://github.com/dotnet/dotnet-docker/blob/master/samples/dotnetapp/dotnet-docker-dev-in-container.md#requirements\n\n### VS Debug\n\n* https://blog.quickbird.uk/debug-netcore-containers-remotely-9a103060b2ff\n* https://stackoverflow.com/questions/48661857/how-to-debug-a-net-core-app-runnig-in-linux-docker-container-from-visual-studio","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttu%2Fchat-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttu%2Fchat-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttu%2Fchat-server/lists"}