{% if sync_markers %}<!-- code2docs:start -->{% endif %}
# {{ project_name }}

{% if badges %}{{ badges }}{% endif %}

{% if "overview" in sections %}
> **{{ stats.get('functions_found', 0) }}** functions | **{{ stats.get('classes_found', 0) }}** classes | **{{ stats.get('files_processed', 0) }}** files | CC̄ = {{ avg_complexity }}

{% if project_description %}
{{ project_description }}
{% else %}
> Auto-generated project documentation from source code analysis.
{% endif %}
{% endif %}

{% if author or license or repo_url %}
**Author:** {% if author %}{{ author }}{% else %}Not specified{% endif %}  
**License:** {% if license %}{{ license }}{% if license_file %}[({{ license_file }})](./{{ license_file }}){% endif %}{% else %}Not specified{% endif %}  
{% if repo_url %}**Repository:** [{{ repo_url }}]({{ repo_url }}){% endif %}

{% endif %}

{% if "install" in sections %}
## Installation

### From PyPI

```bash
pip install {{ project_name }}
```

### From Source

```bash
git clone {{ repo_url or '<repository-url>' }}
cd {{ project_name }}
pip install -e .
```

{% if extras %}
### Optional Extras

```bash
{% for extra in extras %}pip install {{ project_name }}[{{ extra.name }}]    # {{ extra.description }}
{% endfor %}
```
{% endif %}
{% endif %}

{% if "quickstart" in sections %}
## Quick Start

### CLI Usage

```bash
# Generate full documentation for your project
{{ project_name }} ./my-project

# Only regenerate README
{{ project_name }} ./my-project --readme-only

# Preview what would be generated (no file writes)
{{ project_name }} ./my-project --dry-run

# Check documentation health
{{ project_name }} check ./my-project

# Sync — regenerate only changed modules
{{ project_name }} sync ./my-project
```

### Python API

```python
from {{ project_name }} import generate_readme, generate_docs, Code2DocsConfig

# Quick: generate README
generate_readme("./my-project")

# Full: generate all documentation
config = Code2DocsConfig(project_name="mylib", verbose=True)
docs = generate_docs("./my-project", config=config)
```
{% endif %}

{% if "generated_output" in sections %}
## Generated Output

When you run `{{ project_name }}`, the following files are produced:

```
<project>/
├── README.md                 # Main project README (auto-generated sections)
├── docs/
│   ├── api.md               # Consolidated API reference
│   ├── modules.md           # Module documentation with metrics
│   ├── architecture.md      # Architecture overview with diagrams
│   ├── dependency-graph.md  # Module dependency graphs
│   ├── coverage.md          # Docstring coverage report
│   ├── getting-started.md   # Getting started guide
│   ├── configuration.md    # Configuration reference
│   └── api-changelog.md    # API change tracking
├── examples/
│   ├── quickstart.py       # Basic usage examples
│   └── advanced_usage.py   # Advanced usage examples
├── CONTRIBUTING.md         # Contribution guidelines
└── mkdocs.yml             # MkDocs site configuration
```
{% endif %}

{% if "config" in sections %}
## Configuration

Create `{{ project_name }}.yaml` in your project root (or run `{{ project_name }} init`):

```yaml
project:
  name: my-project
  source: ./
  output: ./docs/

readme:
  sections:
    - overview
    - install
    - quickstart
    - api
    - structure
  badges:
    - version
    - python
    - coverage
  sync_markers: true

docs:
  api_reference: true
  module_docs: true
  architecture: true
  changelog: true

examples:
  auto_generate: true
  from_entry_points: true

sync:
  strategy: markers    # markers | full | git-diff
  watch: false
  ignore:
    - "tests/"
    - "__pycache__"
```
{% endif %}

{% if "sync_markers" in sections %}
## Sync Markers

{{ project_name }} can update only specific sections of an existing README using HTML comment markers:

```markdown
<!-- {{ project_name }}:start -->
# Project Title
... auto-generated content ...
<!-- {{ project_name }}:end -->
```

Content outside the markers is preserved when regenerating. Enable this with `sync_markers: true` in your configuration.
{% endif %}

{% if "architecture" in sections and module_tree %}
## Architecture

