Skip to main content

Prerequisites

Before setting up PrivyCode locally, ensure you have the following installed:

Go 1.23+

Required for running the Go backend server

PostgreSQL

Database for storing users and viewer links

GitHub OAuth App

For authenticating users via GitHub

Git

For cloning the repository

Step 1: Clone the Repository

1

Clone the repository

git clone https://github.com/greatdaveo/privycode-server
cd privycode-server
2

Install Go dependencies

go mod tidy
This will download all required dependencies including:
  • gorm.io/gorm - ORM for database operations
  • gorm.io/driver/postgres - PostgreSQL driver
  • github.com/joho/godotenv - Environment variable loading
  • golang.org/x/oauth2 - GitHub OAuth2 integration

Step 2: Set Up PostgreSQL Database

1

Create a PostgreSQL database

CREATE DATABASE privycode;
2

Get your database connection URL

Your DATABASE_URL should follow this format:
postgresql://username:password@localhost:5432/privycode?sslmode=disable
For local development, sslmode=disable is acceptable. For production, always use SSL connections.

Step 3: Create GitHub OAuth App

1

Go to GitHub Developer Settings

Navigate to GitHub Developer Settings → OAuth Apps → New OAuth App
2

Configure your OAuth app

Application name
string
required
PrivyCode Local (or any name you prefer)
Homepage URL
string
required
http://localhost:5173 (or your frontend URL)
Authorization callback URL
string
required
http://localhost:8080/github/callback
3

Save your credentials

After creating the app, copy:
  • Client ID
  • Client Secret (click “Generate a new client secret”)
You’ll need these for your .env file.

Step 4: Configure Environment Variables

1

Create .env file

Copy the example environment file:
cp .env.example .env
2

Update .env with your values

.env
PORT=8080
DATABASE_URL=postgresql://username:password@localhost:5432/privycode?sslmode=disable
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GITHUB_CALLBACK_URL=http://localhost:8080/github/callback
FRONTEND_URL=http://localhost:5173
MOBILE_URL=http://localhost:5173
Do not set GO_ENV=production for local development. The server will automatically load the .env file when GO_ENV is not set to production.

Step 5: Run Database Migrations

1

Uncomment migration line

Open cmd/server/main.go and uncomment the migration line:
cmd/server/main.go
func main() {
    // To Connect to the DB
    config.ConnectDB()

    // For auto migrate to DB
    config.RunMigrations() // Uncomment this line

    // ... rest of the code
}
2

Run the server once to migrate

go run cmd/server/main.go
You should see:
Connected to PostgreSQL successfully!!!
Migrations completed successfully
Server starting on :8080...
3

Comment out migration line

After the first run, comment out the migration line again to avoid running migrations on every server restart:
cmd/server/main.go
// config.RunMigrations()

Step 6: Start the Development Server

go run cmd/server/main.go
The server will start on http://localhost:8080
Your server is now running! You should see:
Connected to PostgreSQL successfully!!!
Server starting on :8080...

Testing the API

1

Test the health check

curl http://localhost:8080/
2

Test GitHub OAuth login

Visit http://localhost:8080/github/login in your browser. You should be redirected to GitHub for authentication.

Common Issues

Make sure your .env file exists in the project root and is not named .env.txt or similar.
  • Verify PostgreSQL is running: psql -U postgres -c "SELECT 1;"
  • Check your DATABASE_URL format
  • Ensure the database exists: psql -U postgres -l
  • Verify your GITHUB_CALLBACK_URL matches exactly what’s in GitHub OAuth settings
  • Check that GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET are correct
  • Ensure your frontend URL is in the CORS allowed origins
Change the PORT in your .env file or kill the process using port 8080:
# Find process on port 8080
lsof -i :8080

# Kill it
kill -9 <PID>

Next Steps

Environment Variables

Learn about all available configuration options

Deployment

Deploy your server to production

API Reference

Explore the available API endpoints

Authentication

Understand how authentication works

Build docs developers (and LLMs) love