|
| 1 | +--- |
| 2 | +title: Architecture Overview |
| 3 | +description: Understanding the ObjectStack Trinity. How ObjectQL, ObjectOS, and ObjectUI collaborate to build the Enterprise Kernel. |
| 4 | +--- |
| 5 | + |
| 6 | +# Architecture Overview |
| 7 | + |
| 8 | +ObjectStack is not a monolithic framework. It is a composable ecosystem designed around a **Layered Architecture**. We call this the **"ObjectStack Trinity."** |
| 9 | + |
| 10 | +Each layer is decoupled and communicates via standard JSON protocols. This allows you to swap out implementations (e.g., swapping the React renderer for a Flutter renderer) without breaking the rest of the stack. |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +## The Trinity |
| 15 | + |
| 16 | +### 1. The Data Layer: ObjectQL |
| 17 | +**"The Universal Protocol"** |
| 18 | + |
| 19 | +At the foundation lies ObjectQL. It is responsible for **Data Definition** and **Data Access**. |
| 20 | + |
| 21 | +* **Role:** Defines *Structure* (Schema) and *Intent* (Query AST). |
| 22 | +* **Responsibility:** It knows *what* a "Customer" object looks like, but it doesn't know *who* is accessing it or *how* it is displayed. |
| 23 | +* **Key Component:** The **Compiler**. It takes an abstract query (`find customers where active = true`) and translates it into optimized SQL for the specific underlying database (Postgres, SQLite, MySQL). |
| 24 | + |
| 25 | +### 2. The Control Layer: ObjectOS |
| 26 | +**"The Business Kernel"** |
| 27 | + |
| 28 | +Sitting in the middle is ObjectOS. It is responsible for **Orchestration** and **Governance**. |
| 29 | + |
| 30 | +* **Role:** Manages the *Lifecycle* of a request. |
| 31 | +* **Responsibility:** |
| 32 | + * **Identity:** "Who is this user?" (Authentication). |
| 33 | + * **Security:** "Can they see this field?" (RBAC/ACL). |
| 34 | + * **Sync:** "How do we merge these offline changes?" (Conflict Resolution). |
| 35 | + * **Process:** "What happens after this record is saved?" (Workflows/Triggers). |
| 36 | +* **Key Concept:** It acts as the gateway. No direct database access is allowed; everything must pass through the OS Kernel. |
| 37 | + |
| 38 | +### 3. The View Layer: ObjectUI |
| 39 | +**"The Projection Engine"** |
| 40 | + |
| 41 | +At the top is ObjectUI. It is responsible for **Interaction** and **Rendering**. |
| 42 | + |
| 43 | +* **Role:** Consumes the Protocol to render the Interface. |
| 44 | +* **Responsibility:** It does not contain hardcoded forms. Instead, it asks ObjectQL: *"What is the schema for a Customer?"* and dynamically renders a layout based on that metadata. |
| 45 | +* **Key Concept:** **Server-Driven UI (SDUI)**. The backend dictates the layout, validation rules, and available actions. The frontend is merely a highly capable renderer. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## The Request Lifecycle |
| 50 | + |
| 51 | +To understand how these pieces fit together, let's trace a typical user interaction—for example, a Sales Rep updating a deal status while offline. |
| 52 | + |
| 53 | +### Step 1: Interaction (ObjectUI) |
| 54 | +The user clicks "Mark as Won" in the UI. |
| 55 | +* **ObjectUI** validates the input against the JSON Schema (loaded locally). |
| 56 | +* It does not send an API request immediately. It writes the change to the **Local Database** (e.g., SQLite/RxDB). |
| 57 | +* The UI updates instantly (0ms latency). |
| 58 | + |
| 59 | +### Step 2: Synchronization (ObjectOS Sync) |
| 60 | +When the network is available, the Client pushes a "Mutation Packet" to the Server. |
| 61 | +* **ObjectOS** receives the packet. |
| 62 | +* It authenticates the session (`@objectos/auth`). |
| 63 | +* It checks against the **Audit Log** for conflicts (e.g., did someone else edit this deal 5 minutes ago?). |
| 64 | +* It runs any server-side **Workflow** logic (e.g., "If Deal > $10k, trigger Manager Approval"). |
| 65 | + |
| 66 | +### Step 3: Compilation (ObjectQL) |
| 67 | +Once ObjectOS approves the request, it passes the data operation to ObjectQL. |
| 68 | +* **ObjectQL** receives the AST: `UPDATE Deals SET Status = 'Won' WHERE ID = '123'`. |
| 69 | +* The **Compiler** translates this into the target dialect: `UPDATE "deals" SET "status" = 'Won'...`. |
| 70 | +* The **Driver** executes the SQL against the master PostgreSQL database. |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Deployment Topologies |
| 75 | + |
| 76 | +Because the architecture is protocol-driven, it supports various deployment models depending on your infrastructure needs. |
| 77 | + |
| 78 | +### A. The Monolith (Default) |
| 79 | +Ideal for small-to-medium enterprise apps. |
| 80 | +* **Frontend:** React Single Page App (SPA). |
| 81 | +* **Backend:** A single Node.js instance running ObjectOS + ObjectQL Core. |
| 82 | +* **Database:** Single PostgreSQL instance. |
| 83 | + |
| 84 | +### B. Local-First / Edge |
| 85 | +Ideal for field service apps, POS systems, and high-performance SaaS. |
| 86 | +* **Frontend:** ObjectUI + Embedded ObjectQL (Wasm) + SQLite. |
| 87 | +* **Backend:** ObjectOS running as a Sync Gateway (Stateless). |
| 88 | +* **Database:** Distributed SQL or simple object storage for replication logs. |
| 89 | + |
| 90 | +### C. Microservices Federation |
| 91 | +Ideal for large-scale enterprise integration. |
| 92 | +* Multiple ObjectOS instances (CRM Service, ERP Service, HR Service). |
| 93 | +* A centralized **Gateway** aggregates the ObjectQL schemas into a "Super Graph" (similar to GraphQL Federation). |
| 94 | +* ObjectUI renders a unified dashboard by consuming the federated schema. |
0 commit comments