Skip to main content

Prerequisites

Before starting, ensure you have:
  • Python 3.13+: Check with python --version
  • uv: Python package installer (installation guide)
  • Bun 1.3.7+: JavaScript runtime and package manager (installation guide)
  • Git: For cloning the repository

Quick Start

The simplest way to run Codex-LB locally is using uvx:
This will:
  • Install Codex-LB in an isolated environment
  • Start the server on port 2455
  • Store data in ~/.codex-lb/
Open http://localhost:2455 to access the dashboard.

Development Setup

For active development with hot reload:

1. Clone the Repository

2. Install Dependencies

3. Configure Environment

Create a .env.local file in the project root:
Edit .env.local to customize settings. Key options:
See Configuration for all options.

4. Run Development Servers

Open two terminal windows: Terminal 1 - Backend (FastAPI):
This starts the backend on http://localhost:2455 with hot reload. Terminal 2 - Frontend (Vite):
This starts the frontend dev server on http://localhost:5173 with HMR (Hot Module Replacement).
In development mode, the frontend at :5173 proxies API requests to the backend at :2455.

5. Access the Dashboard

Open http://localhost:5173 in your browser for the development build with hot reload. For production-like testing, open http://localhost:2455 after building the frontend.

Using Docker Compose for Development

For a containerized development environment with hot reload:
This starts both frontend and backend containers with file watching enabled:
  • Backend changes in ./app sync to the container
  • Frontend changes in ./frontend sync to the container
  • Dependency changes (pyproject.toml, package.json) trigger rebuilds
Access:
Docker Compose watch requires Docker Compose v2.22+ with BuildKit enabled.

Data Directory

Local development stores data in:
To reset your local database:

Database Management

Running Migrations

Manually run database migrations:

Creating Migrations

When you modify database models:
Migration filenames use the format YYYYMMDD_HHMMSS_slug.py to reduce merge conflicts.

Validating Migrations

Before committing migrations, validate them:
This checks:
  • Single migration head (no branches)
  • Correct revision naming format
  • No schema drift between models and migrations

Using PostgreSQL Locally

To test with PostgreSQL:

Building the Frontend

To build the frontend for production:
The output is placed in app/static/, which the FastAPI backend serves at the root path. Test the production build:
Open http://localhost:2455 to see the production build.

Port Configuration

Backend (FastAPI)

Default: 2455 Change with:

Frontend (Vite Dev Server)

Default: 5173 Change in frontend/vite.config.ts:

OAuth Callback

Default: 1455 (cannot be changed) This port is required by OpenAI’s OAuth implementation.

Testing API Endpoints

Interactive API Docs

FastAPI provides interactive documentation:

Using curl

Testing OAuth Flow

  1. Start the backend with OAuth settings configured
  2. Open the dashboard at http://localhost:5173
  3. Navigate to AccountsAdd Account
  4. Click Login with OpenAI
  5. Complete OAuth flow (redirects to port 1455)

Common Development Tasks

Adding a New Endpoint

  1. Create/edit a route in app/modules/*/api.py
  2. Define schemas in app/modules/*/schemas.py
  3. Implement business logic in app/modules/*/service.py
  4. Register the router in app/main.py if new
  5. Test at http://localhost:2455/docs

Modifying the Database

  1. Update models in app/modules/*/models.py
  2. Generate migration: uv run alembic revision --autogenerate -m "description"
  3. Review and edit migration in app/db/migrations/versions/
  4. Apply: uv run python -m app.db.migrate upgrade
  5. Validate: uv run codex-lb-db check

Adding Frontend Features

  1. Edit React components in frontend/src/
  2. Changes hot-reload automatically at http://localhost:5173
  3. Use Tanstack Query for API calls (see existing queries)
  4. Build for production: cd frontend && bun run build

Code Style and Linting

Python

The project uses Ruff for linting and formatting:

Frontend

The frontend uses ESLint and Prettier:

Debugging

Backend

Add breakpoints in your IDE or use breakpoint() in the code:
Run with:

Frontend

Use browser DevTools:
  1. Open http://localhost:5173
  2. Press F12 to open DevTools
  3. Use Console, Network, and Sources tabs for debugging

Database Queries

Enable SQL query logging in .env.local:
This prints all SQL queries to the console.

Troubleshooting

Port Already in Use

Find and kill the process using the port:

Module Not Found

Ensure dependencies are installed:

Frontend Build Fails

Build the frontend:

Database Locked

SQLite is locked by another process. Ensure only one backend instance is running:

OAuth Redirect Fails

Verify in .env.local:
Ensure nothing else is using port 1455.

Next Steps