Skip to main content
Kuldeep Singh
Kuldeep SinghDigital Architecture
OPEN SOURCE · CONTENT CONTROL PLANE · IMMUTABLE REVISIONS · GOVERNED PUBLISHING · AGENT-READY OPERATIONSTier 1 Flagship

BrewCMS: Open-Source Content Control Plane & Agent Operating System

When traditional CMS architectures force false choices between fragile headless SaaS subscription bills and bloated legacy monolithic platforms, architect content as a governed, database-agnostic control plane with bounded agent autonomy and zero SaaS lock-in.

Engineering a database-agnostic, local-first content platform for Next.js 15 with deterministic Content IR, immutable SHA-256 revision trees, native Model Context Protocol (MCP) tooling, and pluggable storage providers (in-process SQLite, PostgreSQL, MySQL).

CONTENT CONTROL PLANEMCP AGENT TOOLSPLUGGABLE STORAGEIMMUTABLE REVISIONSHEXAGONAL COREZERO SAAS LOCK-IN
OPEN SOURCE FLAGSHIP · MCP READY100% In-Browser Execution
Executive BriefOpen
Domain / ScopeOpen Source & Content Systems
Architectural RoleCreator & Principal Systems Architect
Timeline & InitiativeOpen Source Systems Initiative · 2026
Key Verified Invariant

100% elimination of third-party headless CMS SaaS subscription costs across all reference applications.

01 // The Constraint

What Made the Problem Difficult

As digital platforms scale, content management systems have bifurcated into two undesirable extremes: monolithic legacy platforms with excessive memory and plugin overhead, or API-first SaaS headless platforms that separate content from presentation at the cost of high monthly bills, external network latency, and brittle third-party dependencies. Furthermore, with the rise of autonomous AI coding assistants (Cursor, Claude Desktop, Antigravity), engineering teams need AI agents to inspect, draft, and propose content modifications directly. However, giving AI agents unconstrained write access to databases creates severe risks of hallucinations and brand drift. A new architecture was needed: a local-first, zero-dependency Content Operating System that combines sub-millisecond in-process performance with formal, human-gated AI autonomy.

Core Platform Constraint

Systemic Friction
01
Headless CMS SaaS platforms introduce recurring subscription costs, vendor lock-in, and 20ms–80ms HTTP latency round-trips for every document query. 2) Traditional Node.js SQLite solutions depend on better-sqlite3 or native C++ addons that fail on modern serverless or lightweight hosting environments. 3) Content revisions in standard CMS databases are mutable, causing unversioned content drift without cryptographic audit trails. 4) AI agents lack a standard, governed interface to read and write content safely without bypassing editorial review.
Boundary Invariants & Operational Limits:
  • !Zero native C++ build dependencies: Must run on Node.js 22 native node:sqlite without node-gyp.
  • !Sub-millisecond read latency: Public document queries must execute in <0.2ms directly from disk B-trees.
  • !Bounded AI agent autonomy: Autonomous operations must be subject to policy gates (ALLOW, DENY, REQUIRE_APPROVAL).
  • !Dual-topology flexibility: Must run embedded inside existing Next.js apps or standalone as a headless REST server.
  • !Zero SaaS subscription fees: 100% self-hosted on commodity disk without external database infrastructure.
02 // The Architecture

What System Was Designed

BrewCMS implements a strict Hexagonal / Ports & Adapters architecture. At the center is @brew-cms/core, containing pure TypeScript domain entities, business logic, and application services with zero framework dependencies. The content layer (@brew-cms/content) tokenizes Markdown and Frontmatter into a versioned Abstract Syntax Tree / Content IR, computing a deterministic SHA-256 hash for every revision. Storage (@brew-cms/db) is abstracted via repository interfaces implemented on top of Node.js 22 native node:sqlite with Write-Ahead Logging (WAL) and 5000ms busy timeouts for high-concurrency read/write operations. AI agents interact through a native Model Context Protocol server (@brew-cms/mcp) that maps agent tool calls (brew_create_draft, brew_request_publish) to core application services, evaluating every mutation against a declarative policy engine (@brew-cms/policy) before execution. In consumer applications, BrewCMS embeds directly inside the Next.js App Router, enabling Server Components to query documents in-process with zero network overhead while exposing the full Editorial Studio at /admin/cms.

