Skip to content

Monorepo of all Pocket App Typescript Backend Sevices

License

Notifications You must be signed in to change notification settings

Pocket/pocket-monorepo

Repository files navigation

Pocket Monorepo

This repo contains all the Pocket Typescript systems built as a monorepo but deployed as microservices. For services that power Recomendations or Pocket Curated Content see the Content Monorepo

What's inside?

This Repo includes the following packages/servers:

Folder structure

  • servers: all our typescript microservices required for running baseline Pocket.
  • lambdas: all our lambda listeners that are made up of SQS Queue processers or API Gateways
  • infrastructure: all of the terraform infrastructure that is used to deploy each microservice
  • packages/eslint-config-custom: eslint configurations
  • packages/tsconfig: tsconfig.jsons used throughout the monorepo
  • packages/apollo-utils: holds helpers for all services that boot up graphql. It also includes tracing libraries and hoists apollo in node-modules so that we do not have to keep defining apollo in all services.
  • packages/ts-logger: helper library to add json structured logging to all our services.
  • packages/tracing: helper library to add tracing to all our services.
  • packags/terraform-modules: a set of modules built for Pocket based on the Terraform CDK, used to deploy our infrastructure.
  • .docker/aws-resources: all aws resources that are used by the monorepo, if something is used here, but owned by a service not in this repository, it resides in the legacy files, otherwise each service will have its own script or prefixed resources.
  • .docker/mysql-8-resources: all mysql resources, prefixed with a number letter system so that docker executes database creation in a specific order. All services share a single docker server, but have their own databases unless they read from our legacy (mono) database.
  • .docker/postgres-resources: similar to mysql but for services that use postgres.

Each package/app is 100% TypeScript.

Utilities

This Turborepo has some additional tools already setup for you:

Using the Repo

To build all apps and packages, run the following command:

cd pocket-monorepo
pnpm build

Develop

All

To develop all apps and packages, run the following commands:

cp .env.example .env
cd pocket-monorepo
docker compose up --wait
pnpm dev

This will bring up the docker shared services (MySQL, Memcached, Redis) and then run all the apps in a dev mode.

Specific Server

To run a specific server, run the following:

cp .env.example .env
cd pocket-monorepo
docker compose up --wait
pnpm dev --filter=annotations-api...

Where annotations-api is the server name from package.json you want to run. ... prefixed informs turborepo to include all dependent workspace packages.

You can expand this to run multiple specific servers as well like: pnpm run dev --filter=list-api... --filter=feature-flags...

Caching

This repo relies on Turbo repos caching strategies to speed up development and only execute tasks that are needed when certain files change.

More information can be found on Turbo repos site.

If you add new build outputs or inputs, you will need to add them to the necessary area in turbo.json.

If for any reason you need to bypass caching you can add --force to any command. It would be run like:

pnpm run test --force

or

pnpm run test --filter=annocations-api... --force

Testing

Updating Packages

To update packages this repository uses Renovate on a pr by pr basis and you can initiate that here

In some cases it may be easier to update packages locally, like updating all development depencies at once.

To select and update development dependencices, interactively you can use the following command ran at the root of the repository.

pnpm update -iDLr

To select and update production and optional dependencices, interactively you can use the following command ran at the root of the repository.

pnpm update -iPLr

Integration Testing

When doing an integration test, if you need aws based resources, the CI is setup to run a .sh script that corresponds to the package name you are testing. So if you need aws resources for a package named annotations-api you would create a annoations-api.sh in .docker/aws-resources that created all the necessary aws resources.

Useful Links

Learn more about the power of Turborepo: