This project is a whatsapp integration for Monika. It allows you to send recovery and incident notifications to your whatsapp number.
This is a monorepo project using Turborepo and pnpm. It contains the apps (in apps directory) and packages (in packages directory).
web: The Next.js web app that allows user to register their whatsapp number and to get the unique URL to use in their Monika configuration. They can also get the instructions to use Monika with WhatsApp. This app also allows user to delete the webhook from our database.facebook-webhooks: The Hono server that handles the webhooks from Facebook.facebook-webhooks-netlify: The Netlify Functions app that serves thefacebook-webhooksapp.notify-api: The Hono server that handles the notifications from Monika. The URL of this server is used in the Monika configuration.notify-api-netlify: The Netlify Functions app that serves thenotify-apiapp.whatsapp-mock-server: The mock server that simulates the WhatsApp API for development purposes.docs: This documentation app which is using Fumadocs to generate the documentation.
env: The package that contains the environment variables for the project. Use this package to read environment variables in the apps and packages.whatsapp: The package that contains the WhatsApp API client and other helpers to send messages via WhatsApp.database: The package that contains the prisma client, schema, and other helpers to interact with the database.ui: The package that contains the shadcn components and other UI components which can be used in the apps likeweb.eslint-config: The package that contains the eslint config which can be used in other apps and packages.eslint-config-custom: The package that contains the custom eslint config which can be used in other apps and packages.typescript-config: The package that contains the typescript config which can be used in other apps and packages.utils: The package that contains the utility functions which can be used in other apps and packages.
- Run
pnpm installto install the dependencies. cp env.example .envfrom thepackages/envdirectory.- Edit the environment variable values as needed.
- Run
./dev-bootstrap.shto bootstrap the development environment. The script basically creates symlinks to thepackages/env/.envfile to.env.localin all apps and packages.
- Run
docker-compose upto start the database. - Run
pnpm run buildto build the apps and packages. We need to build the packages first because the apps depend on the packages. - Run
pnpm run dev --filter whatsapp-mock-serverto start the WhatsApp mock server. - Set
WHATSAPP_API_BASE_URLtohttp://localhost:5001in thepackages/env/.envfile. The5001port is the port of the WhatsApp mock server you run in the step 3. If you change the port, you need to update this value. - Run
pnpm run dev --filter webto start the development server.
- Run
pnpm run buildto run the apps and packages. - Run
pnpm run dev --filter notify-apito start the development server.
pnpm dlx shadcn@latest add button -c apps/web
You can either create a new package manually by creating a new directory in the packages directory and adding a package.json file to it or by copying an existing package and modifying it. To duplicate an existing package, you can run the following command from the root of the project:
pnpm dlx turbo gen workspace --copy
After adding a new package, you need to:
- run
pnpm installfrom the root of the project to install the dependencies. - run
./dev-bootstrap.shto bootstrap the development environment. - If you want to use the package in the apps or other packages, you need to run
pnpm installfrom the root of the project again after adding the package topackage.jsonfile.
This project uses env-to-t3 to generate strongly typed code to read environment variables. Follow these guides to use it in your app or package:
- In your app or package, don't read environment variables using
process.envdirectly. Instead, use theenvpackage. - Every time you make changes (change the name, add new variables, delete variables) to the
.envfile in thepackages/envpackage, you need to runpnpm run buildfrom thepackages/envpackage. - If you make changes to the
.envfile in thepackages/envpackage, make sure to update theenv.examplefile in the same package.
- The tests are written using vitest.
- To test React components, we use testing-library.
- Contrary to common practice, the prisma client is not mocked in most of the tests. Instead, we use a test database. Each test will create a new schema in the test database. Then the function that is being tested will use the test database through the dependency injection mechanism. In this project, we use async local storage to provide the database context. See the tests for more information.
- Before running tests, you need to run
docker-compose upfrom the root of the project to start the database. - Run
pnpm run testto run the tests. - Run
pnpm run coverageto run the tests with coverage. - The coverage report will be generated in the
coveragedirectories of each package. - To open the coverage reports in the browser, run
./open-coverages.sh. - To combine the coverage reports of all apps and packages, run
pnpm run coverage:combined.
You can clean up node_modules, coverage, dist, build, .turbo, .cache, generated, and .next directories by running ./clean.sh.
- If you got typescript errors like cannot find module of the other package, try run
pnpm installfrom the root of the project to install the dependencies, thenpnpm run build.
This project is licensed under the MIT License.