@kelceyp/caw-server 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # CAW Server
2
+
3
+ The CAW server provides REST API, MCP server, WebSocket bridge, and core content management features.
4
+
5
+ ## Overview
6
+
7
+ The server is the central component of CAW, providing:
8
+
9
+ - **REST API** - HTTP endpoints for web client and CLI
10
+ - **MCP Server** - HTTP MCP server for Claude Code integration
11
+ - **WebSocket Bridge** - Real-time communication with browser extension tabs
12
+ - **Core** - Business logic layer (services, stores, entities)
13
+ - **Static File Hosting** - Serves the web client
14
+
15
+ ## Architecture
16
+
17
+ ```
18
+ ┌─────────────────────────────────────────┐
19
+ │ API Layer (REST/MCP) │ HTTP routes, MCP tools
20
+ │ (api/, mcp/) │ Auth via Bearer tokens
21
+ └─────────────────────────────────────────┘
22
+
23
+ ┌─────────────────────────────────────────┐
24
+ │ Server.js │ Express app setup
25
+ │ (main.js) │ Port management
26
+ └─────────────────────────────────────────┘
27
+
28
+ ┌─────────────────────────────────────────┐
29
+ │ Core Facade │ Token resolution
30
+ │ (core/Core.js) │ Service caching
31
+ │ │ Flat API
32
+ └─────────────────────────────────────────┘
33
+
34
+ ┌─────────────────────────────────────────┐
35
+ │ Services Layer │ Orchestration
36
+ │ (core/services/) │ Business workflows
37
+ │ │ Multi-store coordination
38
+ └─────────────────────────────────────────┘
39
+
40
+ ┌─────────────────────────────────────────┐
41
+ │ Stores Layer │ Data access
42
+ │ (core/stores/) │ Identity Map caching
43
+ │ │ CRUD operations
44
+ └─────────────────────────────────────────┘
45
+
46
+ ┌─────────────────────────────────────────┐
47
+ │ Database Layer │ SQLite
48
+ │ (db/) │ Kysely query builder
49
+ └─────────────────────────────────────────┘
50
+ ```
51
+
52
+ ## Directory Structure
53
+
54
+ ```
55
+ server/
56
+ ├── src/
57
+ │ ├── main.js # Entry point, server initialization
58
+ │ ├── Server.js # Express app factory
59
+ │ ├── api/ # REST API routes
60
+ │ │ ├── ProjectRoutes.js
61
+ │ │ ├── FolderRoutes.js
62
+ │ │ ├── DocumentRoutes.js
63
+ │ │ ├── TemplateRoutes.js
64
+ │ │ ├── FieldRoutes.js
65
+ │ │ ├── ExportRoutes.js
66
+ │ │ └── EventRoutes.js
67
+ │ ├── core/ # Business logic layer
68
+ │ │ ├── Core.js # Facade - token resolution, service caching
69
+ │ │ ├── entities/ # Domain objects (read-only)
70
+ │ │ ├── services/ # Orchestration layer
71
+ │ │ └── stores/ # Data access + caching
72
+ │ ├── db/ # Database layer
73
+ │ │ ├── Connection.js # Database connection factory
74
+ │ │ ├── schema.js # Table definitions
75
+ │ │ └── seed.js # Initial data seeding
76
+ │ ├── mcp/ # MCP server implementation
77
+ │ ├── wss/ # WebSocket server
78
+ │ ├── static/ # Static files for web client
79
+ │ └── common/ # Shared utilities
80
+ └── test/ # Test suites
81
+ ├── unit/ # In-memory unit tests
82
+ ├── integration/ # Real database integration tests
83
+ └── component/ # Black-box HTTP tests via subprocess
84
+ ```
85
+
86
+ ## Port Configuration
87
+
88
+ The server uses the `CAW_PORT` environment variable:
89
+
90
+ ```bash
91
+ CAW_PORT=3131 caw-server # Default: 3131
92
+ ```
93
+
94
+ ## Building
95
+
96
+ ```bash
97
+ # Build server only
98
+ bun run build
99
+
100
+ # Build client + server
101
+ bun run build:all
102
+ ```
103
+
104
+ Output: `dist/main.js` (ES6 module for Node.js)
105
+
106
+ ## Running
107
+
108
+ ```bash
109
+ # Development (uses source files)
110
+ bun run dev
111
+
112
+ # Production (uses built files)
113
+ node dist/main.js
114
+ ```
115
+
116
+ ## Testing
117
+
118
+ ```bash
119
+ # Run all tests
120
+ bun test
121
+
122
+ # Run specific test suite
123
+ bun test test/unit/
124
+ bun test test/integration/
125
+ bun test test/component/
126
+ ```
127
+
128
+ Test types:
129
+ - **Unit** - In-memory tests (entities, utilities)
130
+ - **Integration** - Real database tests (stores, services)
131
+ - **Component** - Black-box HTTP tests (API routes, MCP tools)
132
+
133
+ ## Tech Stack
134
+
135
+ - **Pure JavaScript** - ES6 modules, factory functions only
136
+ - **Express** - HTTP server framework
137
+ - **Kysely** - SQL query builder (type-safe)
138
+ - **better-sqlite3** - SQLite driver
139
+ - **ws** - WebSocket server
140
+ - **MCP SDK** - Model Context Protocol implementation
141
+ - **Bun** - Build tool (development and bundling)
142
+
143
+ ## Distribution
144
+
145
+ Published to npm as `@kelceyp/caw-server`:
146
+
147
+ ```bash
148
+ # Global install
149
+ npm install -g @kelceyp/caw-server
150
+
151
+ # Run
152
+ caw-server
153
+ ```
154
+
155
+ ## Key Features
156
+
157
+ ### Token-Based Authentication
158
+
159
+ All API and MCP requests use Bearer tokens:
160
+
161
+ ```bash
162
+ Authorization: Bearer <project-token>
163
+ ```
164
+
165
+ Core facade resolves tokens to project context and caches services per project.
166
+
167
+ ### Multi-Store System
168
+
169
+ Projects use a hierarchical store structure:
170
+ - **DemuxStore** - Routes operations to child stores
171
+ - **LocalStore A** - Project-specific content
172
+ - **LocalStore B** - Shared content across projects
173
+
174
+ ### Identity Map Caching
175
+
176
+ Stores cache entities to ensure single object instance per ID:
177
+ - Cache checked before database queries
178
+ - Mutations update cache after DB commit (via onSuccess callbacks)
179
+ - Referential equality guaranteed
180
+
181
+ ### Field System
182
+
183
+ Entity fields provide metadata storage:
184
+ - In-memory only (not persisted)
185
+ - Store-level defaults
186
+ - Single-valued and multi-valued fields
187
+ - Accessed via FieldService
188
+
189
+ ## Development
190
+
191
+ See individual component READMEs:
192
+ - `/core/README.md` - Core architecture
193
+ - `/core/entities/README.md` - Domain entities
194
+ - `/core/services/README.md` - Service layer
195
+ - `/core/stores/README.md` - Data access layer
196
+ - `/api/README.md` - REST API routes
197
+ - `/db/README.md` - Database layer
198
+ - `/test/README.md` - Testing guide