Skip to main content

OnIt Database

Manages projects, terminal associations, and context documents.
╔═════════════════════════════════════════════════════════════════════╗
║                        ONIT.DB OVERVIEW                              ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   ┌─────────────────────┐  ┌─────────────────────┐                   ║
║   │  monolex_projects   │  │ monolex_project_    │                   ║
║   │                     │  │ folders             │                   ║
║   │ - id (PK)           │  │                     │                   ║
║   │ - name              │  │ - project_id (FK)   │                   ║
║   │ - description       │  │ - folder_path       │                   ║
║   │ - is_active         │  │ - folder_type       │                   ║
║   │ - status            │  │                     │                   ║
║   │ - archived_at       │  │                     │                   ║
║   └─────────────────────┘  └─────────────────────┘                   ║
║            │                        │                                ║
║            └────────────────────────┘                                ║
║                                                                      ║
║   ┌─────────────────────┐  ┌─────────────────────┐                   ║
║   │ terminal_name_      │  │    context_docs     │                   ║
║   │ history             │  │                     │                   ║
║   │                     │  │ - id (PK)           │                   ║
║   │ - terminal_id       │  │ - doc_type          │                   ║
║   │ - old_name          │  │ - project_id (FK)   │                   ║
║   │ - new_name          │  │ - file_path         │                   ║
║   │ - renamed_at        │  │ - usage_count       │                   ║
║   └─────────────────────┘  └─────────────────────┘                   ║
║                                                                      ║
║   ┌─────────────────────┐  ┌─────────────────────┐                   ║
║   │    daily_stats      │  │ terminal_heartbeats │                   ║
║   │                     │  │                     │                   ║
║   │ - date (PK)         │  │ - terminal_id (PK)  │                   ║
║   │ - total_operations  │  │ - instance_id       │                   ║
║   │ - read_count        │  │ - last_heartbeat    │                   ║
║   │ - write_count       │  │ - is_alive          │                   ║
║   │ - edit_count        │  │ - cwd               │                   ║
║   └─────────────────────┘  └─────────────────────┘                   ║
║                                                                      ║
║                            onit.db                                   ║
╚═════════════════════════════════════════════════════════════════════╝

Project Lifecycle

How projects flow through different states.
╔═════════════════════════════════════════════════════════════════════╗
║                    PROJECT STATUS LIFECYCLE                          ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   CREATE                                                             ║
║        │                                                             ║
║        │ INSERT (status='active', is_active=1)                       ║
║        ▼                                                             ║
║   ┌───────────────────┐                                              ║
║   │      ACTIVE       │                                              ║
║   │                   │                                              ║
║   │  - Visible in UI  │                                              ║
║   │  - Accepts files  │                                              ║
║   │  - Has terminals  │                                              ║
║   └───────────────────┘                                              ║
║        │                                                             ║
║        │ archive_project()                                           ║
║        │ UPDATE status='archived', is_active=0                       ║
║        ▼                                                             ║
║   ┌───────────────────┐                                              ║
║   │     ARCHIVED      │                                              ║
║   │                   │                                              ║
║   │  - Hidden from UI │                                              ║
║   │  - Data preserved │                                              ║
║   │  - Can restore    │                                              ║
║   └───────────────────┘                                              ║
║        │                                                             ║
║        │ restore_project()                                           ║
║        │ UPDATE status='active', is_active=1                         ║
║        ▼                                                             ║
║   ┌───────────────────┐                                              ║
║   │      ACTIVE       │  (restored)                                  ║
║   └───────────────────┘                                              ║
║                                                                      ║
║   NOTE: Soft delete pattern - no actual DELETE operations            ║
║         Data is always preserved for potential recovery              ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Project Data Flow

╔═════════════════════════════════════════════════════════════════════╗
║                      PROJECT WORKFLOW                                ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   User Creates Project                                               ║
║        │                                                             ║
║        │ invoke("create_project", { name, ... })                     ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  INSERT INTO monolex_projects                                 │  ║
║   │  RETURN inserted project ID                                   │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        │ Project ID returned                                         ║
║        ▼                                                             ║
║   User Adds Folders                                                  ║
║        │                                                             ║
║        │ invoke("add_project_folder", { project_id, path })          ║
║        ▼                                                             ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │  INSERT INTO monolex_project_folders                          │  ║
║   │  Link folder to project                                       │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║        │                                                             ║
║        ▼                                                             ║
║   Project Ready for Use                                              ║
║        │                                                             ║
║        │ Terminal activity auto-associates with project              ║
║        │ Based on current working directory match                    ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Context Documents

