diff --git a/.idx/AGENTS.md b/.idx/AGENTS.md new file mode 100644 index 00000000..02f81e88 --- /dev/null +++ b/.idx/AGENTS.md @@ -0,0 +1,22 @@ +# Expert AI Engineering Protocol + +## Clean Code & TypeScript Principles +When modifying or extending this framework, strictly adhere to these principles: + +### 1. Robust Type Safety +- **No 'any'**: Avoid the use of 'any' at all costs. Use Zod schemas for all external data sources and configuration files. +- **Inference where possible**: Trust TypeScript's inference for local variables, but explicitly type exported constants and function parameters. +- **Exhaustive Checks**: Use discriminating unions and exhaustive 'switch' checks for themes, routes, and layout types. + +### 2. Framework Modularity +- **Source of Truth**: The centralized 'src/config.ts' is the single source of truth for site-wide settings. Do not hardcode strings (site names, social URLs, paths) in components. +- **Feature Flags**: Respect all feature flags defined in 'CONFIG.features'. If a feature is disabled, the corresponding components should not render and routes should be guarded via middleware. +- **CSS Variable Overrides**: Design changes should primarily be handled through HSL variable overrides defined in 'CONFIG.theme.overrides'. + +### 3. File Operations +- **Atomic Writes**: Always ensure configuration files are well-formed before writing. +- **Asset Integrity**: When changing PWA settings or site metadata, verify that the referenced assets (favicons, manifest icons) exist in the 'public/' directory. + +### 4. Verification Workflow +- Every change must pass a full build ('npm run build') and all unit tests ('npm test'). +- Frontend changes require visual verification via Playwright, ensuring consistent layout across different configured themes. diff --git a/FRAMEWORK_PLAN.md b/FRAMEWORK_PLAN.md new file mode 100644 index 00000000..661f060f --- /dev/null +++ b/FRAMEWORK_PLAN.md @@ -0,0 +1,103 @@ +# Framework Conversion Plan (v2) + +This document outlines the comprehensive strategy for transforming this repository into a reusable Astro blog framework, enhanced with senior-level architectural considerations for long-term maintainability. + +## 1. Centralized Configuration & Validation + +To ensure the framework is robust, we will implement a centralized configuration system using **Zod** for schema validation. This provides both TypeScript types and runtime error checking. + +### Configuration Schema (`src/schemas/config.ts`) +```typescript +import { z } from 'zod'; + +export const FrameworkConfigSchema = z.object({ + site: z.object({ + title: z.string(), + description: z.string(), + author: z.string(), + logoText: z.string().optional(), + siteUrl: z.string().url(), + lang: z.string().default('en'), + social: z.record(z.string()).optional(), + }), + navigation: z.object({ + header: z.array(z.object({ label: z.string(), href: z.string() })), + footer: z.array(z.object({ label: z.string(), href: z.string() })), + }), + features: z.object({ + enableSearch: z.boolean().default(true), + enablePWA: z.boolean().default(true), + enableToolsPage: z.boolean().default(false), + enableRSS: z.boolean().default(true), + }), + theme: z.object({ + active: z.enum(['newspaper', 'minimal', 'modern']).default('newspaper'), + overrides: z.record(z.string()).optional(), + }), + routing: z.object({ + homepage: z.enum(['blog', 'tools']).default('blog'), + }), + assets: z.object({ + favicon: z.string().default('/favicon.svg'), + defaultHeroImage: z.string().default('/placeholder-social.jpg'), + pwaIconsDir: z.string().default('/icons'), + }) +}); + +export type FrameworkConfig = z.infer; +``` + +## 2. Dynamic Routing & Feature Toggles + +### Homepage Selection +- **Refactor `src/pages/index.astro`**: It will serve as a dynamic router. Based on `config.routing.homepage`, it will import and render the appropriate template (Blog or Tools). + +### Disabling Routes +- **Astro Middleware**: Use middleware to redirect requests for disabled features (e.g., `/tools`) back to the homepage if `enableToolsPage` is false. This ensures a clean user experience even if URLs are directly accessed. + +## 3. Advanced Theming System + +- **Tailwind v4 Integration**: Use `@theme` blocks in `src/styles/global.css` to define base variables. +- **Dynamic CSS Injection**: In `PageLayout.astro`, inject a `