Implement social-media chat app by using nestjs, typescript, turborepo as monorepo and clean-architecture concept, etc. Please have fun and enjoy it. =)
- create user - [POST]
{{BASE_URL}}/api/v1/users
- get me - [GET]
{{BASE_URL}}/api/v1/users/me
- get user - [GET]
{{BASE_URL}}/api/v1/users/:id
- create channel - [POST]
{{BASE_URL}}/api/v1/channels
- get channel - [GET]
{{BASE_URL}}/api/v1/channels/:id
- create member(join channel) - [POST]
{{BASE_URL}}/api/v1/members
- create chat - [POST]
{{BASE_URL}}/api/v1/chats
- get chat - [GET]
{{BASE_URL}}/api/v1/chats/:id
- list chat - [GET]
{{BASE_URL}}/api/v1/chats
- remove chat - [DELETE]
{{BASE_URL}}/api/v1/chats/remove-multiple
- retract chat - [PUT]
{{BASE_URL}}/api/v1/chats/retract-multiple
- search chat - [GET]
{{BASE_URL}}/api/v1/chats-search
- clientid is clientid_${channel_id}
- email is your user email
ws://localhost:3030/?clientid=clientid_${channel_id}&email=${email}
- after connecting the websocket connection with specifeid channel and end-user
- use create chat api, then you can see the response from websocket server
- it will delete related resource suchas subscriptions from redis, etc.
- createdAt is creation of specified chat that client receive from gateway server
- this process will callback to socialmedia api server to updat on acked at field
{
"event": "onAck",
"data": {
"channelId": 1,
"createdAt": "2024-12-19T06:54:04.273Z"
}
}
- Consuming dynamodb data from creating chat api, and bulk insert into elasticsearch for full-text feature
#cd root path
#install package
pnpm i
#build package
pnpm build
#root folder use docker-compsoe
docker-compose up -d
#check related adapters is running
#Mysql, Redis, Elasticsearch, Logstash, Kibana, Localstack(for DynamoDB, S3)
docker ps
#cd apps/socialmedia-api path
#init knex project
knex init -x ts
#Migration
#create file
knex migrate:make ${name} -x ts #name: is your file name
#up
knex migrate:up
#down
knex migrate:down
#Seed
#create file
knex seed:make ${name} #name: is your file name
- use localstack as dynamodb
- use awslocal command
#create table and enable dynamodb stream
#table name is chats
awslocal dynamodb create-table \
--table-name chats \
--key-schema AttributeName=channel_id,KeyType=HASH AttributeName=created_at,KeyType=RANGE \
--attribute-definitions AttributeName=channel_id,AttributeType=N AttributeName=created_at,AttributeType=S \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE \
--region ap-east-1
#describe table
awslocal dynamodb describe-table --table-name chats --region ap-east-1
{
#...
"LatestStreamArn": "arn:aws:dynamodb:ap-east-1:000000000000:table/chats/stream/2024-12-23T05:46:08.897",
#pleas set this stream arn to ./apps/serverless/serverless.yaml file
#...
}
#delete table
awslocal dynamodb delete-table --table-name chats --region ap-east-1
#list tables
awslocal dynamodb list-tables --region ap-east-1
#DynamoDB stream
#list
awslocal dynamodbstreams list-streams
#describe
awslocal dynamodbstreams describe-stream --stream-arn arn:aws:dynamodb:ap-east-1:000000000000:table/chats/stream/2024-12-23T05:46:08.897
- use localstack as s3
- use awslocal command
#create bucket
awslocal s3api create-bucket --bucket ${bucket_name} --create-bucket-configuration LocationConstraint=ap-east-1
{
"Location": "http://${bucket_name}.s3.localhost.localstack.cloud:4566/"
}
#delete
awslocal s3 rb s3://${bucket_name} --force
#list
awslocal s3api list-buckets
//create template
PUT /_index_template/chats-index-template
{
"index_patterns" :["chats"],
"priority" : 1,
"template": {
"settings" : {
"number_of_shards" : 1
},
"mappings": {
"properties": {
"channel_id": {
"type": "integer",
"index": true
},
"created_at": {
"type": "date",
"index": true
},
"updated_at": {
"type": "date"
},
"sender_id": {
"type": "integer"
},
"text": {
"type": "text"
},
"is_retract": {
"type": "boolean"
},
"ignored_user_ids": {
"type": "integer"
}
}
}
}
}
#cd root path and start servers
#socialmedia-api(listen at 3000 port)
#chat-ws-gateway(listen at 3030)
pnpm dev
#cd ./apps/serverless path
#use serverless-offline
sls offline
- serverless-offline-dynamodb-streams
- dynamodb streams
- google-protobuf
- javascript_dynamodb_code_examples
- Expressions.UpdateExpressions
- gRPC style guide
- gRPC style guide
- serverless-offline
- Media feature is unready.
- use s3 as media bucket
- use presigned url
- Swagger document is unready.
- The authorization of gRPC protocol is unimplemented.
- The heart beat of websocket is unimplemented.
- Delete specified channel api.
- Leave specified channel api.
- Publish chat failover solution.
- Implement dispatcher server between socialmedia-api and chat-ws-gateway server.
- Separate redis server to each microservice.
- Add unit test.
- Modify logger.
- Probably ...