Skip to content

About

Twitter-style social backend in Nest.js microservices: API gateway + Kafka event service, MySQL, Redis, Elasticsearch, DynamoDB, S3, Terraform CI/CD

Topics

Resources

Code of conduct

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

121 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Yo - Twitter-style Backend in Nest.js Microservices

Nest.js TypeScript Kafka MySQL Redis Elasticsearch DynamoDB AWS Terraform GitHub Actions

Yo is a production-style backend for a Twitter-like social app. It's built as a Nest.js monorepo with an API gateway and an event service that talk over Kafka, and it covers the things real social platforms need: auth, follows, posts, replies, reposts, likes, search, notifications and media uploads.


✨ Highlights

  • Microservices monorepo: api-gateway (REST + Swagger) and event-service (Kafka consumer), with shared libs/ for config, Kafka, email, types and utils
  • Event-driven design: domain events (for example, user created) are published to Kafka so async work stays decoupled from the request path
  • Data layer: MySQL with TypeORM, versioned migrations, seeders, plus backup and restore scripts
  • Performance: Redis caching and DataLoader batching to avoid N+1 queries
  • Search: Elasticsearch-powered search module
  • Notifications: stored in DynamoDB (see DYNAMODB_IMPLEMENTATION.md)
  • Media uploads: S3 presigned URLs, so clients upload avatars directly to S3
  • Security: session-based auth guards, bcrypt password hashing, request validation with class-validator
  • Observability: Datadog tracing via dd-trace
  • Quality: Jest unit tests across controllers, services and guards, plus e2e tests and Compodoc docs
  • CI/CD: GitHub Actions pipeline that provisions staging with Terraform and ships Docker images to AWS ECR

πŸ—οΈ Architecture

flowchart LR
    Client([Client]) --> GW[API Gateway<br/>Nest.js REST + Swagger]
    GW --> MySQL[(MySQL<br/>TypeORM)]
    GW --> Redis[(Redis cache)]
    GW --> ES[(Elasticsearch)]
    GW --> S3[(S3 presigned uploads)]
    GW -- domain events --> Kafka{{Kafka}}
    Kafka --> EV[Event Service<br/>Nest.js consumer]
    EV --> DDB[(DynamoDB<br/>notifications)]
Loading

Avatar upload flow (S3 presigned URL)

  1. The backend generates a presigned S3 URL and object key
  2. The client uploads the image straight to S3 with a PUT request
  3. The object key is saved on the user record
  4. Avatars are served through signed URLs generated by the backend

πŸš€ Getting started

# install dependencies
npm install

# start MySQL, Kafka, Redis, Elasticsearch and admin UIs
npm run docker:up

# run migrations and seed data
npm run migration:run
npm run db:seed

# start the services in watch mode
npm run start:api-gateway
npm run start:event-service

API docs are available at http://localhost:3000/api (Swagger).

More detail lives in readme/GETTING_STARTED.md and readme/MIGRATIONS.md.

Tests

npm run test       # unit tests
npm run test:e2e   # end-to-end tests
npm run test:cov   # coverage report

πŸ“‘ Endpoints

πŸ”’ = auth required Β· πŸ“ƒ = paginated

Auth

  • POST /auth/login

Users

  • GET /users/@{username}
  • GET /users/{userid}
  • POST /users
  • PATCH /users/{userid} πŸ”’
  • PUT /users/{userid}/follow πŸ”’
  • DELETE /users/{userid}/follow πŸ”’
  • GET /users πŸ“ƒ
  • GET /users/{userid}/followers πŸ“ƒ
  • GET /users/{userid}/followees πŸ“ƒ

Posts

  • GET /posts/{postid}
  • POST /posts πŸ”’ (simple posts, replies, reposts and quote posts)
  • DELETE /posts/{postid} πŸ”’
  • PUT /posts/{postid}/like πŸ”’
  • DELETE /posts/{postid}/like πŸ”’
  • GET /posts πŸ“ƒ filtered by author
  • GET /posts filters for replies, original posts and full-text search
  • #hashtags and @mentions in posts

Hashtags

  • GET /hashtags πŸ“ƒ
  • GET /hashtags/{tag}/posts πŸ“ƒ

πŸ› οΈ Tech stack

Nest.js Β· TypeScript Β· TypeORM Β· MySQL Β· Kafka (KafkaJS) Β· Redis (ioredis) Β· DataLoader Β· Elasticsearch Β· DynamoDB Β· AWS S3 Β· Swagger Β· Jest Β· Docker Β· Terraform Β· GitHub Actions Β· Datadog


πŸ‘€ Author

Mustkeem K, Senior Full Stack Engineer Β· mustkeemk.com Β· LinkedIn

Licensed under the GNU AGPL v3.

About

Twitter-style social backend in Nest.js microservices: API gateway + Kafka event service, MySQL, Redis, Elasticsearch, DynamoDB, S3, Terraform CI/CD

Topics

Resources

Code of conduct

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages