Skip to main content

Prerequisites

Before you begin, ensure you have the following installed on your development machine:
Install Git for version control from git-scm.comVerify installation:
git --version
Recommended: Visual Studio Code or Cursor with the following extensions:
  • ESLint
  • Prettier
  • Tailwind CSS IntelliSense
  • TypeScript and JavaScript Language Features

Installation

1. Clone the Repository

git clone https://github.com/dazedmind/rlink.git
cd rlink

2. Install Dependencies

This project uses npm and has a package-lock.json file for consistent dependency versions.
npm install
Do not use yarn or pnpm as this may cause dependency conflicts. Stick with npm to maintain consistency with the lock file.

3. Environment Configuration

Create a .env file in the project root with the following variables:
# Database Configuration
DATABASE_URL="postgresql://username:password@host/database?sslmode=require"

# Application URLs
NEXT_PUBLIC_APP_URL="http://localhost:3000"
BETTER_AUTH_URL="http://localhost:3000"
SITE_URL="http://localhost:3000"

# CORS Configuration
ALLOWED_ORIGIN="http://localhost:3000"

# Email Configuration (Resend)
RESEND_API_KEY="re_xxxxxxxxxxxxxxxxxxxxx"
RESEND_FROM="RLink <noreply@yourdomain.com>"

# Security
BETTER_AUTH_SECRET="your-secret-key-here-min-32-chars"
CRON_SECRET="your-cron-secret-here"
REVALIDATION_SECRET="your-revalidation-secret-here"
VariablePurposeRequired
DATABASE_URLNeon PostgreSQL connection string✅ Yes
NEXT_PUBLIC_APP_URLPublic site URL (used by auth client)✅ Yes
BETTER_AUTH_URLAuth origin fallback⚠️ Optional
SITE_URLFor health checks and cache tooling⚠️ Optional
ALLOWED_ORIGINProduction browser origin for API CORS✅ Yes (Production)
RESEND_API_KEYResend API key for sending emails✅ Yes
RESEND_FROMDefault “from” email address⚠️ Optional
BETTER_AUTH_SECRETSecret for Better Auth (min 32 chars)✅ Yes
CRON_SECRETBearer token for cron endpoints✅ Yes (Production)
REVALIDATION_SECRETBearer token for cache-clear APIs⚠️ Optional

4. Database Setup

Generate and Apply Migrations

The repository includes pre-generated migrations in the drizzle/ directory. Apply them to your database:
npx drizzle-kit migrate

Alternative: Push Schema Directly (Development Only)

For rapid local iteration, you can push the schema directly without migrations:
npx drizzle-kit push
Use drizzle-kit push only in development with disposable databases. Always use proper migrations for production.

Generate New Migrations (After Schema Changes)

If you modify db/schema.ts or db/auth-schema.ts:
npx drizzle-kit generate
npx drizzle-kit migrate

Development Server

Start the development server:
npm run dev
Open http://localhost:3000 in your browser.

Default Routes

  • Login: /login
  • Dashboard: /home
  • Forgot Password: /forgot-password
  • Reset Password: /reset-password
The dashboard (/home/*) uses client-side protection via ProtectedRoute component and authenticated API routes.

Project Structure Overview

rlink/
├── app/                    # Next.js App Router
│   ├── api/               # API route handlers
│   ├── home/              # Authenticated dashboard (/home/*)
│   ├── login/             # Public auth entry
│   ├── forgot-password/
│   ├── reset-password/
│   └── globals.css
├── components/            # Shared UI components
├── db/                    # Database schemas
│   ├── schema.ts          # Application tables
│   └── auth-schema.ts     # Better Auth tables
├── drizzle/               # SQL migrations
├── hooks/                 # React hooks
├── lib/                   # Domain helpers and utilities
│   ├── cms/               # CMS types, queries, cache
│   ├── crm/
│   ├── iam/
│   └── email/
├── templates/email/       # React Email templates
├── proxy.ts               # Session redirect + API CORS helpers
└── public/                # Static assets

Available Scripts

CommandDescription
npm run devStart development server
npm run buildBuild for production
npm run startStart production server
npm run lintRun ESLint
npm testRun Jest tests
npm run test:watchRun tests in watch mode

Verifying Your Setup

1. Check Database Connection

The application should connect to your Neon database on startup. Check the terminal for any connection errors.

2. Access the Login Page

Navigate to http://localhost:3000/login and ensure the page loads correctly.

3. Run Tests

npm test
All tests should pass if the setup is correct.

Next Steps

Architecture

Understand the system design

Database schema

Learn about the data models

Authentication

Explore auth implementation

REST API reference

Review available endpoints

Dashboard overview

Understand the app areas under /home/*

Testing

Verify setup, auth, and API behavior

Troubleshooting

  • Verify your DATABASE_URL is correct
  • Ensure your Neon database is active and accessible
  • Check that SSL mode is properly configured in the connection string
  • Confirm firewall settings allow database connections
  • Delete node_modules/ and package-lock.json
  • Run npm install again
  • Ensure you’re using a compatible Node.js version (LTS recommended)
If port 3000 is already in use:
# macOS / Linux — find and stop the process on port 3000
lsof -ti:3000 | xargs kill -9

# Or use a different port
PORT=3001 npm run dev
# Windows PowerShell — find PID on port 3000, then stop it
Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue |
  Select-Object -ExpandProperty OwningProcess -Unique |
  ForEach-Object { Stop-Process -Id $_ -Force }

# Or use a different port
$env:PORT=3001; npm run dev
  • Ensure BETTER_AUTH_SECRET is at least 32 characters
  • Verify NEXT_PUBLIC_APP_URL matches your actual URL
  • Check that auth tables were created in the database
If something still fails, check the terminal and browser Network tab for the exact status code and response body. That message usually points to the root cause (missing env, bad URL, or schema mismatch).