Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto
1## Getting Started 2 3### Prerequisites 4 5#### Required 6- **Node.js** (>= v21.0.0) - JavaScript runtime 7- **Rust** (latest stable) - For Rust services compilation 8- **pnpm** (package manager) - Workspace management 9- **PostgreSQL** - Database server 10 11#### Optional Development Tools 12- **Docker** & **Docker Compose** - Container orchestration (compose files included) 13- **cargo-watch** - Auto-rebuilding Rust services during development 14- **cargo-tarpaulin** - For checking code coverage in Rust 15 16### Installation 17 181. **Install required dependencies**: 19 ```bash 20 # Install Rust (if not already installed) 21 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 22 23 # Install pnpm (if not already installed) 24 npm install -g pnpm 25 ``` 26 272. **Set up the project**: 28 ```bash 29 # Install all dependencies (Node.js and Rust) 30 pnpm install 31 32 # clone submodules 33 git submodule update --init --recursive 34 35 # Set up environment configuration 36 cp apps/aqua/.env.example apps/aqua/.env 37 38 # Set up database with SQLx 39 ./scripts/setup-sqlx.sh 40 41 # Or manually: 42 pnpm run db:create 43 pnpm run db:migrate 44 ``` 45 463. **macOS-specific setup** (if needed): 47 ```bash 48 pnpm add @libsql/darwin-x64 49 ``` 50 514. **Optional: Install development tools**: 52 ```bash 53 # For Rust file watching during development 54 cargo install cargo-watch 55 56 # optionally, set up docker + docker-compose 57 # on Linux 58 curl -fsSL https://get.docker.com -o get-docker.sh 59 sudo sh get-docker.sh 60 61 # on macOS, you should use colima or orbstack 62 brew install colima # or brew install orbstack 63 colima start # or use the GUI for orbstack 64 ``` 65 665. **Bring up dependencies** (Docker): 67 ```bash 68 # bring up all dependencies with the compose.dev.yml compose file 69 docker compose up -d -f compose.dev.yml garnet postgres 70 ``` 71 72### Database Management 73 74This project uses **SQLx** for database management with PostgreSQL. Please note all database operations are handled through raw, albeit typechecked, SQL. 75 76#### Database Commands 77 78```bash 79# Set up database and run all migrations 80./scripts/setup-sqlx.sh 81 82# Individual database operations 83pnpm db:create # Create database 84pnpm db:migrate # Run migrations 85pnpm db:migrate:revert # Revert last migration 86pnpm db:reset # Drop, recreate, and migrate database 87pnpm db:prepare # Prepare queries for compile-time verification 88``` 89 90#### Migration Management 91 92- **Location**: `services/migrations/` 93- **Format**: `YYYYMMDDHHMMSS_description.sql` (timestamped SQL files) 94- **Type**: Forward-only SQL migrations managed by SQLx 95 96## Development 97 98To start the development server run: 99 100```bash 101turbo dev --filter=@teal/aqua 102``` 103 104Open http://localhost:3000/ with your browser to see the home page. Note: if the redirect back to the app after you login isn't working correctly, you may need to replace the `127.0.0.1` with `localhost`, or you may need to set up a publicly accessible endpoint for the app to post to (see below). 105 106### Running the full stack in docker for development 107 108_Still a work in progress and may have some hiccups_ 109 110#### 1. Set up publicly accessible endpoints. 111 112It is recommended if you are running aqua to make a publicly accessible endpoint for the app to post to. You can do that a couple of ways: 113 114- Set up the traditional port forward on your router 115- Use a tool like [ngrok](https://ngrok.com/) with the command `ngrok http 8080` or [Cloudflare tunnels](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/) (follow the 2a. portion of the guide when you get to that point). 116 117If you do the cloudflare tunnels for amethyst as well, 118you will also need 119to follow [this](https://caddy.community/t/caddy-with-cloudflare-tunnel/18569) for routing to work properly. 120Although you can just run it locally and it will work. 121 122#### 2. Set up .envs 123 1241. copy [.env.template](.env.template) and name it [.env](.env). The docker build will pull everything from this `.env`. There are notes in the [.env.template](.env.template) on what some of the values should be. 1252. Follow the instructions in [piper](https://github.com/teal-fm/piper) to set up environment variables for the music scraper. But name it `.env.air` 126 127#### 3. Run docker 128 1291. Make sure docker and docker compose is installed 1302. It is recommended to run 'docker compose -f compose.dev.yml pull' to pull the latest remote images before running the docker compose command. 1313. Run `docker compose -f compose.dev.yml up -d` 132 133And that's it! You should have the full teal.fm stack running locally. Now if you are working on aqua you can do `docker container stop aqua-app` and run that locally during development while everything else is running in docker. 134 135### Lexicon Management 136 137We use AT Protocol lexicons with dual TypeScript/Rust codegen (lex-cli + esquema). Use the unified lexicon CLI for managing schema changes: 138 139```bash 140# Generate all types from lexicons 141pnpm lex:gen 142 143# Watch lexicons and auto-regenerate 144pnpm lex:watch 145 146# Validate type consistency 147pnpm lex:validate 148 149# Show lexicon change impact 150pnpm lex:diff 151``` 152 153# Updating Vendored Lexicons 154To update vendored lexicons (anything that's not under fm.teal), follow these steps: 155```bash 156cd vendor/atproto 157git pull origin main 158cd ../.. 159git add vendor/atproto 160git commit -m "Update atproto lexicons to latest" 161``` 162 163See [`tools/lexicon-cli/README.md`](tools/lexicon-cli/README.md) for detailed documentation.