Backend
The code is located in thepkg directory and is started by the main.py file in the root directory.
Install dependencies, we use uv to manage dependencies.
data/config.yaml file.
Frontend
The code is located in theweb directory and requires Node.js and pnpm.
Copy .env.example to .env and fill in the values.
- Usage in Linux and other environments
- Usage in Windows environments
http://127.0.0.1:3000 to view the standalone frontend page.
In production environments, the frontend will be precompiled into static files and provided by the backend, and the frontend will automatically access the backend address on the same domain.
Code Formatting
The repository contains lint and format check workflows, and your code will be automatically checked when you push it. Please configure pre-commit to check your code locally before submitting.API Documentation
We will write API documentation in APIFox before developing each interface. Please refer to API Documentation(Chinese).Database Migrations
LangBot uses Alembic to manage database migrations, supporting both SQLite and PostgreSQL seamlessly without database-specific branching.Migration File Location
Creating a New Migration
The recommended way is to use autogenerate, which compares ORM models against the database schema and generates a migration script:src/langbot/pkg/persistence/alembic/versions/. Review and edit the generated script to confirm the changes are correct before committing.
Autogenerate can automatically detect column additions/removals, table changes, type changes, etc. However, for data migrations (e.g., modifying JSON field content), you need to manually add code to the generated script.
NNNN_description.py:
Migration Patterns
Schema Changes (add/drop columns, create tables)
Schema Changes (add/drop columns, create tables)
env.py sets render_as_batch=True, which makes Alembic automatically handle SQLite’s ALTER TABLE limitations (via temporary table rebuild). No need to branch on database type.Data Migrations (read and modify data)
Data Migrations (read and modify data)
How It Works
Migrations run automatically when LangBot starts — no manual commands needed:- On first startup, the baseline version is automatically stamped (marking the existing database)
- On subsequent startups, all pending migrations are applied (
alembic upgrade head)
CI Testing
The repository includes atest-migrations.yml workflow that automatically tests migration scripts on both SQLite and PostgreSQL when persistence/ related files change.