```
{{ project_name }}/
{% for mod_name, mod in modules.items()|list %}{% if not mod_name.startswith('_') %}{% set parts = mod_name.split('.') %}{{ '    ' * (parts|length - 1) }}├── {{ parts[-1] }}{% if mod.is_package %}/{% endif %}
{% endif %}{% endfor %}
```
{% endif %}

{% if "api" in sections %}
## API Overview

{% if public_classes %}
### Classes

{% for name, cls in public_classes.items()|list %}
{% if not cls.name.startswith('_') %}
- **`{{ cls.name }}`** — {{ cls.docstring.split('\n')[0] if cls.docstring else '—' }}
{% endif %}
{% endfor %}

{% endif %}
{% if public_functions %}
### Functions

{% for name, func in public_functions.items()|list %}
{% if not func.name.startswith('_') %}
- `{{ func.name }}({{ func.args[:4]|join(', ') }})`{% if func.returns %} → {{ func.returns }}{% endif %} — {{ func.docstring.split('\n')[0] if func.docstring else '—' }}
{% endif %}
{% endfor %}

{% endif %}
{% endif %}

{% if "structure" in sections and module_tree %}
## Project Structure

{{ module_tree }}
{% endif %}

{% if "requirements" in sections and dependencies %}
## Requirements

{% if dependencies.python_version %}
- Python >= {{ dependencies.python_version }}
{% endif %}
{% if dependencies and dependencies.dependencies %}
{% for dep in dependencies.dependencies %}
- {{ dep.name }}{% if dep.version_spec %} {{ dep.version_spec }}{% endif %}
{% endfor %}
{% endif %}
{% endif %}

{% if "endpoints" in sections and endpoints %}
## API Endpoints

| Method | Path | Handler | Framework |
|--------|------|---------|-----------|
{% for ep in endpoints %}
| `{{ ep.method }}` | `{{ ep.path }}` | `{{ ep.function_name }}` | {{ ep.framework }} |
{% endfor %}
{% endif %}

{% if "contributing" in sections %}
## Contributing

{% if contributors %}
**Contributors:**
{% for contributor in contributors %}
- {{ contributor }}
{% endfor %}
{% endif %}

We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.

### Development Setup

```bash
# Clone the repository
git clone {{ repo_url or '<repository-url>' }}
cd {{ project_name }}

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest
```
{% endif %}

{% if "docs_nav" in sections %}
## Documentation

{% if repo_url %}
- 📖 [Full Documentation]({{ repo_url }}/tree/main/docs) — API reference, module docs, architecture
- 🚀 [Getting Started]({{ repo_url }}/blob/main/docs/getting-started.md) — Quick start guide
- 📚 [API Reference]({{ repo_url }}/blob/main/docs/api.md) — Complete API documentation
- 🔧 [Configuration]({{ repo_url }}/blob/main/docs/configuration.md) — Configuration options
{% else %}
- 📖 [Full Documentation](./docs) — API reference, module docs, architecture
- 🚀 [Getting Started](./docs/getting-started.md) — Quick start guide
- 📚 [API Reference](./docs/api.md) — Complete API documentation
- 🔧 [Configuration](./docs/configuration.md) — Configuration options
{% endif %}
- 💡 [Examples](./examples) — Usage examples and code samples

### Generated Files

| Output | Description | Link |
|--------|-------------|------|
| `README.md` | Project overview (this file) | — |
| `docs/api.md` | Consolidated API reference | [View](./docs/api.md) |
| `docs/modules.md` | Module reference with metrics | [View](./docs/modules.md) |
| `docs/architecture.md` | Architecture with diagrams | [View](./docs/architecture.md) |
| `docs/dependency-graph.md` | Dependency graphs | [View](./docs/dependency-graph.md) |
| `docs/coverage.md` | Docstring coverage report | [View](./docs/coverage.md) |
| `docs/getting-started.md` | Getting started guide | [View](./docs/getting-started.md) |
| `docs/configuration.md` | Configuration reference | [View](./docs/configuration.md) |
| `docs/api-changelog.md` | API change tracking | [View](./docs/api-changelog.md) |
| `CONTRIBUTING.md` | Contribution guidelines | [View](./CONTRIBUTING.md) |
| `examples/` | Usage examples | [Browse](./examples) |
| `mkdocs.yml` | MkDocs configuration | — |
{% endif %}

{% if sync_markers %}<!-- code2docs:end -->{% endif %}
