/chirp-backend

Backend for Chirp, a Twitter clone. Built on Deno.

Primary LanguageTypeScript

Backend for Chirp: A Twitter clone

We created Chirp, a very simple copy of Twitter to learn about Agile Process Management, Collaboration, Web Technologies and Relational Databases. This repository contains the backend code for Chirp.

Website Frontend Repository Postman Docs Swagger Docs

The backend is built on Deno + Oak and currently deployed on Deno Deploy. It uses synchronous JWTs for authorization and a Cockroach database on Cockroach Labs. However, apart from Row-Based TTL, our implementation is compatible to PostgreSQL. The system additionally interacts with MailerSend for sending emails to users and ImageKit.io for storing user data.

The frontend repository can be found here

Servers

The API is publicly accessible using the proper user authentication.

Production Server: https://api.thechirp.de
Sandbox Server: https://sandbox.api.thechirp.de

If you stumble across a chirp.koenidv.de, it is equivalent to thechirp.de.

Running locally

  1. If you haven't already, install deno
  2. Get the .env or new keys for each environment variable
  3. Run deno run -A main.ts

Documentation

The public interactive API documentation can be found at docs.api.thechirp.de.
If you prefer using Postman, you can refer to the badge above. Please note joining the Postman Team requires manual approval.

Project Architecture

Project Architecture

Testing

Run tests using deno test --allow-read --allow-env.

Mock Server

The GET methods at and below /v1/tweet and /v1/user are available as mocked endpoints for frontend testing. Simply direct your requests to https://a092a8fb-fc57-4e0e-b09f-3f41170486b0.mock.pstmn.io.

Mocked user: halbunsichtbar
Mocked tweet: 72969718891000
Mocked comment: 73013027891000

Load Testing

Load testing is done using Locust against localhost (testing database integration) or the sandbox server.

To start Locus, use:
locust -f ./locust/locustfile.py --headless -H http://sandbox.api.thechirp.de/v1 -u 15 -r 1 -t 5m

Refer to the Locust documentation for more information.

Environment Variables

Make sure to include these paramters in your environment to make the service work:

  • DATABASE_URL - Connection string to your Cockroach database
  • JWT_KEY - 256bit synchronous key for JWT signing
  • MAILERSEND_KEY - API key for MailerSend
  • CDN_KEY - API key for ImageKit.io
  • SENTRY_DSN - DSN for Sentry

Deploying

This project is continuously deployed on Deno Deploy on pushes to main.
If you'd rather deploy on your own infrastructure, a Dockerfile is set up. However, the database will not be set up automatically and you will have to run ./db/makeTables.ts manually.

Security

Threat Model

A list of security measures implemented can be found in securitymeasures.md.

Data Model

ERD