This directory contains development standards, coding guidelines, and best practices for the Research Project Template system. All code must follow these standards.
Note: Cursor reads the repository root
.cursorrulesfile for IDE/agent routing. Extended editorial standards live indocs/rules/(this directory).
Project paths in examples: default to
projects/templates/template_code_project/. Authoritative activeprojects/names → _generated/active_projects.md (see _generated/README.md).
| File | Purpose | Best For |
|---|---|---|
| AGENTS.md | This file - overview and navigation | Understanding the system |
| README.md | Quick reference guide | Finding quick answers |
| folder_structure.md | Folder structure documentation standard | Understanding folder organization |
| error_handling.md | Error handling and exception patterns | Writing error handling code |
| security.md | Security standards and guidelines | Writing secure code |
| python_logging.md | Logging standards and best practices | Adding logging to code |
| infrastructure_modules.md | Infrastructure module development standards | Creating new infrastructure modules |
| testing_standards.md | Testing patterns and coverage standards | Writing tests with pytest |
| documentation_standards.md | AGENTS.md and README.md writing guide | Writing documentation |
| type_hints_standards.md | Type annotation patterns | Adding type hints |
| llm_standards.md | LLM/Ollama integration patterns | Using local LLMs for research |
| code_style.md | Code formatting and style standards | Writing consistent, readable code |
| git_workflow.md | Git workflow and commit standards | Managing version control |
| api_design.md | API design and interface standards | Creating clean, consistent APIs |
| manuscript_style.md | Manuscript formatting and style standards | Writing research manuscripts |
| reporting.md | Reporting module standards and outputs | Using reporting utilities |
| refactoring.md | Refactoring and modularization standards | Refactoring code with clean breaks |
| memory_and_decision_records.md | Decision memory, ADRs, local agent memory, and RedTeam negative controls | Capturing rationale without stale parallel ledgers |
Layer 1: Infrastructure (Generic, reusable)
- Location:
infrastructure/(root level) - Domain-independent tools
- Reusable across projects
- 60% minimum test coverage required (current % — see coverage-gaps.md)
Layer 2: Project (Specific, customizable)
- Location:
projects/{name}/src/(project-specific code) - Research-specific code
- Uses generic infrastructure utilities
- 90% minimum test coverage required (current % — see COUNTS.md)
- Tests:
projects/{name}/tests/ - Scripts:
projects/{name}/scripts/(thin orchestrators)
- Business logic →
projects/{name}/src/orinfrastructure/ - Orchestration →
scripts/(root, generic) orprojects/{name}/scripts/(project-specific) - No logic in scripts - only coordination
- Testing: 90%+ coverage required (60% infra, 90% project), data only
- Documentation: AGENTS.md + README.md for each directory
- Type Safety: Type hints on all public APIs
- Error Handling: Use custom exception hierarchy
- Logging: Unified logging system throughout
The template provides two pipeline orchestrators with different scope:
Interactive Menu (./run.sh)
- Use for: Full pipeline with optional LLM stages
- Stages: 1-9 (displayed as [1/9] to [9/9], with an initial clean step shown as [0/9])
- Features: Interactive menu, research templates, LLM reviews, translations
- When to use: Full builds, LLM features needed
Python Orchestrator (uv run python scripts/execute_pipeline.py)
- Use for: Core or full pipeline, programmatic execution (
--core-onlyskips LLM stages) - Stages: Default core run is eight executor stages (clean outputs, setup, infrastructure tests, project tests, analysis, PDF rendering, validation, copy outputs). With
--skip-infra, infrastructure tests are omitted (seven stages). Full pipeline adds LLM review and translations before copy; seeexecutor.py(PipelineExecutor._build_stage_list). - Features: Checkpoint/resume; delegates to numbered scripts
scripts/00_*.py–scripts/05_*.pyplus optional06/07where applicable - When to use: Automated environments, CI/CD, or when you want explicit flags instead of the menu
- Start here: Read AGENTS.md (this file) for overview
- Pick your task - Read the appropriate guide:
- Writing code: error_handling.md, python_logging.md, type_hints_standards.md
- Creating modules: infrastructure_modules.md, testing_standards.md
- Writing docs: documentation_standards.md
- Writing manuscripts: manuscript_style.md
- Writing tests: testing_standards.md
- Capturing rationale: memory_and_decision_records.md
- Follow the standards - Apply the patterns and examples from the guide
- Cross-reference - See "See Also" sections for related guides
- Quick lookup: Use README.md for fast pattern references
- Deep dive: Read specific guide files as needed
- Copy patterns: Use code examples from appropriate guide
- Reference: Keep this directory open during development
- ✅ Read relevant rules files in
docs/rules/ - ✅ Understand two-layer architecture
- ✅ Review existing similar code
- ✅ Plan with thin orchestrator pattern
- ✅ Write tests first (TDD)
- ✅ Follow type hints standards
- ✅ Use unified logging
- ✅ Handle errors properly
- ✅ Document as you go
- ✅ Test coverage requirements met (60% infra, 90% project)
- ✅ All tests pass
- ✅ No linter errors
- ✅ Documentation updated
- ✅ AGENTS.md and README.md updated
Key Points:
- Use custom exception hierarchy from
infrastructure/core/exceptions.py - Always chain exceptions with
from - Provide context in exceptions
- Log before raising critical errors
Example:
from infrastructure.core.exceptions import ValidationError
try:
result = process_data(input)
except ValueError as e:
raise ValidationError("Invalid input", context={"input": input}) from eKey Points:
- Use
infrastructure.core.logging.utils.get_logger(__name__) - Log at appropriate levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Include context in log messages
- Use structured logging where possible
Example:
from infrastructure.core.logging.utils import get_logger
logger = get_logger(__name__)
logger.info(f"Processing {count} items")Key Points:
- Generic and domain-independent only
- 60% minimum test coverage required (current % — see coverage-gaps.md)
- AGENTS.md + README.md
- Public API in
__init__.py - Type hints on all functions
- Follow thin orchestrator pattern
- Use custom exceptions from
core.exceptions - Use unified logging from
core.logging.utils
Structure:
flowchart LR
M[infrastructure module]
M --> INIT[__init__.py public API]
M --> CORE[core.py core logic]
M --> CLI[cli.py optional]
M --> CFG[config.py optional]
M --> DOCS[AGENTS README SKILL]
Related Documentation:
- infrastructure/AGENTS.md - Module organization
- infrastructure_modules.md - Development standards
- error_handling.md - Exception patterns
- python_logging.md - Logging standards
Key Points:
- Use isolated Pandoc
$$display blocks or labelled equation environments, depending on the project renderer and reference scheme. - Always label figures, tables, and equations
- Use descriptive labels (e.g.,
fig:convergence_plot,eq:objective) - Reference using
\ref{}for sections/figures/tables,\eqref{}for equations - Place citations before punctuation
- Use relative paths for figures:
../output/figures/
Example:
\begin{equation}
\label{eq:objective}
f(x) = \sum_{i=1}^{n} w_i \phi_i(x)
\end{equation}
As shown in \eqref{eq:objective}, the objective function...Related Documentation:
- manuscript_style.md - manuscript formatting guide
- projects/templates/template_code_project/manuscript/ - Example manuscript (active project)
- docs/usage/markdown-template-guide.md - Markdown guide
- Infrastructure: 60% minimum (current % — see coverage-gaps.md)
- Project code: 90% minimum (current % — see COUNTS.md)
- Integration tests: All critical workflows covered
flowchart TB
T[tests]
T --> INFRA[infra_tests Layer 1]
T --> INTEG[integration cross-layer]
T --> HELP[helpers utilities]
INFRA --> SUB[test_module per package]
- No mocks for core logic - use data
- Test behavior, not implementation
- Clear names - test should be self-documenting
- Fast execution - unit tests < 1s each
- Isolated - tests should not depend on each other
Every directory must have:
-
AGENTS.md - Technical documentation
- Purpose and architecture
- Usage examples
- Configuration options
- Testing instructions
- Best practices
-
README.md - Quick reference
- Quick start
- Key features
- Common commands
- Links to detailed docs
Module docstrings:
"""Module description.
Detailed explanation of module purpose and contents.
"""Function docstrings:
def function(arg: str) -> str:
"""One-line summary.
Detailed description.
Args:
arg: Description
Returns:
Description
Raises:
ExceptionType: When this happens
Example:
>>> function("test")
'result'
"""# Standard library
import os
from pathlib import Path
# Third party
import requests
import pytest
# Local infrastructure (Layer 1)
from infrastructure.core.logging.utils import get_logger
from infrastructure.core.exceptions import TemplateError
from infrastructure.documentation import FigureManager
# Local project (Layer 2)
from project.src import module
from project.src.simulation import SimpleSimulationfrom dataclasses import dataclass
import os
@dataclass
class ModuleConfig:
"""Module configuration."""
setting: str = "default"
@classmethod
def from_env(cls) -> "ModuleConfig":
"""Load from environment variables."""
return cls(
setting=os.getenv("MODULE_SETTING", "default")
)from infrastructure.core.logging.utils import get_logger
from infrastructure.core.exceptions import TemplateError
logger = get_logger(__name__)
try:
result = risky_operation()
except SpecificError as e:
logger.error(f"Operation failed: {e}")
raise TemplateError("High-level description") from eflowchart TB
ROOT[template repo]
ROOT --> INFRA[infrastructure Layer 1]
ROOT --> PROJ[projects Layer 2]
ROOT --> SCR[scripts Layer 1]
ROOT --> T[tests Layer 1]
ROOT --> DOC[docs]
ROOT --> RULES[docs rules]
INFRA --> INFRA_SUB[infra packages]
PROJ --> P_NAME[project name]
P_NAME --> P_SUB[src tests scripts manuscript]
- Understand two-layer architecture
- Identify correct layer (infrastructure vs project)
- Review relevant rules files in
docs/rules/ - Plan with thin orchestrator pattern
- Write tests first (TDD)
- Add type hints to all functions
- Use unified logging system
- Handle errors with custom exceptions
- Document as you go
- Test coverage requirements met (60% infra, 90% project)
- All tests pass
- No linter errors
- AGENTS.md - [ ] README.md updated
- Code reviewed against standards
- Integration tests pass
- Root AGENTS.md - System overview
- Infrastructure AGENTS.md - Infrastructure layer
- Projects AGENTS.md - Projects layer
- Documentation Hub - docs hub guide
This directory provides modular development standards. Each file covers specific aspects:
| File | Purpose | Best For |
|---|---|---|
| AGENTS.md | Overview & navigation | Understanding the system |
| README.md | Quick reference | Finding patterns fast |
| folder_structure.md | Folder organization standard | Setting up documentation |
| error_handling.md | Exception patterns | Writing error handling |
| security.md | Security standards | Writing secure code |
| python_logging.md | Logging standards | Adding logging to code |
| infrastructure_modules.md | Infrastructure development | Creating modules |
| testing_standards.md | Testing patterns | Writing tests |
| documentation_standards.md | Documentation guidelines | Writing docs |
| type_hints_standards.md | Type annotation patterns | Adding type hints |
| code_style.md | Code formatting standards | Writing consistent code |
| git_workflow.md | Git workflow standards | Managing version control |
| api_design.md | API design standards | Creating clean APIs |
| llm_standards.md | LLM/Ollama patterns | Using local LLMs |
| manuscript_style.md | Manuscript formatting standards | Writing research manuscripts |
| reporting.md | Reporting module standards | Reporting outputs and dashboards |
The docs/rules/ standards align with and support the main documentation:
For Architecture Decisions: → Check AGENTS.md for decision criteria → Read docs/core/architecture.md for full architectural overview → Consult docs/architecture/thin-orchestrator-summary.md for pattern details
For Infrastructure Development: → Check infrastructure_modules.md for standards → Study infrastructure/AGENTS.md for module organization → Review infrastructure/README.md for quick patterns
For Code Quality: → Check error_handling.md and python_logging.md → Read docs/best-practices/best-practices.md for practices → See docs/operational/error-handling-guide.md for detailed patterns
Quick Reference (< 100 lines)
- README.md - Fast patterns lookup
Medium Details (100-300 lines)
- error_handling.md - Exception patterns
- python_logging.md - Logging standards
- type_hints_standards.md - Type annotation patterns
- code_style.md - Code formatting standards
- git_workflow.md - Git workflow standards
Guides (300-600 lines)
- api_design.md - API design standards
- testing_standards.md - testing guide
- infrastructure_modules.md - Module development guide
- documentation_standards.md - Documentation writing guide
- llm_standards.md - LLM/Ollama integration guide
- manuscript_style.md - Manuscript formatting and style guide
System Overview (400+ lines)
- AGENTS.md - This file - system overview
This directory is maintained as part of the template repository. All updates should:
- Maintain consistency across files
- Update this AGENTS.md when adding new rule files
- Keep README.md in sync with new guides
- Follow the same standards described here
- Ensure cross-references to main documentation are accurate
- Test all code examples in guides
- Keep "See Also" sections current
When creating a new rules file:
- Add entry to Files table in this file
- Add entry to Files section in README.md
- Create "See Also" section linking to related guides
- Include code examples for all patterns
- Test all examples before committing
- Update integration table with main docs
Development Standards:
README.md- Quick reference guide../AGENTS.md- system documentationinfrastructure/AGENTS.md- Infrastructure layer documentationprojects/AGENTS.md- Projects layer documentation
Related Documentation:
docs/core/architecture.md- System architecture overviewdocs/core/workflow.md- Development workflowtests/AGENTS.md- Testing philosophy and guide
Version: 3.3.1 Last Updated: 2026-06-08 Files: 18 (AGENTS.md + README.md + 16 guideline files) Status: All 16 guideline files cross-referenced Updates: All development rules and standards synchronized with docs/