03 // The Key Decision

Pivotal Architectural Choices

Key Architectural Decisions

ADR // 01DETERMINISTIC CHOICE

Native node:sqlite with WAL Mode over external database or native addons

Context:

Traditional embedded SQLite in Node.js required better-sqlite3, which requires native C++ compilation tools (python, make, gcc) that frequently break in containerized or shared hosting environments.

Alternatives Evaluated:
  • PostgreSQL
  • better-sqlite3
  • Supabase
  • Cloudflare D1
Chosen: Node.js 22 built-in node:sqlite with PRAGMA journal_mode = WAL

Zero npm build scripts, zero native C++ compilation requirements, ~15MB LRU memory cache footprint, and sub-0.2ms read latency directly on NVMe disk. Fits within any standard Node hosting quota without managing a separate database daemon.

ADR // 02DETERMINISTIC CHOICE

Deterministic Content IR with SHA-256 Hashing over raw Markdown storage

Context:

Storing raw markdown strings causes parsing ambiguities, unverified HTML injection risks, and makes detecting exact semantic content modifications difficult across revision histories.

Alternatives Evaluated:
  • Raw markdown text
  • HTML string blobs
  • ProseMirror JSON
Chosen: Deterministic Content IR (Abstract Syntax Tree) validated by Zod schemas with cryptographic content hashes

Decouples storage from rendering, allows safe client and server rendering without dangerouslySetInnerHTML hazards, and computes exact cryptographic content hashes for immutable revision tracking.

ADR // 03DETERMINISTIC CHOICE

Embedded In-Process Engine over Mandatory Remote Headless Server

Context:

Deploying a separate CMS server requires dedicated ports, subdomain registration (cms.domain.com), cross-origin CORS handling, and extra webapp slots on hosting platforms like Hostinger.

Alternatives Evaluated:
  • Mandatory Headless API
  • Microservices container
  • Third-party SaaS
Chosen: Dual-mode architecture supporting both embedded in-process direct calls and standalone REST API

Allows Next.js applications like CoffeeDiscussions and this portfolio to run the entire CMS natively inside /admin/cms using 0 extra webapp slots, 0 subdomains, and zero HTTP network round-trips.

ADR // 04DETERMINISTIC CHOICE

Native Model Context Protocol (MCP) with Human Approval Policy Gates

Context:

AI agents need structured access to query documents, propose drafts, and update taxonomies without being given unfettered write or publish permissions.

Alternatives Evaluated:
  • Custom OpenAI function calling
  • Unrestricted REST API tokens
  • LangChain agent tools
Chosen: Standardized Model Context Protocol (MCP) server with @brew-cms/policy enforcement

Provides universal compatibility with Cursor, Claude Desktop, and autonomous agent loops. Low-risk operations (reading, drafting) are allowed automatically, while high-risk operations (publishing, unpublishing) generate approval requests for human editors.

04 // The Engineering

What Was Actually Built

01

13 Modular TypeScript Packages: Built as a strict pnpm monorepo using TypeScript project references (tsc -b), ensuring clean dependency graphs and zero circular imports.

02

High-Concurrency WAL Concurrency: SQLite configured with PRAGMA journal_mode = WAL, synchronous = NORMAL, and busy_timeout = 5000, allowing concurrent readers alongside write operations without database locking errors.

03

Full Next.js 15 App Router Editorial Studio: Responsive studio featuring split-pane live markdown editing, real-time HTML preview, revision rollback history, media library asset browser, taxonomy governance, and agent approval queues.

04

Zero-Latency Server Component Hydration: In embedded mode, Next.js Server Components call repository methods directly in-process, bypassing the HTTP network stack entirely.

05

Cryptographic Audit Trail: Every state transition, human editorial decision, and AI agent execution emits an immutable audit event recording actor identity, before/after snapshots, and timestamps.

