webspresso 0.0.95 → 0.0.96
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/.agents/ADMIN.md +225 -0
- package/.agents/AGENTS.md +72 -0
- package/.agents/ARCHITECTURE.md +119 -0
- package/.agents/AUTH.md +103 -0
- package/.agents/CLI.md +115 -0
- package/.agents/COMPRESSION.md +59 -0
- package/.agents/CONVENTIONS.md +46 -0
- package/.agents/EMAIL.md +141 -0
- package/.agents/ERRORS.md +201 -0
- package/.agents/MCP.md +103 -0
- package/.agents/ORM.md +230 -0
- package/.agents/PLUGINS.md +419 -0
- package/.agents/QUEUE.md +113 -0
- package/.agents/REALTIME.md +213 -0
- package/.agents/ROUTING.md +292 -0
- package/.agents/SERVICES.md +341 -0
- package/.agents/SHUTDOWN.md +67 -0
- package/.agents/STREAMING.md +73 -0
- package/.agents/WORKFLOW.md +27 -0
- package/.agents/internal/DOCUMENTATION_REVIEW.md +485 -0
- package/.agents/internal/TECHNICAL_REVIEW.md +428 -0
- package/.cursorrules +14 -0
- package/AGENTS.md +175 -0
- package/CLAUDE.md +54 -0
- package/README.md +18 -14
- package/bin/commands/agents-init.js +169 -0
- package/bin/commands/api.js +114 -48
- package/bin/commands/doctor.js +35 -0
- package/bin/commands/new.js +13 -2
- package/bin/commands/page.js +75 -89
- package/bin/commands/service.js +77 -0
- package/bin/webspresso.js +2 -2
- package/core/compileSchema.js +1 -1
- package/core/errors/middleware.js +22 -2
- package/core/errors/normalize.js +29 -2
- package/{utils/schemaCache.js → core/schema-cache.js} +2 -3
- package/index.d.ts +306 -0
- package/index.js +35 -1
- package/package.json +5 -3
- package/plugins/admin-panel/client/parts/05-rich-text-file-helpers.js +22 -1
- package/plugins/csrf/index.js +3 -2
- package/plugins/csv/engine.js +447 -0
- package/plugins/csv/index.js +94 -0
- package/plugins/csv/middleware.js +80 -0
- package/plugins/csv/services.js +138 -0
- package/plugins/file-manager/admin-component.js +613 -0
- package/plugins/file-manager/api-handlers.js +261 -0
- package/plugins/file-manager/core.js +601 -0
- package/plugins/file-manager/index.js +139 -0
- package/plugins/file-manager/security.js +207 -0
- package/plugins/index.js +8 -0
- package/plugins/xlsx/engine.js +397 -0
- package/plugins/xlsx/index.js +91 -0
- package/plugins/xlsx/middleware.js +87 -0
- package/plugins/xlsx/services.js +118 -0
- package/src/api/api-loader.js +233 -0
- package/src/api/define-api.js +35 -0
- package/src/discovery/file-route-parser.js +201 -0
- package/src/discovery/scan-routes.js +265 -0
- package/src/file-router.js +6 -0
- package/src/modules/define-module.js +99 -0
- package/src/modules/module-discovery.js +117 -0
- package/src/pages/define-page.js +36 -0
- package/src/pages/page-loader.js +214 -0
- package/src/routing/mount-discovered-routes.js +78 -0
- package/src/routing/route-table.js +191 -0
- package/src/server.js +112 -15
- package/src/services/builtins/file-manager.js +178 -0
- package/src/services/index.js +2 -0
- package/bin/commands/skill.js +0 -187
- package/templates/skills/webspresso-usage/REFERENCE-framework.md +0 -289
- package/templates/skills/webspresso-usage/REFERENCE-kernel.md +0 -93
- package/templates/skills/webspresso-usage/SKILL.md +0 -48
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
# Webspresso — Documentation Audit & Restructuring Strategy Report
|
|
2
|
+
|
|
3
|
+
> **Date:** 2026-08-28
|
|
4
|
+
> **Scope:** Webspresso Framework Documentation Inventory, Code Alignment Verification, Information Architecture (IA), and Incremental Migration Roadmap
|
|
5
|
+
> **Status:** Completed / Actionable
|
|
6
|
+
> **Objective:** Restructure documentation to be sustainable, accurate, modular, and seamless to navigate for both human engineers and AI coding assistants.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. Executive Summary
|
|
11
|
+
|
|
12
|
+
Webspresso is a lightweight, zero-dependency-sprawl Express 5 SSR framework featuring file-based routing, Nunjucks templating, an intuitive Knex-based ORM with ambient transactions, a modular plugin ecosystem, and a customizable Mithril.js SPA Admin Panel.
|
|
13
|
+
|
|
14
|
+
An audit of the current documentation reveals:
|
|
15
|
+
1. **Monolithic Documentation Bloat**: `README.md` (103.6 KB, 2,917 lines) and `doc/index.html` (160 KB monolithic HTML) consolidate getting started guides, architecture deep dives, CLI command manuals, and all 15 plugin API references into single giant files. This degrades navigation speed, first impressions, and AI context window efficiency.
|
|
16
|
+
2. **Broken & Outdated References**: `README.md` and `doc/index.html` link to non-existent directories such as `examples/alpine-swup-demo/` (`DOCS_OUTDATED`).
|
|
17
|
+
3. **Layer Confusion**: "How do I do X?" (Guide), "How does it work and why?" (Concept), and "What is the complete API contract?" (Reference) are intertwined under monolithic headings.
|
|
18
|
+
4. **High Quality Agent Documentation**: The 17 topic guides under `.agents/` are accurate, modular, and provide an excellent blueprint for public developer documentation under `docs/`.
|
|
19
|
+
|
|
20
|
+
This report establishes a phased restructuring methodology:
|
|
21
|
+
**`audit → verify → classify → restructure → simplify → validate`**
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 2. Current Documentation Inventory
|
|
26
|
+
|
|
27
|
+
The repository documentation landscape is categorized below:
|
|
28
|
+
|
|
29
|
+
| Source / Path | Size / Lines | Category | Current Role & Status |
|
|
30
|
+
| :--- | :--- | :--- | :--- |
|
|
31
|
+
| **`README.md`** | 103.6 KB (2,917 lines) | Mixed (Monolith) | Deep monolith containing quickstart, CLI, ORM, services, plugins, hooks, and API references. **REWRITE & SLIM DOWN**. |
|
|
32
|
+
| **`doc/index.html`** | 160.1 KB (1,400+ lines) | Reference / Guide | Single-page static HTML documentation with embedded Tailwind styles and code snippets. **MOVE TO MD & SPLIT**. |
|
|
33
|
+
| **`docs/ARCHITECTURE.md`** | 17.4 KB (364 lines) | Architecture | C4-style architectural overview of system context, containers, and component map. **KEEP & EXPAND**. |
|
|
34
|
+
| **`TECHNICAL_REVIEW.md`** | 42.0 KB (645 lines) | Internal / Architecture | Comprehensive codebase health check, technical debt register, and cleanup roadmap. **KEEP (Internal)**. |
|
|
35
|
+
| **`SECURITY.md`** | 7.3 KB (200 lines) | Reference / Security | Security policy, vulnerability reporting protocol, and threat model. **KEEP**. |
|
|
36
|
+
| **`CHANGELOG.md`** | 37.4 KB | Reference / Release | Chronological release history and version logs. **KEEP**. |
|
|
37
|
+
| **`AGENTS.md` (Root)** | 8.2 KB (84 lines) | Agent Documentation | Core architectural rules, zero regression policy, and guide index for AI agents. **KEEP**. |
|
|
38
|
+
| **`.agents/*.md` (17 Files)** | ~82 KB (17 topics) | Agent Documentation | In-depth topic guides for admin, ORM, auth, services, streaming, shutdown, and plugins. **KEEP**. |
|
|
39
|
+
| **`index.d.ts`** | 53.8 KB (1,445 lines) | Reference / Types | TypeScript definitions and inline JSDoc comments. Canonical API contract. **KEEP**. |
|
|
40
|
+
| **CLI Help (`bin/`)** | Inline code | Reference / CLI | Commander command-line help strings (`webspresso --help`). **KEEP (Source of Truth)**. |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 3. Documentation vs Implementation Findings
|
|
45
|
+
|
|
46
|
+
Audit comparing documentation claims against the authoritative source code (`src/`, `core/`, `plugins/`):
|
|
47
|
+
|
|
48
|
+
| Feature / Subsystem | Docs Status | Code Alignment | Detailed Findings & Discrepancies |
|
|
49
|
+
| :--- | :--- | :--- | :--- |
|
|
50
|
+
| **`createApp()` Options** | `DOCS_OUTDATED` | Partially Aligned | `README.md` and `doc/index.html` omit recent additions (`pageAssets`, `trustProxy`, `server.shutdown`, `server.compression`) or present legacy formats. `index.d.ts` is fully up-to-date. |
|
|
51
|
+
| **Client Runtime & Demos** | `DOCS_OUTDATED` | Non-Existent | `examples/alpine-swup-demo/` is referenced as a live demo, but the `examples/` directory does not exist in the repository. |
|
|
52
|
+
| **Routing & SSR Loaders** | `DOCS_CORRECT` | Fully Aligned | `pages/[id].njk`, `pages/[...rest].njk`, `async function load({ req, res, db, ctx })`, and `_hooks.js` match runtime behavior exactly. |
|
|
53
|
+
| **Services Layer** | `DOCS_CORRECT` | Fully Aligned | `services/` auto-discovery, dot-notation names, camelCase aliases, predicate auth, Zod validation, `transaction: true`, and `ctx.service()` are verified. |
|
|
54
|
+
| **Validation Core** | `DOCS_OUTDATED` | Resolved | Previous documentation missed the unification of API schema compilation and service validation under `core/validation`. Now resolved. |
|
|
55
|
+
| **Dual Authentication** | `DOCS_CORRECT` | Fully Aligned | Session + Cookie and stateless HS256 JWT (`core/auth`), policy guards, and route middleware integration match code. |
|
|
56
|
+
| **Graceful Shutdown** | `DOCS_CORRECT` | Fully Aligned | `server.shutdown: { enabled, mode: 'graceful'|'force', timeout }`, socket tracking, HTTP 503 draining, and reverse-order plugin disposers match code. |
|
|
57
|
+
| **ORM & Ambient Transactions** | `DOCS_CORRECT` | Fully Aligned | `defineModel`, `zdb`, Repositories API, `AsyncLocalStorage` ambient transactions (`core/orm/transaction.js`), and soft-delete/tenant scopes match code. |
|
|
58
|
+
| **`core/kernel`** | `DOCS_AMBIGUOUS` | Resolved | Previous docs blurred `kernel.createApp()` and SSR `createApp()`. Now clearly designated as an experimental/standalone event subsystem. |
|
|
59
|
+
| **15 Built-in Plugins** | `DOCS_INCOMPLETE` | Partially Missing | Newly added plugins (`realtimePlugin`, `basicAuthPlugin`, `dataExchangePlugin`) have scattered or incomplete option tables in README. |
|
|
60
|
+
| **Exceptions & Errors** | `DOCS_CORRECT` | Fully Aligned | `WebspressoError`, `ValidationError`, `SecurityError`, `HttpError`, `app.setErrorHandler` hierarchy verified against `core/errors`. |
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 4. Current Problems & Pain Points
|
|
65
|
+
|
|
66
|
+
1. **Monolithic README Bloat**:
|
|
67
|
+
- At 103.6 KB, `README.md` is too large for GitHub rendering, makes finding specific information difficult, and overwhelms new users.
|
|
68
|
+
2. **Layer Mixing (Guide / Concept / Reference)**:
|
|
69
|
+
- Topics mix introductory walkthroughs (Guides), internal event bus / transaction mechanics (Concepts), and full parameter matrices (Reference) under the same sections.
|
|
70
|
+
3. **Information Duplication (Copy-Paste Sync Debt)**:
|
|
71
|
+
- Substantial text blocks are copied between `README.md`, `doc/index.html`, and `.agents/`. Updating one option requires editing three separate locations.
|
|
72
|
+
4. **Maintenance Overhead of Static HTML (`doc/index.html`)**:
|
|
73
|
+
- `doc/index.html` is a monolithic 160 KB raw HTML file that cannot easily be cross-referenced or validated with modern markdown tooling.
|
|
74
|
+
5. **Missing `llms.txt`**:
|
|
75
|
+
- No standardized `llms.txt` file exists to index framework documentation for LLMs and autonomous coding tools.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 5. Proposed Information Architecture
|
|
80
|
+
|
|
81
|
+
Public documentation will be organized into five standard pillars under `docs/`:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
docs/
|
|
85
|
+
├── getting-started/ # "Get Started Fast" (0 -> 1 Walkthroughs)
|
|
86
|
+
│ ├── installation.md
|
|
87
|
+
│ ├── first-app.md
|
|
88
|
+
│ ├── project-structure.md
|
|
89
|
+
│ └── deployment.md
|
|
90
|
+
│
|
|
91
|
+
├── guides/ # "How do I do X?" (Task & Problem Oriented)
|
|
92
|
+
│ ├── routing.md
|
|
93
|
+
│ ├── ssr-and-templates.md
|
|
94
|
+
│ ├── services.md
|
|
95
|
+
│ ├── database-and-orm.md
|
|
96
|
+
│ ├── authentication.md
|
|
97
|
+
│ ├── api-routes.md
|
|
98
|
+
│ ├── admin-panel.md
|
|
99
|
+
│ ├── plugins.md
|
|
100
|
+
│ ├── realtime.md
|
|
101
|
+
│ ├── file-uploads.md
|
|
102
|
+
│ └── email.md
|
|
103
|
+
│
|
|
104
|
+
├── concepts/ # "How does it work and why?" (Mental Models & Deep Dives)
|
|
105
|
+
│ ├── architecture.md
|
|
106
|
+
│ ├── request-lifecycle.md
|
|
107
|
+
│ ├── service-execution-pipeline.md
|
|
108
|
+
│ ├── transaction-propagation.md
|
|
109
|
+
│ ├── plugin-system.md
|
|
110
|
+
│ ├── error-boundary.md
|
|
111
|
+
│ ├── shutdown-and-lifecycle.md
|
|
112
|
+
│ └── asset-pipeline.md
|
|
113
|
+
│
|
|
114
|
+
├── reference/ # "What is the exact API contract?" (Unbiased Spec & Options)
|
|
115
|
+
│ ├── create-app.md
|
|
116
|
+
│ ├── cli.md
|
|
117
|
+
│ ├── request-response.md
|
|
118
|
+
│ ├── service-definition.md
|
|
119
|
+
│ ├── model-definition.md
|
|
120
|
+
│ ├── plugins-api.md
|
|
121
|
+
│ ├── template-helpers.md
|
|
122
|
+
│ └── exceptions.md
|
|
123
|
+
│
|
|
124
|
+
└── examples/ # "Tested, Runnable Projects"
|
|
125
|
+
├── basic-ssr/
|
|
126
|
+
├── rest-and-services/
|
|
127
|
+
├── auth-session-jwt/
|
|
128
|
+
└── admin-custom-pages/
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 6. README Restructuring Plan
|
|
134
|
+
|
|
135
|
+
`README.md` will be slimmed down from **103.6 KB to ~8–12 KB**, delegating exhaustive reference material to `docs/`.
|
|
136
|
+
|
|
137
|
+
### Restructured README Outline:
|
|
138
|
+
1. **Header & Badges**: Package name, description ("Minimal, Zero-Sprawl Express SSR Framework"), npm and license badges.
|
|
139
|
+
2. **Why Webspresso? (Value Proposition)**:
|
|
140
|
+
- Zero-dependency sprawl (native Node.js modules for Auth, JWT, Errors, Compression, Shutdown).
|
|
141
|
+
- File-based Nunjucks SSR + API routing.
|
|
142
|
+
- Knex-based ORM with ambient `AsyncLocalStorage` transaction propagation.
|
|
143
|
+
- Built-in Mithril.js SPA Admin Panel and modular Plugin Ecosystem.
|
|
144
|
+
3. **Quick Start (3-Minute Setup)**:
|
|
145
|
+
```bash
|
|
146
|
+
npx webspresso new my-app --install
|
|
147
|
+
cd my-app
|
|
148
|
+
npm run dev
|
|
149
|
+
```
|
|
150
|
+
4. **Minimal Code Walkthrough (`pages/index.njk` & `services/hello.js`)**.
|
|
151
|
+
5. **Key Feature Highlights** with direct links to `docs/`.
|
|
152
|
+
6. **Documentation Sitemap**:
|
|
153
|
+
- [Getting Started](docs/getting-started/installation.md)
|
|
154
|
+
- [Guides](docs/guides/routing.md)
|
|
155
|
+
- [Concepts & Architecture](docs/concepts/architecture.md)
|
|
156
|
+
- [API Reference](docs/reference/create-app.md)
|
|
157
|
+
7. **License & Community**.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 7. Getting Started Plan
|
|
162
|
+
|
|
163
|
+
Designed to take a new developer from installation to a running, styled, database-connected application within 5 minutes:
|
|
164
|
+
|
|
165
|
+
- **`installation.md`**: System requirements (Node.js 20 LTS), package manager instructions (npm/pnpm/yarn), global CLI vs npx.
|
|
166
|
+
- **`first-app.md`**: Scaffolding with `webspresso new`, creating the first SSR page (`pages/index.njk`), adding an API route (`pages/api/hello.get.js`), and launching the dev server.
|
|
167
|
+
- **`project-structure.md`**: Standard anatomy (`pages/`, `views/`, `services/`, `models/`, `config/`, `public/`).
|
|
168
|
+
- **`deployment.md`**: Production build (`NODE_ENV=production`), process managers (PM2, Docker, systemd), graceful shutdown, and reverse proxy configuration (Nginx / Cloudflare).
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 8. Guides Plan (Task-Oriented)
|
|
173
|
+
|
|
174
|
+
Each guide addresses a specific developer goal ("How do I do X?"):
|
|
175
|
+
|
|
176
|
+
1. **`routing.md`**: Static routes, dynamic params (`[id]`), catch-all (`[...slug]`), and per-page asset bundles (`pageAssets`).
|
|
177
|
+
2. **`ssr-and-templates.md`**: Server-side data fetching via `load()`, Nunjucks layouts, `fsy` helper catalog, and chunked streaming (`res.renderStream`).
|
|
178
|
+
3. **`services.md`**: Defining services (`defineService`), Zod input validation, RBAC/Auth predicates, and automatic ACID transactions.
|
|
179
|
+
4. **`database-and-orm.md`**: Defining models (`defineModel`), `zdb` schema builder, Repositories API (`find`, `create`, `query`), and Knex migrations.
|
|
180
|
+
5. **`authentication.md`**: Dual Auth implementation, Session login/logout, stateless JWT & Refresh Token rotation, and route protection guards.
|
|
181
|
+
6. **`api-routes.md`**: HTTP-method-suffixed file handlers (`.get.js`, `.post.js`), `req.input` validation, and JSON responses.
|
|
182
|
+
7. **`admin-panel.md`**: Admin SPA module registration, custom Mithril pages (`component.js`), field renderers, and custom dashboard widgets.
|
|
183
|
+
8. **`plugins.md`**: Registering plugins (`createApp({ plugins })`), creating custom plugins, and lifecycle hooks (`register`, `onRoutesReady`).
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 9. Concepts Plan (Mental Models & Deep Dives)
|
|
188
|
+
|
|
189
|
+
In-depth explanations of framework mechanics and architectural decisions:
|
|
190
|
+
|
|
191
|
+
- **`architecture.md`**: Layered architecture, system boundaries, and design principles.
|
|
192
|
+
- **`request-lifecycle.md`**: Step-by-step path from incoming HTTP socket to template render and response stream.
|
|
193
|
+
- **`service-execution-pipeline.md`**: Input sanitization → Zod schema compilation → Auth guards → Ambient transaction wrapping → Memoization/Cache → Execution → Result.
|
|
194
|
+
- **`transaction-propagation.md`**: How Node.js `AsyncLocalStorage` propagates active Knex transactions across nested services and repositories without manual parameter passing.
|
|
195
|
+
- **`error-boundary.md`**: Central error handler, Django-inspired exception hierarchy, and production error detail masking.
|
|
196
|
+
- **`shutdown-and-lifecycle.md`**: Connection tracking, keep-alive draining, HTTP 503 handling, and reverse-order plugin disposers.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 10. Reference Plan (API Specifications)
|
|
201
|
+
|
|
202
|
+
Exhaustive, unbiased API reference verified against `index.d.ts`:
|
|
203
|
+
|
|
204
|
+
- **`create-app.md`**: All `CreateAppOptions` parameters (`pagesDir`, `viewsDir`, `db`, `auth`, `server`, `pageAssets`, `trustProxy`, `clientRuntime`, `plugins`, `errorPages`).
|
|
205
|
+
- **`cli.md`**: Complete CLI manual (`webspresso new`, `dev`, `start`, `doctor`, `db:migrate`, `db:seed`, `favicon:generate`, `add tailwind`, `admin:password`).
|
|
206
|
+
- **`service-definition.md`**: `defineService` parameters (`schema`, `auth`, `timeout`, `transaction`, `cache`, `handler`) and `ServiceContext` properties.
|
|
207
|
+
- **`model-definition.md`**: `defineModel` options, `zdb` column types, and `Repository` methods (`find`, `findById`, `findOne`, `create`, `update`, `delete`, `query`, `paginate`).
|
|
208
|
+
- **`plugins-api.md`**: Options matrix for all 15 built-in plugins and `PluginContext` API.
|
|
209
|
+
- **`exceptions.md`**: Full exception class hierarchy (`WebspressoError`, `ValidationError`, `SecurityError`, `HttpError`, `ConfigurationError`, `PluginError`, `RouteNotFoundError`).
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 11. Examples Plan
|
|
214
|
+
|
|
215
|
+
Populate `examples/` with runnable, tested standalone projects:
|
|
216
|
+
|
|
217
|
+
1. **`examples/basic-ssr`**: Minimal Nunjucks SSR + SQLite setup.
|
|
218
|
+
2. **`examples/rest-and-services`**: REST API endpoints, Zod schema validation, and services layer.
|
|
219
|
+
3. **`examples/auth-session-jwt`**: Dual auth demonstration (Session cookies for SSR + JWT for REST API).
|
|
220
|
+
4. **`examples/admin-custom-pages`**: Admin Panel SPA with custom Mithril.js components and widgets.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 12. Architecture & Lifecycle Documentation
|
|
225
|
+
|
|
226
|
+
### 12.1 System Layer Architecture
|
|
227
|
+
|
|
228
|
+
```mermaid
|
|
229
|
+
graph TD
|
|
230
|
+
Client["Client / Browser"] --> HTTP["HTTP Layer (Express 5 Engine)"]
|
|
231
|
+
HTTP --> Shutdown["Shutdown & RateLimit Boundary"]
|
|
232
|
+
Shutdown --> ContextMW["Request Context Container (req.context)"]
|
|
233
|
+
ContextMW --> Auth["Dual Auth (Session / JWT Middleware)"]
|
|
234
|
+
Auth --> Router["File Router (pages/ & pages/api/)"]
|
|
235
|
+
|
|
236
|
+
Router -->|SSR Page| SSR["SSR Pipeline (Nunjucks + Layouts + fsy)"]
|
|
237
|
+
Router -->|API Route| API["API Validation (Zod req.input)"]
|
|
238
|
+
|
|
239
|
+
SSR --> Services["Services Layer (src/services)"]
|
|
240
|
+
API --> Services
|
|
241
|
+
|
|
242
|
+
Services --> SVal["Input Sanitization & Validation"]
|
|
243
|
+
SVal --> SAuth["Auth & Role Guards"]
|
|
244
|
+
SAuth --> STrx["Ambient Transaction (AsyncLocalStorage)"]
|
|
245
|
+
STrx --> SCache["Service Cache Layer"]
|
|
246
|
+
SCache --> SHandler["Service Handler Execution"]
|
|
247
|
+
|
|
248
|
+
SHandler --> ORM["ORM & Repositories (core/orm)"]
|
|
249
|
+
ORM --> Cache["ORM Query Cache"]
|
|
250
|
+
Cache --> Knex["Knex Query Builder"]
|
|
251
|
+
Knex --> DB[("SQL Database (SQLite / Postgres / MySQL)")]
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### 12.2 Request Lifecycle
|
|
255
|
+
|
|
256
|
+
```mermaid
|
|
257
|
+
sequenceDiagram
|
|
258
|
+
autonumber
|
|
259
|
+
actor User as Client
|
|
260
|
+
participant Express as Express / Server
|
|
261
|
+
participant Hooks as Global & Route Hooks
|
|
262
|
+
participant Mw as Middlewares
|
|
263
|
+
participant Router as File Router
|
|
264
|
+
participant Loader as load() Loader
|
|
265
|
+
participant Engine as Nunjucks Engine
|
|
266
|
+
|
|
267
|
+
User->>Express: HTTP GET /products/123
|
|
268
|
+
Express->>Express: Init req.context & req.service
|
|
269
|
+
Express->>Hooks: executeHook('onRequest', ctx)
|
|
270
|
+
Express->>Hooks: executeHook('onRoute', ctx)
|
|
271
|
+
Express->>Hooks: executeHook('beforeMiddleware', ctx)
|
|
272
|
+
Express->>Mw: Execute Route Middlewares
|
|
273
|
+
Express->>Router: Match pages/products/[id].njk
|
|
274
|
+
Router->>Loader: Call load({ req, res, db, ctx })
|
|
275
|
+
Loader-->>Router: Return data { product, title }
|
|
276
|
+
Router->>Hooks: executeHook('beforeRender', ctx)
|
|
277
|
+
Router->>Engine: Render template with data & fsy helpers
|
|
278
|
+
Engine-->>Express: Compiled HTML output
|
|
279
|
+
Express->>Hooks: executeHook('afterRender', ctx)
|
|
280
|
+
Express-->>User: 200 OK (HTML Stream / Compressed)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 12.3 Service Execution Lifecycle
|
|
284
|
+
|
|
285
|
+
```mermaid
|
|
286
|
+
sequenceDiagram
|
|
287
|
+
autonumber
|
|
288
|
+
actor Caller as Route / SSR Loader
|
|
289
|
+
participant Registry as ServiceRegistry
|
|
290
|
+
participant Val as Validation (core/validation)
|
|
291
|
+
participant Auth as Auth Guard
|
|
292
|
+
participant ALS as Ambient Trx (AsyncLocalStorage)
|
|
293
|
+
participant Cache as Service Cache
|
|
294
|
+
participant Handler as Service Handler
|
|
295
|
+
|
|
296
|
+
Caller->>Registry: call('order.create', input, ctx)
|
|
297
|
+
Registry->>Val: sanitizeInput(input) & validate(schema)
|
|
298
|
+
Val-->>Registry: Validated & Sanitized Data
|
|
299
|
+
Registry->>Auth: checkServiceAuth(def.auth, ctx)
|
|
300
|
+
Auth-->>Registry: Authorization OK
|
|
301
|
+
alt Cache Enabled & Hit
|
|
302
|
+
Registry->>Cache: checkCache(key)
|
|
303
|
+
Cache-->>Caller: Return Cached Result
|
|
304
|
+
else Cache Miss / Execution
|
|
305
|
+
alt transaction: true
|
|
306
|
+
Registry->>ALS: runWithAmbientTransaction(trx, fn)
|
|
307
|
+
ALS->>Handler: execute handler(input, ctx)
|
|
308
|
+
Handler-->>ALS: Result
|
|
309
|
+
ALS-->>Registry: Committed Result
|
|
310
|
+
else Standard Execution
|
|
311
|
+
Registry->>Handler: execute handler(input, ctx)
|
|
312
|
+
Handler-->>Registry: Result
|
|
313
|
+
end
|
|
314
|
+
Registry->>Cache: setCache(key, result, ttl)
|
|
315
|
+
Registry-->>Caller: Return Result
|
|
316
|
+
end
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## 13. Single Source of Truth Opportunities
|
|
322
|
+
|
|
323
|
+
Key areas where documentation should directly reflect code metadata:
|
|
324
|
+
|
|
325
|
+
1. **CLI Commands Reference**: `bin/commands/*.js` Commander definitions generate `docs/reference/cli.md`.
|
|
326
|
+
2. **TypeScript Declarations**: `index.d.ts` types (`CreateAppOptions`, `ModelDefinition`, `ServiceDefinition`, `Repository`) serve as the source of truth for API reference documents.
|
|
327
|
+
3. **Environment Schema**: `config/env.schema.js` validates environment variables and defines `docs/reference/configuration.md`.
|
|
328
|
+
4. **Exception Catalog**: `core/errors/index.js` defines all classes and status codes for `docs/reference/exceptions.md`.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## 14. Documentation Validation Strategy
|
|
333
|
+
|
|
334
|
+
Lightweight automated checks to prevent documentation rot:
|
|
335
|
+
|
|
336
|
+
1. **Markdown Link Checker**: Validate internal cross-links and anchors (`npm run docs:lint-links`).
|
|
337
|
+
2. **TypeScript Smoke Test**: Ensure declarations stay synced via `npm run check:types`.
|
|
338
|
+
3. **Code Snippet Verification**: Vitest unit tests asserting that example snippets in documentation execute cleanly (`tests/docs/snippets.test.js`).
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## 15. AI & Agent Documentation (`AGENTS.md` & `llms.txt`)
|
|
343
|
+
|
|
344
|
+
Distinct strategies for human engineers vs autonomous agents:
|
|
345
|
+
|
|
346
|
+
- **`AGENTS.md` (Root)**: Compact architectural rules, zero regression policies, critical signatures, and danger zones.
|
|
347
|
+
- **`.agents/*.md`**: 17 modular topic guides optimized for agent lookup.
|
|
348
|
+
- **`llms.txt`**: Standardized, compact index mapping framework features to canonical documentation paths under `docs/`.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 16. Legacy, Duplicate & Unclear Documentation Disposition
|
|
353
|
+
|
|
354
|
+
| Document | Current State | Action | Target / Resolution |
|
|
355
|
+
| :--- | :--- | :--- | :--- |
|
|
356
|
+
| `README.md` | 103.6 KB monolith | **REWRITE & SLIM DOWN** | Retain core value proposition & quickstart; move deep references to `docs/` (~10 KB target). |
|
|
357
|
+
| `doc/index.html` | 160 KB raw HTML | **DEPRECATE & MIGRATE** | Migrate all content to modular markdown files in `docs/`; provide redirect/pointer. |
|
|
358
|
+
| `docs/ARCHITECTURE.md` | C4 architecture | **MERGE & MOVE** | Migrate into `docs/concepts/architecture.md` and enrich with Mermaid diagrams. |
|
|
359
|
+
| `examples/alpine-swup-demo/` | Broken reference | **REMOVE REFERENCE & REBUILD** | Remove broken links; build real, tested example projects under `examples/`. |
|
|
360
|
+
| `.agents/*.md` | 17 modular guides | **KEEP & SYNC** | Maintain synchronization with public `docs/`. |
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## 17. Incremental Migration Roadmap
|
|
365
|
+
|
|
366
|
+
```text
|
|
367
|
+
[Phase 0: Inventory & Audit] ────► [Phase 1: Docs Structure Setup (docs/)]
|
|
368
|
+
│
|
|
369
|
+
▼
|
|
370
|
+
[Phase 3: Concepts & Arch] ◄──── [Phase 2: README & Getting Started]
|
|
371
|
+
│
|
|
372
|
+
▼
|
|
373
|
+
[Phase 4: Task Guides] ────► [Phase 5: API Reference Migration]
|
|
374
|
+
│
|
|
375
|
+
▼
|
|
376
|
+
[Phase 7: Validation & CI] ◄──── [Phase 6: Working Examples Suite]
|
|
377
|
+
│
|
|
378
|
+
▼
|
|
379
|
+
[Phase 8: Agent Docs & llms.txt]
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Phase Breakdown:
|
|
383
|
+
- **Phase 0 – Inventory & Audit** (✅ Completed with this report).
|
|
384
|
+
- **Phase 1 – Documentation Directory Structure Setup**: Create `docs/getting-started/`, `docs/guides/`, `docs/concepts/`, `docs/reference/`, `docs/examples/`, and `docs/README.md` index.
|
|
385
|
+
- **Phase 2 – README Simplification & Getting Started**: Slim down `README.md` and author `docs/getting-started/` guides.
|
|
386
|
+
- **Phase 3 – Concepts & Architecture Migration**: Create `docs/concepts/architecture.md`, `request-lifecycle.md`, and `service-execution-pipeline.md`.
|
|
387
|
+
- **Phase 4 – Task-Oriented Guides**: Author focused guides under `docs/guides/` (routing, ssr, services, database, auth, admin).
|
|
388
|
+
- **Phase 5 – Unbiased API Reference**: Complete `docs/reference/` specs (`create-app.md`, `cli.md`, `model-definition.md`, `service-definition.md`).
|
|
389
|
+
- **Phase 6 – Verified Examples Suite**: Create runnable starter templates under `examples/`.
|
|
390
|
+
- **Phase 7 – Documentation Validation**: Add link checking and snippet testing scripts.
|
|
391
|
+
- **Phase 8 – Agent Documentation & `llms.txt`**: Generate `llms.txt` and synchronize `.agents/`.
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## 18. Task Backlog
|
|
396
|
+
|
|
397
|
+
```text
|
|
398
|
+
ID: DOC-P1-01 [COMPLETED]
|
|
399
|
+
Title: Scaffold docs/ folder structure and navigation index
|
|
400
|
+
Priority: HIGH
|
|
401
|
+
Status: COMPLETED (Created docs/README.md and docs/getting-started/ guides)
|
|
402
|
+
Risk: ZERO
|
|
403
|
+
Affected areas: docs/, docs/README.md, docs/getting-started/
|
|
404
|
+
Dependencies: None
|
|
405
|
+
|
|
406
|
+
ID: DOC-P2-01 [COMPLETED]
|
|
407
|
+
Title: Slim down README.md and link to docs/getting-started/
|
|
408
|
+
Priority: HIGH
|
|
409
|
+
Status: COMPLETED (Reduced README from 103.6 KB to 6.2 KB, linking directly to docs/ pillars)
|
|
410
|
+
Risk: LOW
|
|
411
|
+
Affected areas: README.md, docs/getting-started/
|
|
412
|
+
Dependencies: DOC-P1-01
|
|
413
|
+
|
|
414
|
+
ID: DOC-P3-01 [COMPLETED]
|
|
415
|
+
Title: Create core Concepts and Architecture diagrams in docs/concepts/
|
|
416
|
+
Priority: MEDIUM
|
|
417
|
+
Status: COMPLETED (Authored architecture.md, request-lifecycle.md, service-execution-pipeline.md, transaction-propagation.md)
|
|
418
|
+
Risk: LOW
|
|
419
|
+
Affected areas: docs/concepts/
|
|
420
|
+
Dependencies: DOC-P1-01
|
|
421
|
+
|
|
422
|
+
ID: DOC-P4-01 [COMPLETED]
|
|
423
|
+
Title: Migrate and expand task-oriented Guides in docs/guides/
|
|
424
|
+
Priority: MEDIUM
|
|
425
|
+
Status: COMPLETED (Authored routing.md, ssr-and-templates.md, services.md, database-and-orm.md, authentication.md, admin-panel.md)
|
|
426
|
+
Risk: LOW
|
|
427
|
+
Affected areas: docs/guides/
|
|
428
|
+
Dependencies: DOC-P1-01
|
|
429
|
+
|
|
430
|
+
ID: DOC-P5-01 [COMPLETED]
|
|
431
|
+
Title: Complete unbiased API Reference in docs/reference/
|
|
432
|
+
Priority: HIGH
|
|
433
|
+
Status: COMPLETED (Authored create-app.md, cli.md, service-definition.md, model-definition.md, exceptions.md)
|
|
434
|
+
Risk: LOW
|
|
435
|
+
Affected areas: docs/reference/
|
|
436
|
+
Dependencies: DOC-P1-01
|
|
437
|
+
|
|
438
|
+
ID: DOC-P6-01 [COMPLETED]
|
|
439
|
+
Title: Remove broken example references and create examples/basic-ssr
|
|
440
|
+
Priority: MEDIUM
|
|
441
|
+
Status: COMPLETED (Scaffolded examples/basic-ssr with verified tests/unit/examples-smoke.test.js)
|
|
442
|
+
Risk: LOW
|
|
443
|
+
Affected areas: examples/, README.md, tests/unit/examples-smoke.test.js
|
|
444
|
+
Dependencies: DOC-P2-01
|
|
445
|
+
|
|
446
|
+
ID: DOC-P8-01 [COMPLETED]
|
|
447
|
+
Title: Create llms.txt standard documentation index
|
|
448
|
+
Priority: MEDIUM
|
|
449
|
+
Status: COMPLETED (Created root llms.txt mapping docs and agent guides)
|
|
450
|
+
Risk: ZERO
|
|
451
|
+
Affected areas: llms.txt
|
|
452
|
+
Dependencies: DOC-P1-01
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
## 19. Risks & Mitigation
|
|
458
|
+
|
|
459
|
+
| Risk | Probability | Impact | Mitigation Strategy |
|
|
460
|
+
| :--- | :--- | :--- | :--- |
|
|
461
|
+
| **Broken External Links** (Existing README anchors or doc/index.html bookmarks) | Medium | Medium | Do not delete `doc/index.html` immediately; leave redirect anchors in `README.md`. |
|
|
462
|
+
| **Documentation & Code Desynchronization** | Medium | High | Derive all reference specs directly from `index.d.ts` and `src/server.js`. |
|
|
463
|
+
| **Accidental Code Modifications during Docs Work** | Low | High | Strictly prohibit codebase refactoring during documentation phases. |
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## 20. Open Questions
|
|
468
|
+
|
|
469
|
+
1. Should `docs/` eventually be built into a static site generator (e.g., VitePress or Starlight), or should GitHub native markdown remain the primary presentation format?
|
|
470
|
+
2. Should projects in `examples/` be wired to run as integration tests in the primary CI test run (`npm test`)?
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
## 21. Recommended Next Task
|
|
475
|
+
|
|
476
|
+
### 🎯 Documentation Restructuring Completed!
|
|
477
|
+
|
|
478
|
+
### Progress Summary:
|
|
479
|
+
- ✅ **DOC-P1-01 Completed**: Master sitemap [docs/README.md](file:///Users/ahmet/projects/webspresso/docs/README.md) and all 4 Getting Started guides ([installation.md](file:///Users/ahmet/projects/webspresso/docs/getting-started/installation.md), [first-app.md](file:///Users/ahmet/projects/webspresso/docs/getting-started/first-app.md), [project-structure.md](file:///Users/ahmet/projects/webspresso/docs/getting-started/project-structure.md), [deployment.md](file:///Users/ahmet/projects/webspresso/docs/getting-started/deployment.md)).
|
|
480
|
+
- ✅ **DOC-P2-01 Completed**: [README.md](file:///Users/ahmet/projects/webspresso/README.md) slimmed down from 103.6 KB (2,917 lines) to 6.2 KB (152 lines) with high-impact quickstart, value proposition, and direct documentation links.
|
|
481
|
+
- ✅ **DOC-P3-01 Completed**: All core conceptual deep-dive guides ([architecture.md](file:///Users/ahmet/projects/webspresso/docs/concepts/architecture.md), [request-lifecycle.md](file:///Users/ahmet/projects/webspresso/docs/concepts/request-lifecycle.md), [service-execution-pipeline.md](file:///Users/ahmet/projects/webspresso/docs/concepts/service-execution-pipeline.md), [transaction-propagation.md](file:///Users/ahmet/projects/webspresso/docs/concepts/transaction-propagation.md)) with Mermaid diagrams.
|
|
482
|
+
- ✅ **DOC-P4-01 Completed**: All 6 core task guides ([routing.md](file:///Users/ahmet/projects/webspresso/docs/guides/routing.md), [ssr-and-templates.md](file:///Users/ahmet/projects/webspresso/docs/guides/ssr-and-templates.md), [services.md](file:///Users/ahmet/projects/webspresso/docs/guides/services.md), [database-and-orm.md](file:///Users/ahmet/projects/webspresso/docs/guides/database-and-orm.md), [authentication.md](file:///Users/ahmet/projects/webspresso/docs/guides/authentication.md), [admin-panel.md](file:///Users/ahmet/projects/webspresso/docs/guides/admin-panel.md)).
|
|
483
|
+
- ✅ **DOC-P5-01 Completed**: All 5 public API specifications ([create-app.md](file:///Users/ahmet/projects/webspresso/docs/reference/create-app.md), [cli.md](file:///Users/ahmet/projects/webspresso/docs/reference/cli.md), [service-definition.md](file:///Users/ahmet/projects/webspresso/docs/reference/service-definition.md), [model-definition.md](file:///Users/ahmet/projects/webspresso/docs/reference/model-definition.md), [exceptions.md](file:///Users/ahmet/projects/webspresso/docs/reference/exceptions.md)).
|
|
484
|
+
- ✅ **DOC-P6-01 Completed**: Created [examples/basic-ssr](file:///Users/ahmet/projects/webspresso/examples/basic-ssr/) starter template covered by automated integration smoke test (`tests/unit/examples-smoke.test.js`).
|
|
485
|
+
- ✅ **DOC-P8-01 Completed**: Standard [llms.txt](file:///Users/ahmet/projects/webspresso/llms.txt) machine-readable index for LLMs and AI coding tools.
|