Skip to main content

Infrastructure Overview

Production deployment topology for the TrickBook platform.

System Diagram​

External Services

AWS EC2 (single instance, nginx in front)

DNS (thetrickbook.com)

Clients

iOS App

Android App

Web Browser

api.thetrickbook.com

thetrickbook.com

docs.thetrickbook.com

TB-Backend
Express.js
Port 9000

kaori-bot
ElizaOS
Port 3001

kith-voice
Port 3040

PostgreSQL
pgvector (Kaori RAG)

MongoDB Atlas

AWS S3
Image Storage

Bunny.net CDN
Video Streaming

AWS Amplify
Website Hosting

EAS Build

Apple App Store

Google Play Store

Docusaurus
Docs Site

EC2 Instance​

PropertyValue
InstanceOne EC2 instance behind nginx (identifiers in the internal runbook)
OSUbuntu
App directory/home/ubuntu/TB-Backend/
Env file/home/ubuntu/TB-Backend/.env

PM2 Processes​

Three Node.js processes run under PM2:

Process NamePortPurpose
TB-Backend9000Main Express.js API server (REST + Socket.IO)
kaori-bot3001ElizaOS agent for Kaori AI companion
kith-voice3040Voice processing service

SSH Access​

ssh ubuntu@<backend-host>

Host identifiers, the SSH command and key name live in the internal runbook (not in this repo).

danger

The SSH private key must never be committed to any repository or shared in plaintext. Store it in ~/.ssh/ with permissions set to 600.

PM2 Commands​

NVM must be sourced before running PM2 commands on the server:

# Source NVM (required in non-interactive shells / scripts)
. ~/.nvm/nvm.sh

# Restart the backend
pm2 restart TB-Backend

# View logs
pm2 logs TB-Backend

# View logs for all processes
pm2 logs

# Check process status
pm2 status

# Restart all processes
pm2 restart all

DNS Configuration​

DomainTargetService
api.thetrickbook.comEC2 (nginx reverse proxy)Backend API
thetrickbook.comAWS AmplifyWebsite (Next.js)
docs.thetrickbook.comDocusaurus hostingDocumentation site

External Services​

MongoDB Atlas​

Cloud-hosted MongoDB cluster. Connection string is stored in the ATLAS_URI environment variable on the EC2 instance.

danger

The ATLAS_URI connection string contains database credentials. It must only be stored in the server's .env file or in platform secret managers, never in source code.

PostgreSQL (pgvector)​

Runs directly on the EC2 instance. Used by the kaori-bot process for RAG (Retrieval-Augmented Generation) -- storing and querying vector embeddings for Kaori's knowledge base.

AWS S3​

Used for image storage (profile photos, trick media). Access credentials (AWS_KEY, AWS_SECRET) are configured in the backend .env file.

Bunny.net CDN​

Handles video streaming for trick clips. The backend uploads videos to Bunny.net's stream library and serves playback URLs to clients. Configured via BUNNY_API_KEY, BUNNY_LIBRARY_API_KEY, and BUNNY_STREAM_TOKEN_KEY.

AWS Amplify​

Hosts the Next.js website at thetrickbook.com. Deployments are triggered by pushes to the website repository.

EAS Build​

Expo Application Services builds the React Native mobile app for distribution:

  • iOS: Builds are submitted to Apple App Store / TestFlight
  • Android: Builds are submitted to Google Play Store

Deployment Flow​

Backend​

Merge staging into backend master

SSH to EC2

cd /home/ubuntu/TB-Backend

git fetch + fast-forward origin/master

npm install

pm2 restart TB-Backend

Step-by-step:

# 1. SSH into the server (host and key name are in the internal runbook)
ssh ubuntu@<backend-host>

# 2. Navigate to the app directory
cd /home/ubuntu/TB-Backend

# 3. Pull latest changes
git fetch origin master
git merge --ff-only origin/master

# 4. Install any new dependencies
npm ci --omit=dev # only when package manifests changed

# 5. Source NVM and restart
. ~/.nvm/nvm.sh && pm2 restart TB-Backend

# 6. Verify the process is running
pm2 status

# 7. Check logs for errors
pm2 logs TB-Backend --lines 50

Website​

Pushes to the website repository trigger automatic deployment via AWS Amplify.

Mobile App​

Builds are triggered manually via EAS CLI:

# iOS (TestFlight)
eas build --profile testflight --platform ios

# Android (Play Store)
eas build --profile playstore --platform android

See App Store Deployment and Google Play Deployment for detailed submission guides.