skills/local/cali-codebase-spec/SKILL.md
Use when user provides a codebase (file path, GitHub URL, uploaded files, pasted code, or "@file" reference) and asks to understand, document, reverse-engineer, or analyze what the product does. Triggers on: "spec", "specification", "document this", "what does this do", "reverse engineer", "analyze codebase", "extract product rules", "what can this do", "@/path/to/file", "@file". NOT for: reading logs, debugging specific errors (use agent-browser or ctx_execute instead).
npx skillsauth add renatocaliari/agent-sync-public-skills cali-codebase-specInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Reverse-engineer a product from its source code into a comprehensive, tech-stack-agnostic specification document. The output should be thorough enough that another team could rebuild the product in any language or framework.
The skill accepts any of:
| Input Type | How to Detect | How to Handle |
|------------|---------------|---------------|
| Local path | @/path or @path or absolute path | find + read |
| GitHub URL | github.com/owner/repo | ctx_fetch_and_index + explore |
| Uploaded files | Session attachment | Extract and explore |
| Pasted code | User pasted snippet | Treat as module |
| Zip archive | .zip extension | unzip -o <file> -d /tmp/cali-codebase-spec-input |
Mixed input: Handle each type appropriately and merge findings.
Write the spec to a project-local path in the current working directory:
{cwd}/docs/codebase/{project-name}-spec.md
If {project-name} cannot be determined from the input, use codebase-spec.md.
Why project-local? Living documents should live with the code. This enables:
If the docs/ directory does not exist, create it first.
STOP reading files when you can answer ALL of:
If you cannot answer all 5, continue reading.
| Repo Size | Strategy | |----------|----------| | Small (<50 files) | Read everything | | Medium (50-200 files) | Top 30 files by importance (see priority order below) | | Large (200+ files) | Package roots → feature directories → key files |
Large repo sampling:
package.json, go.mod, pyproject.toml, Cargo.toml)Monorepo handling: If multiple package manifests found:
Read files in this order (most important first):
package.json / go.mod / pyproject.toml / Cargo.toml — tech stack + dependenciessrc/main.ts / src/index.ts / cmd/ / app.py / main.go — entry pointREADME.md — human context (if exists)routes/, controllers/, pages/, handlers/, endpoints/)models/, schemas/, types/, entities/)services/, hooks/, middleware/, validation/)openapi.yaml, graphql/, proto/)auth/, middleware/auth*)db/, migrations/, schema.*)components/, views/)utils/, helpers/, lib/)test/, spec/) — extract rules from test casesAlways search for AI integrations. This is a priority detection.
grep -r -i "openai\|anthropic\|claude\|gpt\|gemini\|mistral\|llama\|ollama\|langchain\|llamaindex\|huggingface\|transformers\|replicate\|groq\|cohere\|bedrock\|vertex" \
--include="*.js" --include="*.ts" --include="*.py" --include="*.go" \
--include="*.rb" --include="*.java" --include="*.cs" \
--include="*.md" --include="*.json" \
. 2>/dev/null | grep -v node_modules | head -50
For each AI integration found, extract:
Execute these steps in order:
find . -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.py" -o -name "*.go" \) \
! -path "./node_modules/*" ! -path "./.git/*" ! -path "./dist/*" ! -path "./build/*" \
! -path "./vendor/*" | head -200
Look for: package.json, go.mod, pyproject.toml, Gemfile, pom.xml, Dockerfile, docker-compose.yml.
Run the grep command above. Read every file that matches.
Start with essential files, then features. Stop when saturation signals met.
Read models, schemas, Zod/Pydantic types, Prisma schema, GraphQL types.
Forms, modals, pages — they reveal exact fields, validations, and UX flows.
Services, hooks, utilities, middleware — where the rules live.
REST routes, GraphQL resolvers, tRPC routers, gRPC protos.
Before writing, ask yourself:
If AI/LLM found: Document EVERY call in detail. This is often the most valuable section.
Write the spec in the same language the user wrote in (Portuguese → Portuguese, English → English).
1. Product Overview
2. Tech Stack Summary (context only)
3. User Roles & Permissions
4. Features & Product Rules
5. User Flows (ASCII art)
6. Screens & Components (ASCII art)
7. Data Models
8. API Surface
9. AI / LLM Integration (detailed — if any)
10. Business Rules Catalog
11. Open Questions / Inferred Behavior
One paragraph: what is this, who uses it, what core problem it solves.
| Layer | Technology | Notes | |-------|-----------|-------| | Frontend | React + Next.js | App Router | | Backend | Node / Express | REST API | | Database | PostgreSQL | via Prisma ORM | | AI | OpenAI SDK | GPT-4o, streaming | | Auth | NextAuth.js | Google + email/password | | Infra | Vercel + Railway | |
Note: This section exists for context only. The rest of the spec is tech-agnostic.
List every role found in the code (admin, user, guest, etc.) and what each can do.
For each feature:
### Feature: [Name]
**Description:** What it does in plain English.
**Rules:**
- Rule 1 (extracted from validation / business logic)
- Rule 2
- ...
**Edge cases handled:**
- ...
Draw flows using ASCII art. Use these symbols:
Arrows: ──► ◄── ──►──► ═══►
Vertical: │ ▲ ▼
Decision: ─┬─ ─┤ └──
Box styles: ┌───────┐ ╭───────╮ ┏━━━━━━━┓
│ text │ │ text │ ┃ text ┃
└───────┘ ╰───────╯ ┗━━━━━━━┛
Draw wireframe-level ASCII for every distinct screen.
If UI is not visible (e.g., API-only product):
ASCII wireframe template:
┌─────────────────────────────────────────────────────┐
│ Header: [Page Title] │
├─────────────────────────────────────────────────────┤
│ Nav: [Nav1] [Nav2] [Nav3] [User ▼] │
├───────────┬─────────────────────────────────────┤
│ Sidebar │ Content Area │
│ - Item 1 │ ┌─────────────────────────────┐ │
│ - Item 2 │ │ Widget / Component │ │
│ - Item 3 │ └─────────────────────────────┘ │
└───────────┴─────────────────────────────────────┘
For each entity:
### Entity: [Name]
| Field | Type | Rules / Notes |
|---------------|-----------|----------------------------------|
| id | UUID | auto-generated |
| email | string | unique, required, validated |
| role | enum | user | admin | guest |
| created_at | timestamp | auto |
Relations:
- [Entity] has many [OtherEntity]
- [Entity] belongs to [OtherEntity]
### POST /api/auth/login
**Purpose:** Authenticate user
**Auth:** Public
**Body:** { email: string, password: string }
**Returns:** { token: string, user: User }
**Rules:**
- Rate limited: 5 attempts / 15min
- Returns 401 if credentials invalid
- Logs failed attempts
This is the most important section for AI-powered products.
For each AI feature:
### AI Feature: [Name]
**Provider:** OpenAI / Anthropic / etc.
**Model:** gpt-4o / claude-3-5-sonnet-20241022 / etc.
**Endpoint:** /api/chat or similar
**Streaming:** yes/no
**System Prompt:**
\`\`\`
[exact system prompt extracted from code]
\`\`\`
**User Prompt Template:**
\`\`\`
[exact template, with {variable} placeholders shown]
\`\`\`
**Inference Parameters:**
| Param | Value |
|---------------|--------|
| temperature | 0.7 |
| max_tokens | 2000 |
**Input:** What is passed to the model
**Output:** How the response is used
**Post-processing:** Any parsing/validation/transform
**Tool/Function Calling (if any):**
\`\`\`json
[exact definitions from code]
\`\`\`
**Error handling:**
- What happens on API failure
- Fallback behavior
A numbered, exhaustive list. Include confidence level for each.
BR-001: [Confidence: HIGH/MEDIUM/LOW]
Users cannot delete a project with active subscriptions.
**Evidence:** `src/services/project.ts:156`
```typescript
if (project.subscriptions.length > 0) {
throw new Error("Cannot delete project with active subscriptions");
}
BR-002: [Confidence: HIGH]
Email must be verified before accessing paid features.
Evidence: src/middleware/auth.ts:23
if (!user.emailVerified && plan === 'paid') {
return res.status(403).json({ error: "Email not verified" });
}
BR-003: [Confidence: MEDIUM]
AI features are disabled for free tier users.
Evidence: src/config/features.ts:15 + UI gate in src/components/AIFeature.tsx
Note: UI prevents access, but backend validation also exists.
BR-004: [Confidence: LOW]
Messages are truncated to 4000 tokens before sending to LLM.
Evidence: Comment in src/services/chat.ts:89
// TODO: confirm token limit with API
Warning: This is inferred from comment, not verified behavior.
#### 11. Open Questions / Inferred Behavior
Mark each item with appropriate flag:
| Flag | Meaning |
|------|---------|
| ⚠️ INFERRED | Behavior assumed from code patterns, not explicit confirmation |
| ⚠️ INCOMPLETE | Handler exists but edge cases not fully traced |
| ❓ UNCLEAR | Cannot determine intent from available code |
| 🔍 VERIFIED | Confirmed against running system or tests |
⚠️ INFERRED: The legacy_mode flag appears in the user model but is never set
anywhere in the current codebase. Possibly dead code or migrated feature.
⚠️ INCOMPLETE: Payment webhook handler exists but only handles payment_succeeded.
No handler found for payment_failed or subscription_cancelled.
❓ UNCLEAR: The onboarding flow appears to be optional based on a skip button,
but no skip logic was found in the backend.
## Confidence Levels
| Level | Criteria | Example |
|-------|----------|---------|
| **HIGH** | Exact code match, line referenced | `auth.ts:42` shows exact behavior |
| **MEDIUM** | Cross-reference inference | Called by A, used by B, behavior inferred |
| **LOW** | Comment, TODO, or guess | "// TODO: implement rate limiting" |
**Rule:** Never claim HIGH confidence for inferred behavior.
## Phase 4: Quality Gates
Before saving, verify:
- [ ] All 5 saturation questions answered
- [ ] Every route/page has corresponding entry (screen or description)
- [ ] Every AI call documented in Section 9 (if any AI found)
- [ ] Every validation rule captured in Section 10
- [ ] Confidence level on every business rule
- [ ] ASCII art renders correctly (consistent widths, aligned columns)
- [ ] No placeholder text ("TBD", "TODO", "FIXME" in output)
- [ ] Output path exists or was created
- [ ] Tech-stack specifics in Section 2 only (rest is agnostic)
## Phase 5: Post-Write Audit
After saving, add to the spec:
When code changes, re-run this skill to regenerate:
git diff docs/codebase/{name}-spec.mdLiving document maintenance:
## Common Errors to Avoid
1. **Tech vs Product confusion**
→ If it requires code to verify, it's tech; if it's behavioral, it's product
2. **Inferring user roles that don't exist**
→ Only document roles found in code (auth checks, role enums, permission guards)
3. **Missing AI integration details**
→ Always run the grep command; AI features are often the most valuable output
4. **Incomplete business rules**
→ Extract from: validation, middleware, service logic, edge case handlers, test cases
5. **ASCII art as obligation**
→ If UI is not visible (API-only, backend), describe textually. Don't fake wireframes.
6. **All rules as HIGH confidence**
→ Include MEDIUM and LOW with appropriate evidence. False confidence is worse than uncertainty.
## Testing the Skill
After any changes to this skill, test with:
**Trigger tests:**
- "Document this codebase" + local path → should trigger
- "Analyze @src/" + pasted code → should trigger
- "What does this do?" + GitHub URL → should trigger
- "Debug the login bug" → should NOT trigger
**Output tests:**
- Spec contains all 11 sections
- AI/LLM section complete if AI found
- Every business rule has confidence level
- ASCII art renders without broken boxes
## References
- [SKILL.md Guide](https://lalitmadan.com/post/the-skill-md-guide) — Lalit Madan
- [Anthropic Skills Best Practices](https://github.com/anthropics/skills)
- [mgechev/skills-best-practices](https://github.com/mgechev/skills-best-practices)
- [MCP Build with Agent Skills](https://modelcontextprotocol.io/docs/develop/build-with-agent-skills)
---
*Skill v2.0.0 — Updated based on execution experience + 2026 skill design research*
development
PocketBase v0.39+ development - API rules, auth, collections, SDK, realtime, files, Go/JS extending, deployment, production tuning.
tools
Auto-initialize structured documentation for any project using lat.md (knowledge graph of markdown files with [[wiki links]], // @lat: code refs, and semantic search). Detects cali-product-workflow artifacts (spec-product.md, spec-tech.md, critiques) and uses them as seed material. Falls back to extracting business rules, architecture, and design decisions directly from the codebase. Use when a project lacks structured documentation or when lat.md/ is missing. After seeding, lat.md extension hooks keep documentation alive automatically.
testing
[Cali] Server security audit and hardening for private servers behind Tailscale. Use when: auditing server security, hardening SSH/firewall/Docker, checking for vulnerabilities, setting up fail2ban, reviewing port exposure, or responding to security alerts. Covers 6 layers: CloudFlare, UFW, Tailscale, SSH, Docker, Application. Triggers: "server security", "security audit", "harden server", "SSH hardening", "firewall rules", "UFW config", "fail2ban", "port security", "Docker security", "vulnerability check", "security review".
tools
Run supply chain security scans before installing packages or before releases. Triggers when: user installs a package (npm, pip, go get, brew), user asks to 'scan dependencies', 'check vulnerabilities', 'supply chain', 'security audit', 'run trivy', 'run socket', or before any release/deployment. Also triggers on mentions of: socket.dev, trivy, OSV-scanner, dotenvx, CVE, dependency audit. Covers all four tools with concrete commands.