Local Development
This guide walks you through setting up your local development environment to contribute to the Sayr codebase.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have the following tools installed:
| Tool | Version | Purpose |
|---|---|---|
| Node.js | 22+ (LTS recommended) | Runtime for frontend and tooling |
| Bun | 1.0+ | Runtime for backend and worker services |
| pnpm | 10.6+ | Package manager |
| PostgreSQL | 15+ | Primary database |
| Docker | Latest (optional) | Containerized development |
Installing Prerequisites
Section titled “Installing Prerequisites”# Install pnpm globallynpm install -g pnpm
# Install Bun (required for backend/worker)curl -fsSL https://bun.sh/install | bash
# Verify installationsnode --version # Should be 22+pnpm --version # Should be 10.6+bun --version # Should be 1.0+Project Structure
Section titled “Project Structure”Sayr is a Turborepo monorepo with the following structure:
sayr/├── apps/│ ├── backend/ # Hono API server (Bun, port 5468)│ ├── start/ # TanStack Start frontend (port 3000)│ ├── marketing/ # Astro docs/marketing site (port 3002)│ └── worker/ # GitHub webhook processor (Bun)├── packages/│ ├── auth/ # Better Auth configuration│ ├── database/ # Drizzle ORM schemas and CRUD│ ├── storage/ # MinIO S3-compatible client│ ├── ui/ # Shadcn/ui component library│ ├── util/ # Shared utilities│ ├── queue/ # Job queue abstraction│ └── opentelemetry/ # Tracing utilities└── ...Initial Setup
Section titled “Initial Setup”1. Clone the Repository
Section titled “1. Clone the Repository”git clone https://github.com/dorasto/sayr.gitcd sayr2. Install Dependencies
Section titled “2. Install Dependencies”We recommend using pnpm for all package management tasks:
pnpm install3. Configure Environment Variables
Section titled “3. Configure Environment Variables”Copy the environment template to each app that requires it:
cp .env.example apps/backend/.envcp .env.example apps/start/.envcp .env.example apps/worker/.envEdit each .env file with your local configuration. Key variables include:
Database:
DATABASE_URL=postgresql://user:password@localhost:5432/sayrStorage (MinIO/S3):
STORAGE_URL=http://localhost:9000STORAGE_BUCKET=sayrSTORAGE_ACCESS_KEY=minioadminSTORAGE_SECRET_KEY=minioadminFILE_SALT=your-random-saltFILE_CDN=http://localhost:9000/sayrFrontend:
VITE_URL_ROOT=http://admin.app.localhost:3000VITE_PROJECT_NAME=SayrVITE_ROOT_DOMAIN=app.localhost4. Set Up the Database
Section titled “4. Set Up the Database”Ensure PostgreSQL is running, then push the schema:
pnpm -F @repo/database db:pushTo explore your database with a visual interface:
pnpm -F @repo/database db:studio5. Start Development
Section titled “5. Start Development”Start all apps simultaneously:
pnpm devOr start specific apps:
# Backend API onlypnpm -F backend dev
# Frontend onlypnpm -F start dev
# Marketing/docs site onlypnpm -F marketing devLocal Domains
Section titled “Local Domains”Sayr uses subdomain-based routing in development. The primary reason behind this is due to constraints with how cookies are handled in development environments. By using subdomains, we can ensure that cookies are scoped to the correct domain, allowing for seamless authentication and session management.
| URL | Purpose |
|---|---|
http://admin.app.localhost:3000 | Admin dashboard |
http://{org-slug}.app.localhost:3000 | Organization workspace |
http://localhost:5468 | Backend API |
http://localhost:3002 | Marketing site and documentation (what you’re looking at right now) |
Development Commands
Section titled “Development Commands”Common Commands
Section titled “Common Commands”| Command | Description |
|---|---|
pnpm dev | Start all apps in development mode |
pnpm build | Build all apps for production |
pnpm lint | Run Biome linting |
pnpm lint:fix | Fix linting issues automatically |
pnpm check-types | Run TypeScript type checking |
Database Commands
Section titled “Database Commands”| Command | Description |
|---|---|
pnpm -F @repo/database db:push | Apply schema changes |
pnpm -F @repo/database db:studio | Open Drizzle Studio |
Testing
Section titled “Testing”| Command | Description |
|---|---|
pnpm -F start test | Run all tests |
pnpm -F start test -- --testNamePattern="pattern" | Run tests matching pattern |
pnpm -F start test -- path/to/file.test.ts | Run specific test file |
Code Style
Section titled “Code Style”Sayr uses Biome for linting and formatting. Always run linting before committing:
pnpm lint # Check for issuespnpm lint:fix # Auto-fix issuesFor detailed coding conventions including import organization, naming conventions, error handling patterns, and component structure, see the Code Style Guide.
Adding UI Components
Section titled “Adding UI Components”Sayr uses Shadcn/ui for the component library. To add a new component:
pnpm dlx shadcn@latest add <component-name>Troubleshooting
Section titled “Troubleshooting”Port Already in Use
Section titled “Port Already in Use”If a port is already in use, you can find and kill the process:
# Find process using port 3000lsof -i :3000
# Kill the processkill -9 <PID>Database Connection Issues
Section titled “Database Connection Issues”Ensure PostgreSQL is running and the DATABASE_URL in your .env file is correct:
# Check PostgreSQL statuspg_isready -h localhost -p 5432Bun Not Found
Section titled “Bun Not Found”If you get “bun: command not found” errors, ensure Bun is installed system-wide and in your PATH:
# Check Bun installationwhich bunbun --version
# If not found, reinstallcurl -fsSL https://bun.sh/install | bashsource ~/.bashrc # or ~/.zshrcType Errors After Schema Changes
Section titled “Type Errors After Schema Changes”After modifying database schemas, regenerate types:
pnpm -F @repo/database db:pushNext Steps
Section titled “Next Steps”Once your environment is set up, explore these guides to learn more:
- Architecture Overview — Understand how Sayr’s systems connect
- Code Style Guide — Coding conventions and best practices
- Database Guide — Working with Drizzle ORM schemas and queries
- Testing Guide — Writing and running tests with Vitest
- Adding Features — End-to-end guide for implementing new features
- Pull Request Guidelines — PR conventions and review process
- Writing Documentation — Contributing to these docs (no local setup needed!)
Ready to Contribute?
Section titled “Ready to Contribute?”- Pick an issue from the GitHub Issues
- Create a feature branch from
main - Make your changes following our code style guidelines
- Run
pnpm lintandpnpm check-typesbefore committing - Submit a pull request following our PR guidelines
Thank you for contributing to Sayr!