We are shifting the documentation paradigm from Passive Reference (reading about features) to Active Protocols (instructions on executing tasks).
- The Goal: Transform Astrical from a "CMS" into an "Autonomous Development Environment" where an AI Agent can Orient, Plan, Execute, and Verify without human hand-holding.
- The Method: We will enforce a strict separation between Knowledge (Read-Only) and Tooling (Executable). We will codify implicit architectural patterns (like "Service Singletons") into explicit templates.
We will reorganize dev/ and scripts/ to mirror the cognitive workflow of a Senior Engineer.
This directory is the AI's "Long-Term Memory." It is strictly for reading.
| Directory | Purpose | Key Content |
|---|---|---|
00_context/ |
Orientation. The "Sensory System." | current_state.md (Generated), project_manifest.yaml (Generated). |
01_architecture/ |
Laws. Immutable system rules. | system_boundaries.md (Core vs Module), data_flow.md (Build pipeline). |
02_coding_patterns/ |
Skills. Dynamic logic recipes. | app_logic/ (Services, Guards), client_side/ (Islands), server_side/ (API Routes). |
03_content_ops/ |
Strategy. Content management. | page_recipes.md, content.spec.yaml (Autogenerated specs). |
04_design_system/ |
Vision. Visual standards. | tokens.md (Variables), atomic_css.md (Tailwind rules). |
05_quality_control/ |
Correction. Debugging & QA. | debugging_flowchart.md, testing_protocols.md. |
templates/ |
Tools. Copy-paste starters. | logic/GenericGuard.ts, services/GenericService.ts. |
This directory is the AI's "Nervous System." It contains the executables that generate the artifacts in 00_context and verify work.
generate-context.ts: Scansmodules/,content/, andconfig.yamlto writedev/00_context/current_state.md.validate-content.ts: Enforces Zod schemas on YAML content.validate-themes.ts: Ensures theme integrity.
The Problem: AI Agents often hallucinate files or lose track of installed modules.
The Strategy: We implement a "Wake-Up Routine."
- The Trigger: Every session begins with the command
npm run context:refresh. - The Action: This runs
scripts/generate-context.ts. - The Artifact: It generates
dev/00_context/current_state.md, a single file containing:- Active Configuration (Snippet from
content/config.yaml). - Module Inventory (List of installed capabilities).
- Content Tree (High-level map of
content/pages). - Theme Status (Active theme and overrides).
- Active Configuration (Snippet from
- The Instruction: The AI is strictly instructed: "Before planning any task, read
dev/00_context/current_state.md."
We will codify the three "Universal Patterns" inferred from your codebase to prevent the AI from writing messy, unmaintainable code.
- Derived From:
src/components/common/AuthGuard.astro. - The Rule: "Never mix business logic (Auth, Permissions) with display components."
- The Template:
dev/templates/logic/GenericGuard.astro. - Usage: Feature flags, Subscription gates, A/B testing.
- Derived From:
src/utils/cache.ts. - The Rule: "Never export a raw NanoStore. Always wrap it in a Service facade (
getVar,setVar)." - The Template:
dev/templates/services/GenericService.ts. - Usage: Shopping carts, User preferences, Analytics buffers.
- Derived From:
src/pages/api/submit-form.ts. - The Rule: "API Routes are Controllers, not Services. They Validate Input -> Check Security (Honeypot) -> Delegate to a Utility."
- The Template:
dev/templates/pages/SafeApiRoute.ts. - Usage: Form submissions, Webhooks, Data fetching proxies.
The Problem: AI Agents get stuck in error loops or break existing features.
The Strategy: A mandatory "Verification Step" for every task.
- Debugging Flowchart (
debugging_flowchart.md): A decision tree for common errors.- If "Hydration Mismatch" -> Check HTML nesting in
.astrovs.tsx. - If "Schema Error" -> Fix YAML content, DO NOT edit
.spec.yaml.
- If "Hydration Mismatch" -> Check HTML nesting in
- Testing Protocols (
testing_protocols.md):- Rule: "Every new utility in
src/utils/MUST have a corresponding unit test intest/unit/." - Reference:
test/unit/utils/cache.test.ts.
- Rule: "Every new utility in
- Validation Scripts:
- Rule: "After editing content, run
npm run validate:content." - Rule: "After editing styles, run
npm run validate:themes."
- Rule: "After editing content, run
We will write the documentation in the following priority order to unlock Agent autonomy immediately:
- Sensory System (Immediate Impact):
- Write
scripts/generate-context.ts. - Update
package.jsonwith thecontext:refreshcommand.
- Write
- Coding Patterns (Dynamic Capability):
- Write
02_coding_patterns/client_side/stores.md(The "Service Singleton" pattern). - Write
02_coding_patterns/server_side/api_routes.md(The "Secure Controller" pattern). - Write
02_coding_patterns/client_side/islands.md(Distinguishing Server Logic vs. Client Interactivity).
- Write
- Quality Control (Reliability):
- Write
05_quality_control/debugging_flowchart.md.
- Write
- Templates (Standardization):
- Create the
dev/templates/directory and populate it with the 3 Core Pattern templates.
- Create the