Project Init
Deep-scan an existing project and generate AI context files (AGENTS.md, ARCHITECTURE.md, TESTING.md) for the root and all significant subprojects. After completion, the runtime has the context it needs: tech stack, conventions, structure, setup, testing, security.
1. Initial Reconnaissance
1a. Root Structure Scan
// turbo
ls -la # or Get-ChildItem on Windows
Identify stack signals:
| Signal |
Indicates |
package.json, tsconfig.json |
Node.js / TypeScript |
pom.xml, build.gradle |
Java / Spring |
pyproject.toml, requirements.txt |
Python |
go.mod |
Go |
*.csproj, *.sln |
.NET |
Cargo.toml |
Rust |
Dockerfile, docker-compose.yml |
Containerized |
terraform/, *.tf |
Infrastructure as Code |
helm/, k8s/, charts/ |
Kubernetes |
Multiple package.json / pom.xml |
Monorepo |
nx.json, turbo.json, pnpm-workspace.yaml, lerna.json |
Monorepo tooling |
content/blog/, posts/, .mdx files with frontmatter |
Blog / file-based content |
llms.txt |
AI search optimization |
1b. Detect Project Boundaries
Identify project boundaries — directories that are independent units:
- Monorepo:
apps/, packages/, services/, libs/ with own config files
- Single project: One root config, directories are modules (
src/, app/, internal/)
Build a project map:
Project Root
├── [subproject-1] (type: service, stack: Java Spring Boot)
├── [subproject-2] (type: frontend, stack: Next.js + TypeScript)
├── [subproject-3] (type: infra, stack: Terraform)
└── [shared-lib] (type: library, stack: TypeScript)
1c. Check for Existing Context Files
// turbo
find . -name "AGENTS.md" -o -name "ARCHITECTURE.md" -o -name "TESTING.md" -o -name "FEATURES.md" | head -20
If files exist — read them, note gaps. Create missing files, update outdated ones (with user confirmation).
2. Deep Scan — Iterative
Process one boundary at a time. Scan limits: max 10 boundaries, 20 files per boundary, 3 levels deep. For 100+ file boundaries, summarize from directory listing and configs only.
2a. Per-Boundary Scan Sequence
For each subproject or the root project:
- Config files first —
package.json, pom.xml, pyproject.toml, go.mod, *.csproj, tsconfig.json, .eslintrc, Dockerfile
- Entry points —
main.ts, App.tsx, main.py, Main.java, main.go, Program.cs
- Directory structure — list 2–3 levels deep to understand module organization
- Key patterns — read 1–2 representative files from each major directory to understand conventions:
- Naming patterns (files, classes, functions)
- Import style and module organization
- Error handling patterns
- Testing patterns (find test files)
- CI/CD —
.github/workflows/, Jenkinsfile, .gitlab-ci.yml, cloudbuild.yaml
- Docs —
README.md, docs/, CONTRIBUTING.md
- Content — two patterns to detect:
- Static content files —
static-content/, data/ dirs with TS/JS exports. Map content file → sections → consuming pages
- File-based content (blog/docs) —
content/blog/, posts/, MDX/MD directories. Read 1-2 sample files to extract: frontmatter format (all fields, types, required/optional), file naming convention, cover image path pattern, tags/categories, discovery assets (llms.txt, sitemap config, RSS feed)
- UI conventions — grep for icon libs (
lucide, solar, phosphor), animation libs (framer-motion, gsap), component libs (shadcn, radix, mui), icon registries
- AI tooling —
.codeiumignore, .cursorignore, .gitignore — paths AI tools cannot access
2b. Identify Significant Directories
Identify directories warranting their own scoped AGENTS.md. Criteria (any one): 10+ files with distinct responsibility, clear architectural layer, different conventions than parent, public API surface, generated code, infrastructure code.
Common significant directories:
| Stack |
Significant Directories |
| Java Spring Boot |
controller/, service/, repository/, model/, config/, exception/ |
| Next.js / React |
app/, components/, lib/, hooks/, api/, middleware/ |
| FastAPI / Python |
routers/, services/, models/, schemas/, dependencies/ |
| Go |
cmd/, internal/, pkg/, handler/, store/, middleware/ |
| .NET |
Controllers/, Services/, Models/, Data/, Middleware/ |
3. Generate Root AGENTS.md
Use the matching stack-specific template from .codex/templates/ as a starting point. If no stack matches, use .codex/templates/universal-agents.template.md. Fill in all sections based on deep scan results from Step 2.
Critical rules:
- State the tech stack explicitly — this drives Codex role selection and overlay activation
- Include real setup commands — extracted from config files and CI, copy-pastable
- Link to
ARCHITECTURE.md and TESTING.md in the Architecture reference and Testing Instructions sections
- Map content architecture (if applicable) — which content files drive which pages. Prevents repeated
code_search during content edits
- Document UI conventions (if applicable) — icon set + variant + registry, animation library, component library
- Document blog conventions (if applicable) — frontmatter format, file naming, discovery assets. Enables
blog-post skill workflow
- Keep concise — avoid repeating what scoped AGENTS.md files will cover
4. Generate ARCHITECTURE.md
Apply system-architect role for this step. The system architect owns the ARCHITECTURE.md file — creation, updates, and reviews.
Use templates/architecture.template.md as the starting point. Fill in all 11 sections based on the deep scan results from Step 2.
Rules:
- Mermaid/ASCII diagrams for all visual elements
- Document what exists now, not aspirations. Include versions
- Focus on relationships and data flows
- Monorepos: Root ARCHITECTURE.md (system-wide) + per-subproject for each service with own build config. Skip doc-only, config-only, type-only dirs
5. Generate TESTING.md
Apply qa-engineer role for this step. The QA engineer owns the TESTING.md file — creation, updates, and reviews.
Use templates/testing.template.md as the starting point. Fill in all sections based on the deep scan results from Step 2.
5a. Root TESTING.md
Create TESTING.md at the project root using templates/testing.template.md (root template section). Fill in all placeholders based on deep scan results from Step 2. All sections in the template are required — remove only those marked with <!-- Remove ... --> comments.
Key data sources: test config files → test types and commands; CI pipeline → pipeline stages; directory listing → test organization; .env.example → credential structure.
5b. Per-Service TESTING.md (Monorepos)
For each subproject/service identified in Step 1b, create a scoped TESTING.md using templates/testing.template.md (per-service template section at the bottom of the file).
Rules:
- Include actual commands — copy-pastable, tested
- Reference root
.env for credentials (test_ prefixed vars), do not duplicate
- List key test scenarios for critical paths (auth, payments, data mutations)
- Keep service-specific — do not repeat root TESTING.md content
5c. Single-Project (Non-Monorepo)
For single-project repos, create only root TESTING.md (no per-service files). Include all service-level detail directly in the root file.
6. Generate Scoped AGENTS.md Files
For each significant directory identified in Step 2b, create a scoped AGENTS.md:
# AGENTS.md
## Purpose
[1 sentence: what this directory contains and its role in the architecture]
## Conventions
[Directory-specific patterns, naming, file organization]
## Key Files
[Important files with brief descriptions]
## Patterns
[Code patterns used in this directory — how to add new items]
## Testing
[How to test code in this directory specifically]
## Do NOT
[Directory-specific anti-patterns and constraints]
Rules for scoped AGENTS.md:
- Never repeat root AGENTS.md content — reference it if needed
- Be directory-specific — only include information relevant to THIS directory
- Include "how to add new X" — the most common operation in each directory
- Keep it short — 20–50 lines. Developers read these frequently
- State constraints — what should NOT be in this directory
Example
src/controllers/AGENTS.md — Purpose, naming convention ({Resource}Controller.java), injection rules (constructor, never repositories directly), validation (@Valid), "Adding a New Controller" steps.
7. Review and Confirm
Present a summary of all files to be created:
## Project Init Summary
### Files to create:
- [ ] AGENTS.md (root) — [X lines]
- [ ] ARCHITECTURE.md (root) — [X lines]
- [ ] TESTING.md (root) — [X lines]
- [ ] [service-1]/TESTING.md — [X lines] (monorepo only)
- [ ] [service-2]/TESTING.md — [X lines] (monorepo only)
- [ ] src/controllers/AGENTS.md — [X lines]
- [ ] src/services/AGENTS.md — [X lines]
- [ ] ...
### Project map:
[project boundary diagram from Step 1b]
### Tech stack detected:
[list of technologies, frameworks, tools]
Wait for user APPROVE before writing files. User may skip directories, add undetected ones, or adjust content.
8. Write Files
After approval, create all files. For each file:
- Write the content
- Verify it was created successfully
- Report any issues
If updating existing files — show the diff and request confirmation.
9. Verify
After all files are created:
// turbo
find . -name "AGENTS.md" -o -name "ARCHITECTURE.md" -o -name "TESTING.md" | sort
Verify:
Integration
- Precedes: All other workflows — run this first on a new project
- Templates:
.codex/templates/*-agents.template.md, .codex/templates/architecture.template.md, .codex/templates/testing.template.md
- Roles:
system-architect role (ARCHITECTURE.md creation/review), qa-engineer role (TESTING.md creation/review), cloud-architect role (cloud infrastructure context), devops-architect role (CI/CD architecture context)
- Skills:
test-strategy skill (test strategy, coverage targets)
- Enables:
plan skill, feature-dev skill, bugfix skill, test-local skill, run-tests skill
1---2name: project-init3description: Initialize AI context for an existing project — deep scan the codebase, detect tech stack, identify subprojects and major modules, generate root `AGENTS.md`, `ARCHITECTURE.md`, `TESTING.md`, and directory-scoped `AGENTS.md` files for subprojects and significant directories. Works with monorepos, polyglot projects, and large codebases via iterative scanning.4---56# Project Init78Deep-scan an existing project and generate AI context files (`AGENTS.md`, `ARCHITECTURE.md`, `TESTING.md`) for the root and all significant subprojects. After completion, the runtime has the context it needs: tech stack, conventions, structure, setup, testing, security.910## 1. Initial Reconnaissance1112### 1a. Root Structure Scan1314```15// turbo16ls -la # or Get-ChildItem on Windows17```1819Identify stack signals:2021| Signal | Indicates |22|---|---|23| `package.json`, `tsconfig.json` | Node.js / TypeScript |24| `pom.xml`, `build.gradle` | Java / Spring |25| `pyproject.toml`, `requirements.txt` | Python |26| `go.mod` | Go |27| `*.csproj`, `*.sln` | .NET |28| `Cargo.toml` | Rust |29| `Dockerfile`, `docker-compose.yml` | Containerized |30| `terraform/`, `*.tf` | Infrastructure as Code |31| `helm/`, `k8s/`, `charts/` | Kubernetes |32| Multiple `package.json` / `pom.xml` | Monorepo |33| `nx.json`, `turbo.json`, `pnpm-workspace.yaml`, `lerna.json` | Monorepo tooling |34| `content/blog/`, `posts/`, `.mdx` files with frontmatter | Blog / file-based content |35| `llms.txt` | AI search optimization |3637### 1b. Detect Project Boundaries3839Identify **project boundaries** — directories that are independent units:40- **Monorepo**: `apps/`, `packages/`, `services/`, `libs/` with own config files41- **Single project**: One root config, directories are modules (`src/`, `app/`, `internal/`)4243Build a **project map**:4445```46Project Root47├── [subproject-1] (type: service, stack: Java Spring Boot)48├── [subproject-2] (type: frontend, stack: Next.js + TypeScript)49├── [subproject-3] (type: infra, stack: Terraform)50└── [shared-lib] (type: library, stack: TypeScript)51```5253### 1c. Check for Existing Context Files5455```56// turbo57find . -name "AGENTS.md" -o -name "ARCHITECTURE.md" -o -name "TESTING.md" -o -name "FEATURES.md" | head -2058```5960If files exist — read them, note gaps. Create missing files, update outdated ones (with user confirmation).6162## 2. Deep Scan — Iterative6364Process one boundary at a time. **Scan limits**: max 10 boundaries, 20 files per boundary, 3 levels deep. For 100+ file boundaries, summarize from directory listing and configs only.6566### 2a. Per-Boundary Scan Sequence6768For each subproject or the root project:69701. **Config files first** — `package.json`, `pom.xml`, `pyproject.toml`, `go.mod`, `*.csproj`, `tsconfig.json`, `.eslintrc`, `Dockerfile`712. **Entry points** — `main.ts`, `App.tsx`, `main.py`, `Main.java`, `main.go`, `Program.cs`723. **Directory structure** — list 2–3 levels deep to understand module organization734. **Key patterns** — read 1–2 representative files from each major directory to understand conventions:74 - Naming patterns (files, classes, functions)75 - Import style and module organization76 - Error handling patterns77 - Testing patterns (find test files)785. **CI/CD** — `.github/workflows/`, `Jenkinsfile`, `.gitlab-ci.yml`, `cloudbuild.yaml`796. **Docs** — `README.md`, `docs/`, `CONTRIBUTING.md`807. **Content** — two patterns to detect:81 - **Static content files** — `static-content/`, `data/` dirs with TS/JS exports. Map content file → sections → consuming pages82 - **File-based content (blog/docs)** — `content/blog/`, `posts/`, MDX/MD directories. Read 1-2 sample files to extract: frontmatter format (all fields, types, required/optional), file naming convention, cover image path pattern, tags/categories, discovery assets (`llms.txt`, sitemap config, RSS feed)838. **UI conventions** — grep for icon libs (`lucide`, `solar`, `phosphor`), animation libs (`framer-motion`, `gsap`), component libs (`shadcn`, `radix`, `mui`), icon registries849. **AI tooling** — `.codeiumignore`, `.cursorignore`, `.gitignore` — paths AI tools cannot access8586### 2b. Identify Significant Directories8788Identify directories warranting their own scoped `AGENTS.md`. **Criteria** (any one): 10+ files with distinct responsibility, clear architectural layer, different conventions than parent, public API surface, generated code, infrastructure code.8990**Common significant directories:**9192| Stack | Significant Directories |93|---|---|94| Java Spring Boot | `controller/`, `service/`, `repository/`, `model/`, `config/`, `exception/` |95| Next.js / React | `app/`, `components/`, `lib/`, `hooks/`, `api/`, `middleware/` |96| FastAPI / Python | `routers/`, `services/`, `models/`, `schemas/`, `dependencies/` |97| Go | `cmd/`, `internal/`, `pkg/`, `handler/`, `store/`, `middleware/` |98| .NET | `Controllers/`, `Services/`, `Models/`, `Data/`, `Middleware/` |99100## 3. Generate Root AGENTS.md101102Use the matching stack-specific template from `.codex/templates/` as a starting point. If no stack matches, use `.codex/templates/universal-agents.template.md`. Fill in all sections based on deep scan results from Step 2.103104**Critical rules:**105- State the **tech stack explicitly** — this drives Codex role selection and overlay activation106- Include **real setup commands** — extracted from config files and CI, copy-pastable107- Link to `ARCHITECTURE.md` and `TESTING.md` in the Architecture reference and Testing Instructions sections108- **Map content architecture** (if applicable) — which content files drive which pages. Prevents repeated `code_search` during content edits109- **Document UI conventions** (if applicable) — icon set + variant + registry, animation library, component library110- **Document blog conventions** (if applicable) — frontmatter format, file naming, discovery assets. Enables `blog-post` skill workflow111- Keep **concise** — avoid repeating what scoped AGENTS.md files will cover112113## 4. Generate ARCHITECTURE.md114115**Apply `system-architect` role** for this step. The system architect owns the ARCHITECTURE.md file — creation, updates, and reviews.116117Use `templates/architecture.template.md` as the starting point. Fill in all 11 sections based on the deep scan results from Step 2.118119**Rules:**120- Mermaid/ASCII diagrams for all visual elements121- Document what exists now, not aspirations. Include versions122- Focus on relationships and data flows123- **Monorepos**: Root ARCHITECTURE.md (system-wide) + per-subproject for each service with own build config. Skip doc-only, config-only, type-only dirs124125## 5. Generate TESTING.md126127**Apply `qa-engineer` role** for this step. The QA engineer owns the TESTING.md file — creation, updates, and reviews.128129Use `templates/testing.template.md` as the starting point. Fill in all sections based on the deep scan results from Step 2.130131### 5a. Root TESTING.md132133Create `TESTING.md` at the project root using `templates/testing.template.md` (root template section). Fill in all placeholders based on deep scan results from Step 2. All sections in the template are required — remove only those marked with `<!-- Remove ... -->` comments.134135**Key data sources**: test config files → test types and commands; CI pipeline → pipeline stages; directory listing → test organization; `.env.example` → credential structure.136137### 5b. Per-Service TESTING.md (Monorepos)138139For each subproject/service identified in Step 1b, create a scoped `TESTING.md` using `templates/testing.template.md` (per-service template section at the bottom of the file).140141**Rules:**142- Include actual commands — copy-pastable, tested143- Reference root `.env` for credentials (`test_` prefixed vars), do not duplicate144- List key test scenarios for critical paths (auth, payments, data mutations)145- Keep service-specific — do not repeat root TESTING.md content146147### 5c. Single-Project (Non-Monorepo)148149For single-project repos, create only root `TESTING.md` (no per-service files). Include all service-level detail directly in the root file.150151## 6. Generate Scoped AGENTS.md Files152153For each significant directory identified in Step 2b, create a scoped `AGENTS.md`:154155```markdown156# AGENTS.md157158## Purpose159[1 sentence: what this directory contains and its role in the architecture]160161## Conventions162[Directory-specific patterns, naming, file organization]163164## Key Files165[Important files with brief descriptions]166167## Patterns168[Code patterns used in this directory — how to add new items]169170## Testing171[How to test code in this directory specifically]172173## Do NOT174[Directory-specific anti-patterns and constraints]175```176177**Rules for scoped AGENTS.md:**178- **Never repeat root AGENTS.md content** — reference it if needed179- **Be directory-specific** — only include information relevant to THIS directory180- **Include "how to add new X"** — the most common operation in each directory181- **Keep it short** — 20–50 lines. Developers read these frequently182- **State constraints** — what should NOT be in this directory183184### Example185186**`src/controllers/AGENTS.md`** — Purpose, naming convention (`{Resource}Controller.java`), injection rules (constructor, never repositories directly), validation (`@Valid`), "Adding a New Controller" steps.187188## 7. Review and Confirm189190Present a summary of all files to be created:191192```193## Project Init Summary194195### Files to create:196- [ ] AGENTS.md (root) — [X lines]197- [ ] ARCHITECTURE.md (root) — [X lines]198- [ ] TESTING.md (root) — [X lines]199- [ ] [service-1]/TESTING.md — [X lines] (monorepo only)200- [ ] [service-2]/TESTING.md — [X lines] (monorepo only)201- [ ] src/controllers/AGENTS.md — [X lines]202- [ ] src/services/AGENTS.md — [X lines]203- [ ] ...204205### Project map:206[project boundary diagram from Step 1b]207208### Tech stack detected:209[list of technologies, frameworks, tools]210```211212**Wait for user APPROVE before writing files.** User may skip directories, add undetected ones, or adjust content.213214## 8. Write Files215216After approval, create all files. For each file:2171. Write the content2182. Verify it was created successfully2193. Report any issues220221If updating existing files — show the diff and request confirmation.222223## 9. Verify224225After all files are created:226227```228// turbo229find . -name "AGENTS.md" -o -name "ARCHITECTURE.md" -o -name "TESTING.md" | sort230```231232Verify:233- [ ] Root `AGENTS.md` exists and contains correct tech stack234- [ ] Root `AGENTS.md` links to `TESTING.md` in Testing Instructions section235- [ ] Root and per-subproject `ARCHITECTURE.md` files exist236- [ ] Root `TESTING.md` exists with all test types, commands, infrastructure237- [ ] Per-service `TESTING.md` files exist for each subproject (monorepos)238- [ ] All significant directories have scoped `AGENTS.md`239- [ ] No redundancy between root and scoped files240- [ ] All test commands are accurate and copy-pastable241- [ ] No secrets, PII, or hardcoded credentials in any file (especially `.env` test values)242243## Integration244245- **Precedes**: All other workflows — run this first on a new project246- **Templates**: `.codex/templates/*-agents.template.md`, `.codex/templates/architecture.template.md`, `.codex/templates/testing.template.md`247- **Roles**: `system-architect` role (ARCHITECTURE.md creation/review), `qa-engineer` role (TESTING.md creation/review), `cloud-architect` role (cloud infrastructure context), `devops-architect` role (CI/CD architecture context)248- **Skills**: `test-strategy` skill (test strategy, coverage targets)249- **Enables**: `plan` skill, `feature-dev` skill, `bugfix` skill, `test-local` skill, `run-tests` skill