{"id":13989598,"url":"https://github.com/nathanpeck/socket.io-chat-fargate","last_synced_at":"2025-04-05T03:01:55.128Z","repository":{"id":44470501,"uuid":"119867300","full_name":"nathanpeck/socket.io-chat-fargate","owner":"nathanpeck","description":"A demo application showing how to deploy a scalable realtime chat application powered by Socket.io, Node.js, Docker, and AWS Fargate. Includes full text search powered by OpenSearch Serverless","archived":false,"fork":false,"pushed_at":"2023-06-13T19:45:13.000Z","size":3549,"stargazers_count":431,"open_issues_count":9,"forks_count":238,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-29T02:01:39.615Z","etag":null,"topics":["aws","aws-fargate","nodejs","socketio"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/nathanpeck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-02-01T17:09:54.000Z","updated_at":"2025-02-16T16:07:54.000Z","dependencies_parsed_at":"2024-12-28T15:11:33.804Z","dependency_job_id":null,"html_url":"https://github.com/nathanpeck/socket.io-chat-fargate","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/nathanpeck%2Fsocket.io-chat-fargate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fsocket.io-chat-fargate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fsocket.io-chat-fargate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanpeck%2Fsocket.io-chat-fargate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanpeck","download_url":"https://codeload.github.com/nathanpeck/socket.io-chat-fargate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280190,"owners_count":20912966,"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":["aws","aws-fargate","nodejs","socketio"],"created_at":"2024-08-09T13:01:48.960Z","updated_at":"2025-04-05T03:01:55.091Z","avatar_url":"https://github.com/nathanpeck.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Fargate.chat\n\n[![app](./docs/screenshot.png)](https://fargate.chat)\n\nA Slack-like chat app built with [Node.js](https://nodejs.org/en/) and [Vue.js](https://vuejs.org/) and deployed using Amazon Web Services.\n\nThis application uses Docker containers in [AWS Fargate](https://aws.amazon.com/fargate/), and [AWS App Runner](https://aws.amazon.com/apprunner/), as well as [AWS Lambda](https://aws.amazon.com/lambda/) functions.\n\nA sample version of the app is hosted at: https://fargate.chat\n\n### Architecture features\n\n- No EC2 instances. One of the goals of this application architecture is that it is very hands off, nothing to manage or update. Serverless features are turned on wherever possible.\n- Fully defined as infrastructure as code, using [AWS CloudFormation](https://aws.amazon.com/cloudformation/) to create all the application resources.\n- Included `docker-compose.yml` which stands up a local copy of DynamoDB, and local copy of the socket.io chat server. This allows you to develop locally and see the application at `http://localhost:3000`. The only feature that does not run locally, and is just simulated is the full text chat search.\n- Integration test suite container that you can run against a copy of the application, either locally or remotely.\n\nRead more about [the architecture and services in use](/docs).\n\n### Application features\n\n- User account functionality, including anonymous accounts\n- Real time chat message sending over WebSocket protocol, with persistance in DynamoDB\n- Live user presence, including announcments when users join or leave\n- Unread message indicator\n- Typing indicator, including support for multiple typers at once.\n- Full text search for chat messages, powered by Amazon OpenSearch Serverless\n- Infinite virtual DOM scrolling, for performant feeling even when many thousands of messages have been sent in a room.\n\n### Things to note in this app\n\n- Working configuration for routing WebSocket connections with Socket.io through CloudFront\n- Example of how to setup OpenSearch access policies for a Lambda function\n- Horizontally scalable Socket.io using the Redis adaptor and Amazon ElastiCache\n\n### Setup instructions\n\nInstall if not already installed:\n\n* Docker: https://docs.docker.com/get-docker/\n* AWS SAM CLI: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html\n* Install Node and NPM if not present\n\n```\n# Setup some env variables for later\n# Can try other regions as long as all required services are in that region\nexport AWS_REGION=us-east-2\nexport AWS_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)\n\n# Install the dependencies off of NPM\n(cd services/message-indexer; npm install)\n(cd services/message-search; npm install)\n\n# Setup the base VPC and networking stuff.\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/cluster.yml \\\n  --stack-name chat-cluster \\\n  --capabilities CAPABILITY_IAM\n\n# The shared resources like DynamoDB table and OpenSearch Serverless\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/resources.yml \\\n  --stack-name chat-resources \\\n  --capabilities CAPABILITY_IAM\n\n# Create an ECR repository to host the container image\naws ecr create-repository \\\n  --region $AWS_REGION \\\n  --repository-name fargate-chat\n\n# Login to the ECR repository\naws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com\n\n# Build the Docker image\ndocker build -t fargate-chat ./services/socket\n\n# Upload the built container image to the repository\ndocker tag fargate-chat:latest $AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/fargate-chat:latest\ndocker push $AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/fargate-chat:latest\n\n# Start up the container that runs in AWS Fargate\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/chat-service.yml \\\n  --stack-name chat-service \\\n  --capabilities CAPABILITY_IAM \\\n  --parameter-overrides ImageUrl=$AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/fargate-chat:latest\n\n# Deploy the component which indexes sent chat messages\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/message-indexer.yml \\\n  --stack-name chat-message-indexer \\\n  --resolve-s3 \\\n  --capabilities CAPABILITY_IAM\n\n# Deploy the component which provides search autocomplete and API Gateway\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/message-search.yml \\\n  --stack-name chat-message-search \\\n  --resolve-s3 \\\n  --capabilities CAPABILITY_IAM\n\n# Build the component which hosts static web content\naws ecr create-repository \\\n  --region $AWS_REGION \\\n  --repository-name apprunner-web\n\n# Build the Docker image\ndocker build -t apprunner-web ./services/web\n\n# Upload the built container image to the repository\ndocker tag apprunner-web:latest $AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/apprunner-web:latest\ndocker push $AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/apprunner-web:latest\n\n# Launch the web container inside of App Runner\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/web.yml \\\n  --stack-name chat-web \\\n  --resolve-s3 \\\n  --parameter-overrides ImageUrl=$AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/apprunner-web:latest \\\n  --capabilities CAPABILITY_IAM\n\n# Deploy CloudFront distribution which ties main app and search endpoint together on one domain\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/cloudfront.yml \\\n  --stack-name chat-cloudfront \\\n  --resolve-s3 \\\n  --capabilities CAPABILITY_IAM\n\n# Get the application URL to view it\naws cloudformation describe-stacks \\\n  --stack-name chat-cloudfront \\\n  --query \"Stacks[0].Outputs[?OutputKey==\\`PublicURL\\`].OutputValue\" \\\n  --output text\n\n# Open the URL in the browser window\n\n```\n\n## Project layout\n\n```\n/deps - Folder used only for local development purposes\n/infrastructure - CloudFormation templates used for deployment to AWS\n/services - Independent code components that make up the app\n  /socket - The core Node.js socket.io app, which runs in AWS Fargate\n  /message-indexer - Lambda function which triggers on DynamoDB updates, to index chat messages\n  /message-search - Lamdba function triggered by API Gateway, answers search queries\n  /test-suite - Container used for local tests, runs integ tests against socket service\n  /message-index-drop - Admin Lambda function which drops the OpenSearch Serverless collection\n  /web - Frontend service which serves the static web files in production\n```\n\n## Admin and dev actions\n\nIf you want to drop the search index (will be recreated next time you send a message, though older messages will no longer be remembered)\n\n```\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/message-index-drop.yml \\\n  --stack-name chat-index-drop \\\n  --resolve-s3 \\\n  --capabilities CAPABILITY_IAM\n```\n\nRun a local copy of the socket app for testing:\n\n```\nmake run    # Standup local DynamoDB and local stack\nmake test   # Rebuild and run tests locally\n\n# Open localhost:3000 in browser to view app\n```\n\nLaunch the public facing CloudFormation stack with a custom domain name and SSL cert:\n\n```\nsam deploy \\\n  --region $AWS_REGION \\\n  --template-file infrastructure/cloudfront.yml \\\n  --stack-name chat-cloudfront \\\n  --resolve-s3 \\\n  --capabilities CAPABILITY_IAM \\\n  --parameter-overrides DomainName=fargate.chat CertArn=arn:aws:acm:us-east-1:228578805541:certificate/45b4037a-2257-48ff-b3ae-b8e3e0523e85\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanpeck%2Fsocket.io-chat-fargate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanpeck%2Fsocket.io-chat-fargate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanpeck%2Fsocket.io-chat-fargate/lists"}