Generate Product Knowledge Base
You are generating a comprehensive product knowledge base from source code analysis. The output is an Obsidian vault with interconnected documents covering architecture, data models, APIs, business domains, and infrastructure.
Before You Start
Read these reference files to understand the expected output format and quality criteria:
references/document-formats.md — the 4-part document structure with examples
references/category-patterns.md — where to find information for each tech stack
references/quality-checklist.md — self-review criteria for every document
Workflow
Execute these steps in order. Do not skip steps. Wait for user approval at Step 2 before generating documents.
Step 1 — Setup & Discovery
Gather project information:
- Product name: Ask the user for the product/project name. Use it in all generated doc titles and references.
- Codebase path: Use
$ARGUMENTS if provided, otherwise ask the user. Resolve to an absolute path. Verify the directory exists.
- Output directory: Ask where to write the vault. Default: a sibling directory named
<product>-knowledge/ next to the codebase.
Detect the tech stack:
Glob for marker files at the codebase root and one level deep:
package.json, tsconfig.json → JavaScript/TypeScript
requirements.txt, pyproject.toml, setup.py, Pipfile → Python
pom.xml, build.gradle, build.gradle.kts → Java/Kotlin
go.mod → Go
Cargo.toml → Rust
Gemfile → Ruby
composer.json → PHP
mix.exs → Elixir
*.sln, *.csproj → C#/.NET
Read each detected marker file to identify specific frameworks:
package.json → check dependencies for next, express, nestjs, react, etc.
requirements.txt / pyproject.toml → check for django, fastapi, flask, etc.
build.gradle.kts → check for ktor, spring-boot, etc.
go.mod → check for gin, echo, fiber, etc.
Map the directory structure:
- Find top-level directories:
src/, app/, cmd/, internal/, lib/, pkg/, server/, services/, api/, routes/, controllers/, models/, views/, templates/, static/, public/, frontend/, backend/, infra/, terraform/, deploy/, migrations/, .github/, .circleci/
- Identify monorepo patterns: multiple
package.json files, workspace configs, services/ directories with independent modules
- Find test directories:
test/, tests/, __tests__/, spec/
- Find SDK/client directories:
sdk/, client/, packages/
Report findings to the user:
Detected: [Language] with [Framework]
Services: [list of services/modules found]
Database: [type if detected from configs]
Infrastructure: [CI/CD, cloud provider if found]
Step 2 — Plan the Vault
Based on detected tech stack, determine which categories to generate:
Always include:
architecture/ — system overview, tech stack, data flows
api/ — endpoint documentation (if HTTP routes found)
domains/ — business logic by domain
Include if relevant sources found:
data-model/ — if migration files, ORM models, or schema definitions found
infrastructure/ — if Terraform, CloudFormation, Docker, or CI configs found
sdks/ — if SDK or client library code found
services/ — if multiple backend services (monorepo/microservices)
integrations/ — if third-party service integrations found
Identify business domains by analyzing:
- Directory names under
src/, app/, internal/, services/
- Route/controller groupings
- Model/entity names
- Service class names
Present the plan to the user:
## Generation Plan
Product: [name]
Output: [path]
Tech Stack: [detected]
### Documents to Generate (~XX total)
**Architecture** (X docs)
- architecture/overview.md
- architecture/tech-stack.md
- ...
**API** (X docs)
- api/overview.md
- ...
**Domains** (X docs)
- domains/[domain-1]/overview.md
- ...
Shall I proceed?
Wait for explicit user approval before continuing.
Step 3 — Generate Architecture Docs
Generate 3-8 architecture documents by reading:
- README files, docker-compose files
- Entry points (
main.ts, app.py, Application.kt, main.go, etc.)
- Infrastructure configs (Terraform, CloudFormation, Dockerfile)
- Build configs (
package.json scripts, Makefile, build.gradle.kts)
Required documents:
architecture/overview.md — system topology with a Mermaid diagram showing services, data stores, and external dependencies
architecture/tech-stack.md — languages, frameworks, databases, queues, cloud services with version numbers where available
Optional documents (create if sufficient source material exists):
architecture/data-flow.md — request lifecycle, async processing flows
architecture/backend-services.md — service responsibilities, ports, deployment
architecture/frontend-apps.md — frontend architecture, routing, state management
Step 4 — Generate Data Model Docs
Generate 2-10 data model documents by reading:
- Migration files (
migrations/, db/migrate/, alembic/)
- ORM models (Django
models.py, SQLAlchemy models, Exposed tables, GORM structs)
- Schema definitions (SQL files, Prisma schema, TypeORM entities)
- Seed data files
Required documents:
data-model/overview.md — database architecture, schema organization
Per-entity documents:
data-model/<entity>.md — table/collection schema with columns, types, constraints, relationships
Step 5 — Generate API Docs
Generate 3-20 API documents by reading:
- Route definitions (Express routers, Django URLs, Ktor routing, Go handlers)
- Controller/handler implementations
- OpenAPI/Swagger specs if available
- Middleware (auth, validation, rate limiting)
- Request/response types (protobuf, TypeScript interfaces, Pydantic models)
Required documents:
api/overview.md — API architecture, authentication methods, common patterns
Per-resource documents:
api/<resource>.md — endpoints for a resource group with routes, methods, request/response shapes, and auth requirements
If the codebase has multiple API servers (external + internal, public + admin), organize as:
api/external-api/overview.md
api/internal-api/overview.md
Step 6 — Generate Domain Docs
Generate 10-30 domain documents. This is the largest category and should be chunked.
For each identified business domain:
- Read service layer, domain models, and business logic files
- Generate
domains/<domain>/overview.md — concept, lifecycle, state machine
- Generate
domains/<domain>/<feature>.md — specific feature logic
Chunking strategy:
- Generate domains in batches of 5-10 documents
- After each batch, verify wikilinks between generated docs
- Continue until all domains are covered
Use the Task tool to parallelize independent domain research when the codebase is large.
Step 7 — Generate Infrastructure Docs
Generate 2-5 infrastructure documents by reading:
- Terraform/CloudFormation/Pulumi files
- CI/CD configs (
.github/workflows/, .circleci/, Jenkinsfile, .gitlab-ci.yml)
- Docker files (
Dockerfile, docker-compose.yml)
- Monitoring configs (CloudWatch, Datadog, Prometheus)
- Deployment scripts
Required documents:
infrastructure/overview.md — cloud architecture, deployment topology
Optional documents:
infrastructure/ci-cd.md — build and deploy pipeline
infrastructure/monitoring.md — observability, alerting, logging
infrastructure/database-management.md — backup, scaling, connection pooling
Step 8 — Finalize
Generate README.md: Create the vault's master index using the assets/README.md.template. List every generated document as a [[wikilink]] organized by category.
Generate CLAUDE.md: Create the vault's CLAUDE.md using the assets/CLAUDE.md.template. Fill in:
- Product name
- Vault structure (categories and their contents)
- Source code paths table
- Conventions (wikilinks, document format, Mermaid diagrams)
Validate wikilinks: Run scripts/validate-wikilinks.sh on the output directory. Fix any broken links it reports.
Print summary:
## Generation Complete
Product: [name]
Location: [path]
Documents: [count] across [N] categories
Wikilinks: [count] total, [broken] broken
Categories:
- architecture/: X docs
- data-model/: X docs
- api/: X docs
- domains/: X docs
- infrastructure/: X docs
Open the vault in Obsidian to browse the knowledge graph.
Key Rules
Code-first: Every statement must trace to actual source code. Never invent or assume logic. If you cannot find the implementation, say "Not found in source" rather than guessing.
Source attribution: Every document must include a > **Source files**: block listing the exact files analyzed. Use relative paths from the codebase root.
Fully-qualified wikilinks: Always use the full path from the vault root: [[domains/campaigns/overview]], never [[overview]] or [[campaigns/overview]].
One concern per file: Each document covers exactly one topic. Split large topics into multiple documents.
Mermaid diagrams: Include a Mermaid diagram for any flow with 3+ steps. Use graph TD/TB/LR for flowcharts and sequenceDiagram for interaction flows.
No marketing language: Write for engineers. Include file paths, function names, and implementation details. This is internal documentation, not a product page.
Quality check: Before finalizing each document, verify it against references/quality-checklist.md.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: generate-knowledge-base3description: Generate a product knowledge base from a codebase. Analyzes source code to create an Obsidian vault with architecture docs, API references, domain logic, data models, and infrastructure documentation. Use when the user asks to document a codebase, create a knowledge base, or generate product docs. Use when this capability is needed.4---56# Generate Product Knowledge Base78You are generating a comprehensive product knowledge base from source code analysis. The output is an Obsidian vault with interconnected documents covering architecture, data models, APIs, business domains, and infrastructure.910## Before You Start1112Read these reference files to understand the expected output format and quality criteria:13- `references/document-formats.md` — the 4-part document structure with examples14- `references/category-patterns.md` — where to find information for each tech stack15- `references/quality-checklist.md` — self-review criteria for every document1617## Workflow1819Execute these steps in order. Do not skip steps. Wait for user approval at Step 2 before generating documents.2021### Step 1 — Setup & Discovery2223Gather project information:24251. **Product name**: Ask the user for the product/project name. Use it in all generated doc titles and references.262. **Codebase path**: Use `$ARGUMENTS` if provided, otherwise ask the user. Resolve to an absolute path. Verify the directory exists.273. **Output directory**: Ask where to write the vault. Default: a sibling directory named `<product>-knowledge/` next to the codebase.2829Detect the tech stack:30311. Glob for marker files at the codebase root and one level deep:32 - `package.json`, `tsconfig.json` → JavaScript/TypeScript33 - `requirements.txt`, `pyproject.toml`, `setup.py`, `Pipfile` → Python34 - `pom.xml`, `build.gradle`, `build.gradle.kts` → Java/Kotlin35 - `go.mod` → Go36 - `Cargo.toml` → Rust37 - `Gemfile` → Ruby38 - `composer.json` → PHP39 - `mix.exs` → Elixir40 - `*.sln`, `*.csproj` → C#/.NET41422. Read each detected marker file to identify specific frameworks:43 - `package.json` → check `dependencies` for `next`, `express`, `nestjs`, `react`, etc.44 - `requirements.txt` / `pyproject.toml` → check for `django`, `fastapi`, `flask`, etc.45 - `build.gradle.kts` → check for `ktor`, `spring-boot`, etc.46 - `go.mod` → check for `gin`, `echo`, `fiber`, etc.47483. Map the directory structure:49 - Find top-level directories: `src/`, `app/`, `cmd/`, `internal/`, `lib/`, `pkg/`, `server/`, `services/`, `api/`, `routes/`, `controllers/`, `models/`, `views/`, `templates/`, `static/`, `public/`, `frontend/`, `backend/`, `infra/`, `terraform/`, `deploy/`, `migrations/`, `.github/`, `.circleci/`50 - Identify monorepo patterns: multiple `package.json` files, workspace configs, `services/` directories with independent modules51 - Find test directories: `test/`, `tests/`, `__tests__/`, `spec/`52 - Find SDK/client directories: `sdk/`, `client/`, `packages/`53544. Report findings to the user:55 ```56 Detected: [Language] with [Framework]57 Services: [list of services/modules found]58 Database: [type if detected from configs]59 Infrastructure: [CI/CD, cloud provider if found]60 ```6162### Step 2 — Plan the Vault6364Based on detected tech stack, determine which categories to generate:6566**Always include:**67- `architecture/` — system overview, tech stack, data flows68- `api/` — endpoint documentation (if HTTP routes found)69- `domains/` — business logic by domain7071**Include if relevant sources found:**72- `data-model/` — if migration files, ORM models, or schema definitions found73- `infrastructure/` — if Terraform, CloudFormation, Docker, or CI configs found74- `sdks/` — if SDK or client library code found75- `services/` — if multiple backend services (monorepo/microservices)76- `integrations/` — if third-party service integrations found7778Identify business domains by analyzing:79- Directory names under `src/`, `app/`, `internal/`, `services/`80- Route/controller groupings81- Model/entity names82- Service class names8384Present the plan to the user:85```86## Generation Plan8788Product: [name]89Output: [path]90Tech Stack: [detected]9192### Documents to Generate (~XX total)9394**Architecture** (X docs)95- architecture/overview.md96- architecture/tech-stack.md97- ...9899**API** (X docs)100- api/overview.md101- ...102103**Domains** (X docs)104- domains/[domain-1]/overview.md105- ...106107Shall I proceed?108```109110**Wait for explicit user approval before continuing.**111112### Step 3 — Generate Architecture Docs113114Generate 3-8 architecture documents by reading:115- README files, docker-compose files116- Entry points (`main.ts`, `app.py`, `Application.kt`, `main.go`, etc.)117- Infrastructure configs (Terraform, CloudFormation, Dockerfile)118- Build configs (`package.json` scripts, `Makefile`, `build.gradle.kts`)119120Required documents:121- `architecture/overview.md` — system topology with a Mermaid diagram showing services, data stores, and external dependencies122- `architecture/tech-stack.md` — languages, frameworks, databases, queues, cloud services with version numbers where available123124Optional documents (create if sufficient source material exists):125- `architecture/data-flow.md` — request lifecycle, async processing flows126- `architecture/backend-services.md` — service responsibilities, ports, deployment127- `architecture/frontend-apps.md` — frontend architecture, routing, state management128129### Step 4 — Generate Data Model Docs130131Generate 2-10 data model documents by reading:132- Migration files (`migrations/`, `db/migrate/`, `alembic/`)133- ORM models (Django `models.py`, SQLAlchemy models, Exposed tables, GORM structs)134- Schema definitions (SQL files, Prisma schema, TypeORM entities)135- Seed data files136137Required documents:138- `data-model/overview.md` — database architecture, schema organization139140Per-entity documents:141- `data-model/<entity>.md` — table/collection schema with columns, types, constraints, relationships142143### Step 5 — Generate API Docs144145Generate 3-20 API documents by reading:146- Route definitions (Express routers, Django URLs, Ktor routing, Go handlers)147- Controller/handler implementations148- OpenAPI/Swagger specs if available149- Middleware (auth, validation, rate limiting)150- Request/response types (protobuf, TypeScript interfaces, Pydantic models)151152Required documents:153- `api/overview.md` — API architecture, authentication methods, common patterns154155Per-resource documents:156- `api/<resource>.md` — endpoints for a resource group with routes, methods, request/response shapes, and auth requirements157158If the codebase has multiple API servers (external + internal, public + admin), organize as:159- `api/external-api/overview.md`160- `api/internal-api/overview.md`161162### Step 6 — Generate Domain Docs163164Generate 10-30 domain documents. This is the largest category and should be chunked.165166For each identified business domain:1671. Read service layer, domain models, and business logic files1682. Generate `domains/<domain>/overview.md` — concept, lifecycle, state machine1693. Generate `domains/<domain>/<feature>.md` — specific feature logic170171**Chunking strategy:**172- Generate domains in batches of 5-10 documents173- After each batch, verify wikilinks between generated docs174- Continue until all domains are covered175176Use the Task tool to parallelize independent domain research when the codebase is large.177178### Step 7 — Generate Infrastructure Docs179180Generate 2-5 infrastructure documents by reading:181- Terraform/CloudFormation/Pulumi files182- CI/CD configs (`.github/workflows/`, `.circleci/`, `Jenkinsfile`, `.gitlab-ci.yml`)183- Docker files (`Dockerfile`, `docker-compose.yml`)184- Monitoring configs (CloudWatch, Datadog, Prometheus)185- Deployment scripts186187Required documents:188- `infrastructure/overview.md` — cloud architecture, deployment topology189190Optional documents:191- `infrastructure/ci-cd.md` — build and deploy pipeline192- `infrastructure/monitoring.md` — observability, alerting, logging193- `infrastructure/database-management.md` — backup, scaling, connection pooling194195### Step 8 — Finalize1961971. **Generate README.md**: Create the vault's master index using the `assets/README.md.template`. List every generated document as a `[[wikilink]]` organized by category.1981992. **Generate CLAUDE.md**: Create the vault's CLAUDE.md using the `assets/CLAUDE.md.template`. Fill in:200 - Product name201 - Vault structure (categories and their contents)202 - Source code paths table203 - Conventions (wikilinks, document format, Mermaid diagrams)2042053. **Validate wikilinks**: Run `scripts/validate-wikilinks.sh` on the output directory. Fix any broken links it reports.2062074. **Print summary**:208 ```209 ## Generation Complete210211 Product: [name]212 Location: [path]213 Documents: [count] across [N] categories214 Wikilinks: [count] total, [broken] broken215216 Categories:217 - architecture/: X docs218 - data-model/: X docs219 - api/: X docs220 - domains/: X docs221 - infrastructure/: X docs222223 Open the vault in Obsidian to browse the knowledge graph.224 ```225226## Key Rules2272281. **Code-first**: Every statement must trace to actual source code. Never invent or assume logic. If you cannot find the implementation, say "Not found in source" rather than guessing.2292302. **Source attribution**: Every document must include a `> **Source files**:` block listing the exact files analyzed. Use relative paths from the codebase root.2312323. **Fully-qualified wikilinks**: Always use the full path from the vault root: `[[domains/campaigns/overview]]`, never `[[overview]]` or `[[campaigns/overview]]`.2332344. **One concern per file**: Each document covers exactly one topic. Split large topics into multiple documents.2352365. **Mermaid diagrams**: Include a Mermaid diagram for any flow with 3+ steps. Use `graph TD/TB/LR` for flowcharts and `sequenceDiagram` for interaction flows.2372386. **No marketing language**: Write for engineers. Include file paths, function names, and implementation details. This is internal documentation, not a product page.2392407. **Quality check**: Before finalizing each document, verify it against `references/quality-checklist.md`.241242---243> Converted and distributed by [TomeVault](https://tomevault.io/claim/pmtouchedthecode) — claim your Tome and manage your conversions.244<!-- tomevault:4.0:skill_md:2026-04-13 -->