# nimforum NimForum is a light-weight forum implementation with many similarities to Discourse. It is implemented in the [Nim](https://nim-lang.org) programming language. **This fork uses [BaraDB](https://github.com/yourusername/baradb) instead of SQLite.** BaraDB is a custom database engine that communicates via a TCP wire protocol. The forum connects to a running BaraDB server instead of opening a local SQLite file. ## Architecture ``` ┌─────────────┐ HTTP ┌─────────────┐ TCP ┌─────────────┐ │ Browser │ ◄─────────────► │ nimforum │ ◄────────────► │ BaraDB │ │ │ │ (Jester) │ (wire proto) │ Server │ └─────────────┘ └─────────────┘ └─────────────┘ │ ▼ ┌─────────────┐ │ public/ │ │ (JS, CSS) │ └─────────────┘ ``` ## Why BaraDB? This project was created to test and validate BaraDB's SQL compatibility and wire protocol. Running a real-world application like NimForum against BaraDB surfaced many practical issues (reserved keywords, type conversions, async protocol safety) that unit tests alone would not catch. ## Changes from upstream | Area | Upstream | This fork | |------|----------|-----------| | Database | SQLite (file) | BaraDB (TCP server) | | DB driver | `db_connector/db_sqlite` | `baradb_sqlite.nim` (drop-in adapter) | | Keywords | `status`, `key`, `like` | Renamed to `usrStatus`, `sessionKey`, `postLike` | | Date/time | `DATETIME('now')` | `NOW()` | | FTS search | SQLite FTS4 | Disabled (returns empty) | | HTTP backend | httpbeast (multi-threaded) | asynchttpserver (single-threaded)* | \* *Switched to `asynchttpserver` via `-d:useStdLib` because httpbeast's worker threads share the global `db` ref, causing GC corruption and segfaults at startup.* ## Requirements * Nim >= 2.0 * Nimble * libsass / libsass-dev (for SCSS compilation) * A running BaraDB server (see below) ## Quick start ### 1. Start BaraDB ```bash cd ../Baradb BARADB_JWT_SECRET=test nimble build_debug BARADB_JWT_SECRET=test ./build/baradadb ``` The server listens on `127.0.0.1:9472` by default. ### 2. Build and run the forum ```bash cd nimforum git submodule update --init --recursive # Build CSS and frontend JS nimble frontend # Create development database (admin/admin) nimble devdb # Compile and run backend nimble backend ``` The forum will be available at `http://localhost:5000`. ### Build tasks ```bash nimble backend # Compile & run the forum backend nimble runbackend # Run the compiled backend nimble frontend # Build CSS + JS frontend assets nimble devdb # Create a dev database with seed data nimble testdb # Create a test database nimble blankdb # Create an empty database ``` ## Project layout ``` nimforum/ ├── src/ │ ├── forum.nim # Main Jester backend │ ├── baradb_client.nim # BaraDB wire-protocol client │ ├── baradb_sqlite.nim # Drop-in db_sqlite adapter │ ├── setup_nimforum.nim # DB initialization script │ └── frontend/ # Karax SPA sources ├── public/ │ ├── js/forum.js # Compiled frontend (generated) │ ├── css/ # Compiled SASS + Spectre │ └── images/ ├── Baradb/ # BaraDB source (sibling directory) └── nimforum.nimble ``` ## Known issues / limitations * **FTS search disabled** — BaraDB does not support SQLite FTS4 virtual tables. The search endpoint returns empty results. * **No `COLLATE NOCASE`** — Some string comparisons may be case-sensitive where the original was not. * **Manual `nextId()`** — Auto-increment is simulated with `SELECT COALESCE(MAX(id),0)+1`, which is not atomic under high concurrency. * **Single-threaded HTTP** — Due to the global `db` ref holding async TCP state, the forum runs on a single async thread. For a busy site you would need per-request DB connections or a connection pool. ## License MIT — see upstream [nimforum](https://github.com/nim-lang/nimforum) for original copyright.