# Software After Software: Building a High-Performance, AI-Native Enterprise Core

**Why I Built Astra CMS: A Zero-Downtime, Metadata-Driven Core for the AI Era**

Building enterprise software for fast-moving sectors like logistics and supply chain usually means living with a frustrating bottleneck. Business operations change daily, yet the underlying software stays stuck in a slow cycle: gather requirements, write boilerplate, run risky database migrations, and wait for a maintenance window.

Every time a regional branch needs a new field on an order form, someone has to run an `ALTER TABLE` migration. Every time a large client wants custom logic, engineering teams end up forking the codebase and creating long-term maintenance debt. Now, with AI agents entering the workflow, letting LLMs write code or query production databases directly on traditional architectures is a massive operational risk.

I wanted to solve this at the root. If an application is defined entirely as data, can the software change every day without breaking yesterday’s production?

To answer that, I built [**Astra CMS**](https://labs.sagozen.digital/posts/astra-cms-gioi-thieu). It is an open-source, metadata-driven enterprise platform built for continuous schema evolution, zero downtime, high throughput, and safe AI execution.

---

### 1\. Zero-Downtime Schema Changes Without Table Locks

Astra borrows the core concept of `DocType` from systems like Frappe and ERPNext, though it shares zero code or schema with them. A single YAML file defines the fields, validations, permissions, forms, REST APIs, webhooks, and workflows of a record.

The key architectural difference lies in the storage layer:

- **JSONB by Default with Online Indexes:** Instead of creating a physical SQL table per entity and locking tables on every schema change, Astra stores records in PostgreSQL `JSONB`. If a field requires fast filtering, marking it with `projected: true` creates an online expression index. Form customization in production never locks a table.
- **Tenant Overlays Without Forking:** Multi-tenancy should not require maintaining multiple code branches. In Astra, a tenant can add fields, modify permissions, or attach custom scripts using a versioned YAML overlay. For example, a Hanoi branch can add VAT and island-delivery fields in a single file. It applies at runtime with zero restarts, zero changes to the upstream app, and automated compatibility checks before rollout.

---

### 2\. High Throughput and Financial-Grade Data Integrity

Dynamic schemas often trade off speed or data integrity. Astra avoids both pitfalls through strict separation of concerns:

- **Append-Only Ledgers for Accounting:** While general documents live in `JSONB`, financial entries and inventory movements use immutable, append-only double-entry ledger tables. Records are never updated in place. Mistakes are corrected strictly via reversal entries through a formal `Submit / Cancel / Amend` lifecycle.
- **Rust CDC Workers & Distributed Transactions:** Change Data Capture (CDC) workers are written in **Rust** for high throughput and predictable memory usage. Distributed transactions across microservices are coordinated via **Apache Seata** (AT mode on PostgreSQL, TCC on Redis).
- **Database-Level Isolation:** Multi-tenancy is enforced via PostgreSQL Row-Level Security (RLS). As a hard safety rule, the Astra kernel refuses to boot if connected with a database superuser account.

---

### 3\. Safe Execution and Native Access for AI Agents

Adding AI to enterprise software requires more than bolting a chat wrapper onto an API. Astra is designed so AI agents can both build and operate the system within hard boundaries, keeping humans in control of critical approvals.

**Sandboxed Code Generation (3-Tier Isolation):** Letting an AI write business logic only works if a bad script cannot crash the host. Astra separates extensions into three tiers, using a **WebAssembly (Wasm) Sandbox** at Tier 2 for tenant scripts and AI-generated code.

- Scripts written in Rust, Go, TypeScript, or Python compile to Wasm and hot-swap at runtime.
- In our logistics demo, a holiday shipping discount written in Rust compiled down to **421 bytes**. If an AI-generated script hits an infinite loop, the Wasm sandbox terminates it at **50ms** without touching the underlying JVM pod.

**Native MCP Tools with RBAC:** Every `DocType`, event, and background job is automatically exposed as a **Model Context Protocol (MCP)** tool with a strict JSON Schema.

- When an agent like Claude calls Astra via MCP, it uses the caller's exact token, tenant context, and permissions, with automatic PII masking.
- A support agent's AI assistant cannot create unauthorized orders. When an accounting agent asks about Cash-on-Delivery (COD) balances, the query reads directly from the ledger and requires source citations. Any financial answer without a valid ledger citation is rejected.

---

### 4\. Compliance Built Into the Schema

Instead of treating SOC 2, ISO 27001, and GDPR as an afterthought, Astra embeds compliance directly into the data model. Every `DocType` field includes attributes for data classification, retention period, legal basis, and residency. Data processing records, retention schedules, and audit trails are generated straight from the schema.

---

### What Works Today

Astra CMS is open-source under the MIT License. The repository clearly separates what is running today from the remaining 10-phase roadmap.

Right now, you can spin up a local Kubernetes (`k3d`) cluster with two kernel pods and test:

- PostgreSQL RLS multi-tenancy, `JSONB` storage, and live YAML tenant overlays.
- The Wasm sandbox, Rust CDC workers, Apache Seata transactions, and Keycloak SSO/SCIM.
- The built-in MCP server with field-level PII masking.
- Three reference apps: **Astra Express** (courier and parcel logistics), **HRM/Payroll**, and **STMS** (vehicle routing powered by Timefold).

You can run the full stack locally with JDK 25, Docker, `kubectl`, and `k3d`:

```bash
git clone https://github.com/ZeroHostCMS/astra-cms.git && cd astra-cms
make k3d-up      # API at http://localhost:8080/api
make demo        # Two tenants, hooks, naming series, RLS
make demo-seed   # Seed data for the courier logistics app
open http://localhost:8080/desk/

```

### Links & Resources

- **Source Code:** [GitHub: ZeroHostCMS/astra-cms](https://github.com/ZeroHostCMS/astra-cms)

I am actively looking for feedback on the `DocType` metadata contracts, the 3-tier isolation model, and ERP module boundaries.

Clone the repo, test it out, and let me know what you think.