Documents attached to projects for AI context.
╔═════════════════════════════════════════════════════════════════════╗
║                     CONTEXT DOC SYSTEM                               ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   DOC TYPES                                                          ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │                                                               │  ║
║   │   GLOBAL                          PROJECT                     │  ║
║   │   - project_id = NULL             - project_id = N            │  ║
║   │   - Available to ALL              - Scoped to ONE             │  ║
║   │     projects                        project                   │  ║
║   │   - Company-wide docs             - Project-specific          │  ║
║   │   - Coding standards              - README, specs             │  ║
║   │                                                               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   USAGE TRACKING                                                     ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │                                                               │  ║
║   │   When you use a context doc:                                 │  ║
║   │                                                               │  ║
║   │   UPDATE context_docs                                         │  ║
║   │   SET usage_count = usage_count + 1,                          │  ║
║   │       last_used = NOW()                                       │  ║
║   │   WHERE id = ?                                                │  ║
║   │                                                               │  ║
║   │   Query frequently used docs:                                 │  ║
║   │   SELECT * FROM context_docs                                  │  ║
║   │   ORDER BY usage_count DESC                                   │  ║
║   │                                                               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   WORKFLOW                                                           ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │                                                               │  ║
║   │   Add Doc                                                     │  ║
║   │        │                                                      │  ║
║   │        │ invoke("add_context_doc", { doc_type, file_path })   │  ║
║   │        ▼                                                      │  ║
║   │   INSERT INTO context_docs                                    │  ║
║   │        │                                                      │  ║
║   │        ▼                                                      │  ║
║   │   Use Doc (in AI prompt)                                      │  ║
║   │        │                                                      │  ║
║   │        │ invoke("increment_context_usage", { id })            │  ║
║   │        ▼                                                      │  ║
║   │   usage_count += 1                                            │  ║
║   │                                                               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Write/Read Operations

╔═════════════════════════════════════════════════════════════════════╗
║                    WRITE/READ OPERATIONS                             ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   WRITE (Frontend invoke())                                          ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │                                                               │  ║
║   │   Function                 │ Table                            │  ║
║   │   ═════════════════════════│══════════════════════════════════│  ║
║   │   create_project           │ monolex_projects                 │  ║
║   │   add_project_folder       │ monolex_project_folders          │  ║
║   │   add_context_doc          │ context_docs                     │  ║
║   │   rename_terminal          │ terminal_name_history            │  ║
║   │   update_daily_stats       │ daily_stats                      │  ║
║   │   save_ai_folder           │ terminal_ai_folder               │  ║
║   │                                                               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   READ (Frontend invoke())                                           ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │                                                               │  ║
║   │   Function                 │ Query                            │  ║
║   │   ═════════════════════════│══════════════════════════════════│  ║
║   │   get_projects             │ SELECT WHERE status='active'     │  ║
║   │   get_project_folders      │ SELECT WHERE project_id=?        │  ║
║   │   get_context_docs         │ SELECT WHERE doc_type=?          │  ║
║   │   get_daily_stats          │ SELECT WHERE date BETWEEN        │  ║
║   │                                                               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Daily Statistics

Track terminal usage patterns.
╔═════════════════════════════════════════════════════════════════════╗
║                      DAILY STATS TABLE                               ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   Column           │ Description                                     ║
║   ═════════════════│═════════════════════════════════════════════════║
║   date             │ Stats date (Primary Key)                        ║
║   total_operations │ Total operations for the day                    ║
║   read_count       │ Number of file reads                            ║
║   write_count      │ Number of file writes                           ║
║   edit_count       │ Number of file edits                            ║
║   bash_count       │ Number of bash commands                         ║
║   other_count      │ Other operations                                ║
║   unique_files     │ Number of unique files touched                  ║
║                                                                      ║
║   USE CASE: Analytics Dashboard                                      ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │                                                               │  ║
║   │   "How productive was I this week?"                           │  ║
║   │                                                               │  ║
║   │   SELECT date, total_operations, unique_files                 │  ║
║   │   FROM daily_stats                                            │  ║
║   │   WHERE date BETWEEN '2025-01-01' AND '2025-01-07'            │  ║
║   │   ORDER BY date                                               │  ║
║   │                                                               │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Design Principles Applied

╔═════════════════════════════════════════════════════════════════════╗
║                      DESIGN PRINCIPLES                               ║
╠═════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║   SIMPLICITY (SMPC)                                                  ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ [x] Projects + Folders + Context in single DB                 │  ║
║   │ [x] Standard CRUD via invoke()                                │  ║
║   │ [x] Soft delete (status='archived') not hard delete           │  ║
║   │ [x] Foreign keys for referential integrity                    │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
║   ORDER FROM CHAOS (OFAC)                                            ║
║   ┌───────────────────────────────────────────────────────────────┐  ║
║   │ [x] daily_stats for usage analytics                           │  ║
║   │ [x] terminal_name_history for rename tracking                 │  ║
║   │ [x] usage_count for context doc prioritization                │  ║
║   │ [x] CASCADE delete for clean project removal                  │  ║
║   └───────────────────────────────────────────────────────────────┘  ║
║                                                                      ║
╚═════════════════════════════════════════════════════════════════════╝

Quick Reference

AspectValue
Location~/Library/Application Support/Monolex/protocols/niia/database/onit.db
Primary OwnerOnIt module
Main Tablesmonolex_projects, context_docs
Write MethodFrontend invoke()
Read ByFrontend project sidebar, context menu