How we built our own second brain first
Before SecondBrainDB existed as a product idea, VillaGPT (this project's own internal engineering operation) built a permission-aware, auditable memory and job-ledger layer to keep its own multi-agent work coherent. This page is a sanitized, high-level build guide describing that internal project honestly — what it set out to do, how it is structured, what testing and backup work has actually happened, and what is still unresolved. It is a dated snapshot, not a live status page, and it is kept clearly separate from the SecondBrainDB commercial direction described elsewhere on this site.
Goals
The internal project set out to solve one recurring problem: a growing set of AI-assisted engineering tasks, run across many separate working sessions, kept losing shared context — who changed what, why, under what authorization, and whether a prior attempt had already partially succeeded. The goals were:
- One durable, queryable record of work ("a job ledger") instead of scattered task notes, so a new session can tell what already happened.
- Permission- and provenance-awareness from the start — no assistant session gets broader read access than the task in front of it needs.
- Idempotent, reversible operations by default — a retried or re-run step should detect prior state, not blindly repeat it.
- Honest status tracking — a clear, enforced distinction between something that is merely reported, something independently verified, and something actually live (see the glossary below).
Generic architecture
The system of record is a relational database, not a prompt log or a vector store — the vector/retrieval layer (where one exists) is treated as an optional, rebuildable accelerator on top of the ledger, never the only copy of the data. Every read path into the projection layer is scoped by the same permission model that governs the underlying ledger, so "bounded retrieval" means a session can only see what its own scope allows, not an unrestricted export of the whole ledger.
Guided platform discovery & least-privilege MySQL setup
Setting up the database for this internal project did not start from a
generic shell prompt and a model improvising commands. It used the same
pattern now offered publicly on Guided
Start: a reviewed, versioned prompt first asks an assistant to
report the actual environment (existing databases, available
privileges, storage, network exposure) and to propose a
least-privilege plan — which user, which grants, which schema — before
anything is created. A human reviews that proposal and only then
approves the specific commands to run. For example (synthetic, not a
real transcript): an assistant proposing a new application-only MySQL
user scoped to a single schema with SELECT, INSERT, UPDATE
on specific tables — not ALL PRIVILEGES, and not access to
other schemas on the same instance — is the expected shape of that
proposal, reviewed before it is ever executed.
Role interviews & a shared company foundation
The ledger is one shared schema and permission foundation, not a personal database each person (or each AI session) reshapes on its own. Before adding a new area of tracked work, the pattern is a short, structured interview with the role that owns it — synthetic example: an "operations" role is asked what it needs recorded, what it explicitly does not want visible to other roles, and what existing system (if any) is already the source of truth it should defer to — followed by a cross-role review before any schema change ships, so one role's convenience request doesn't quietly break another role's expectations of the shared foundation.
Source permissions, version history & idempotency
Every schema change is a versioned, numbered migration with both an "up" and a "down" script, reviewed as an ordinary diff before it is applied — there is no freeform, unreviewed schema editing. Installers and migrations are designed to be safely re-run: before changing anything, each step checks recorded applied-state rather than assuming "it didn't report success last time, so it's safe to redo everything."
A resolved problem, described at a safe high level: an internal fault-injection test deliberately interrupted an installer partway through applying a migration, then re-ran it. The original rollback logic assumed it would only ever be invoked against a fully pre-migration or fully post-migration database — against the partially-applied state produced by the interruption, it could have left the schema inconsistent. The fix added an explicit applied-state check before rollback runs, so rollback now refuses to act on state it doesn't recognize instead of guessing. This was caught by tests that deliberately injected failures mid-run, not by normal happy-path testing — a lesson carried into how later migrations are tested.
Bounded retrieval
The "second brain" projection that AI sessions actually query is a read-scoped view of the ledger, rebuildable from it, never an independent copy that can drift out of permission sync with the source. A session's retrieval is bounded to its own authorized scope — there is no "retrieve everything and filter client-side" path, because that would mean the unfiltered data left the trust boundary before any filtering happened.
Tests & backup/restore validation
The ledger's test suite combines unit tests with integration tests run against a real, ephemeral database engine (not only mocked database calls) — several defects in this project were only caught by the real-database integration tests, because a hand-written mock had quietly stopped enforcing a constraint the real engine still enforced. Backup-and-restore procedures have been drilled and checksum-verified in an isolated, non-production test context, including a full restore-from-backup rehearsal. What has not happened: this project's offsite/remote backup replication milestone is, as of this writing, only internally reported — it has not been independently re-verified end-to-end, and it is never described here as delivered. A separate installer step that requires elevated (root) privileges on its target host also remains pending, not completed.
Lessons learned
- Mock-only tests can hide real bugs. A test double that doesn't enforce the same constraints as the real database will pass even when the real system would fail — the fix was adding real (ephemeral, disposable) database integration tests alongside unit tests, not removing the mocks entirely.
- Idempotency has to be designed in, not assumed. "The script finished without an error" is not the same guarantee as "running the script again is safe" — installers need an explicit applied-state check, found the hard way via the rollback issue above.
- Multi-agent review found bugs a single pass missed, at a real cost. A trial where a lead AI session delegated parts of a review to separate read-only reviewer sessions was measurably slower than one session working the same review alone — but it surfaced two real defects the solo pass had missed. That trade-off (slower, but higher recall on review-heavy work) is treated as situational, not a default way of working.
- "Reported" and "verified" are not the same word. Several status claims in this project's own internal task history turned out, on independent re-check, to need correction — which is the direct reason the glossary below exists and is enforced on this page.
Status glossary — how claims on this page are labeled
This project separates what a task reports from what has been independently re-checked, and separates where a change has actually run:
| Label | Meaning |
|---|---|
| Reported | Stated in an internal task record; not yet independently re-confirmed. |
| Verified | Independently re-checked (e.g. by a separate review pass or a later task) against live evidence, not just restated. |
| Prepared | Written and tested in isolation, but not yet run against its real intended target. |
| Installed | Applied to a real but non-production target. |
| Preview | Deployed to a staging/preview environment, not serving real traffic. |
| Production | Live, serving real traffic or users. |
| Unknown | Not yet established either way — explicitly flagged rather than assumed. |
Applied to this case study, for example: the fault-injection-tested installer safety check above is prepared, not yet exercised against a live production target; the offsite backup milestone is reported, explicitly not verified; and the elevated-privilege installer step is unknown/pending, not completed.
Remaining limitations
This internal project is not presented as enterprise-ready, fully autonomous, or guaranteed to succeed elsewhere. Known open items as of this writing include: the offsite backup milestone described above remains unverified; an installer step requiring elevated host privileges has not been completed; and some internal status claims have historically needed correction after independent review, which is exactly why this page states only what has been checked, and labels everything else accordingly. None of this is a claim of bank-grade, vendor-certified, or compliance-audited status.
The guided, customer-owned build model this case study informs — see Guided Start — is intended as an AI-assisted adaptation your own organization runs and owns, not a universal vendor connector platform that integrates every system out of the box.