05 // The Trade-offs

Deliberate Architectural Compromises

Trade-offs & Mitigations

Database Storage

Architectural Benefit:

Zero external server cost, zero connection latency, and instant local-first execution via node:sqlite.

Associated Cost:

Multiple applications maintain independent SQLite database files on disk rather than a single unified database.

Mitigation Strategy:

Supported through BrewCMS REST API export/import pipelines and optional standalone headless deployment topology.

AI Agent Autonomy

Architectural Benefit:

Guaranteed editorial integrity and zero unauthorized content publishing or hallucinations.

Associated Cost:

AI agents cannot publish documents to live production without a human editor approving the action run.

Mitigation Strategy:

Integrated one-click human approval queue in the Studio UI and automated notification hooks.

06 // The Result

Verified Outcomes

✓ VERIFIED RESULT

100% elimination of third-party headless CMS SaaS subscription costs across all reference applications.

✓ VERIFIED RESULT

Reduced content retrieval latency from ~30ms HTTP round-trips down to sub-0.2ms in-process SQLite B-tree queries.

✓ VERIFIED RESULT

Consumes only 2 out of 5 allowed webapp slots on Hostinger, leaving 3 slots completely free for future applications.

✓ VERIFIED RESULT

Full test suite passing: 12 test suites, 45/45 tests passing with 100% clean typecheck (0 errors).

✓ VERIFIED RESULT

Full production adoption across CoffeeDiscussions (magazine) and VictorKuldeep developer portfolio.

07 // Architecture Blueprint

System Schematic & Data Flow

System Topology Blueprint
BrewCMS Governed Content Operating System & Agent Control Plane
INTERACTIVE SCHEMATIC
STAGE 01 · INGESTION & MCPHuman Studio EditorMarkdown + YAML HeaderAI Coding Agents (MCP)Cursor · Claude · Antigravitybrew_create_draft / toolPolicy Approval GateMandatory Human SignoffASTSTAGE 02 · DOMAIN KERNEL1. Zod AST ParserStrict Schema Validation2. Deterministic Content IRCanonical intermediate rep3. SHA-256 ChecksumsCryptographic IntegrityDraft → Review → PublishedStorage PortSTAGE 03 · PLUGGABLE STORAGEPluggable AdaptersSQLite · Postgres · MySQLLocal SQLite (WAL)In-Process • <0.2ms LatencyImmutable RevisionsSHA-256 Revision DAG<0.2msSTAGE 04 · CONSUMPTIONNext.js 15 RSCDirect In-Process Read0ms Network OverheadHeadless REST API/api/v1/[...route]Studio Control Plane/admin/cmsAudit Log TrailFull Agent Telemetry

Hexagonal pipeline showing human editorial studio, bounded AI agents via MCP, deterministic Content IR compiler, and in-process SQLite storage.

Text alternative for screen readers: Architecture flow: Human Editor / AI Agent (MCP) to Policy Engine Gate via RBAC & Autonomy Boundaries; Policy Engine Gate to Application Services via Approved Content Operations; Application Services to Content IR Compiler via Markdown Parsing & SHA-256 Hashing; Content IR Compiler to Immutable Revision Tree via Append-Only Historical Snapshots; Immutable Revision Tree to In-Process SQLite (WAL) via <0.2ms B-Tree Storage; In-Process SQLite (WAL) to Next.js Server Components via Zero-Latency Page Hydration

08 // Why It Matters

Architectural Conclusion

The future of web software is not static CMS databases or unmonitored AI agents, but governed content operating systems where human editorial intent and machine autonomy coexist safely with local-first performance and zero SaaS vendor tax.

Key Lessons for Platform Scale:
  • Local-first SQLite with WAL mode is vastly superior to remote headless APIs for single-server and shared-hosting Next.js architectures.
  • AI agents in production need formal policy boundaries and approval queues rather than direct database write permissions.
  • Deterministic Content IR with cryptographic hashing eliminates content drift and makes revision rollbacks completely predictable.