Skip to content

Commit dd19997

Browse files
refactor(docs): code analysis engine
changes: - file: _registry_adapters.py area: docs added: [_generate_html, IndexHtmlAdapter] modified: [should_run, run] stats: lines: "+38238/-4561 (net +33677)" files: 13 complexity: "Large structural change (normalized)"
1 parent ed701a9 commit dd19997

File tree

20 files changed

+38265
-4566
lines changed

20 files changed

+38265
-4566
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [3.0.21] - 2026-03-15
11+
12+
### Docs
13+
- Update project/context.md
14+
15+
### Test
16+
- Update tests/project/dashboard.html
17+
- Update tests/project/project.yaml
18+
19+
### Other
20+
- Update code2docs/generators/_registry_adapters.py
21+
- Update project.sh
22+
- Update project/analysis.json
23+
- Update project/analysis.toon
24+
- Update project/analysis.yaml
25+
- Update project/calls.mmd
26+
- Update project/dashboard.html
27+
- Update project/flow.mmd
28+
- Update project/flow.toon
29+
- Update project/map.toon
30+
- ... and 2 more files
31+
1032
## [3.0.20] - 2026-03-09
1133

1234
### Docs

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# code2docs
22

3-
![version](https://img.shields.io/badge/version-3.0.20-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![docs](https://img.shields.io/badge/docs-auto--generated-blueviolet)
3+
![version](https://img.shields.io/badge/version-3.0.21-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![docs](https://img.shields.io/badge/docs-auto--generated-blueviolet)
44

55
> Auto-generate and sync project documentation from source code analysis.
66
@@ -140,7 +140,7 @@ code2docs can update only specific sections of an existing README using markers:
140140
```markdown
141141
<!-- code2docs:start --># code2docs
142142

143-
![version](https://img.shields.io/badge/version-3.0.20-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![coverage](https://img.shields.io/badge/coverage-unknown-lightgrey) ![functions](https://img.shields.io/badge/functions-276-green)
143+
![version](https://img.shields.io/badge/version-3.0.21-blue) ![python](https://img.shields.io/badge/python-%3E%3D3.9-blue) ![coverage](https://img.shields.io/badge/coverage-unknown-lightgrey) ![functions](https://img.shields.io/badge/functions-276-green)
144144
> **276** functions | **57** classes | **51** files | CC̄ = 3.8
145145

146146
> Auto-generated project documentation from source code analysis.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.20
1+
3.0.21

code2docs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
README.md, API references, module docs, examples, and architecture diagrams.
66
"""
77

8-
__version__ = "3.0.20"
8+
__version__ = "3.0.21"
99
__author__ = "Tom Sapletta"
1010

1111
from .config import Code2DocsConfig

code2docs/generators/_registry_adapters.py

Lines changed: 158 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,25 +250,178 @@ def should_run(self, *, readme_only: bool = False) -> bool:
250250

251251
def run(self, ctx: GenerateContext) -> Optional[str]:
252252
from .org_readme_gen import OrgReadmeGenerator
253-
253+
254254
org_name = getattr(self.config, 'org_name', '')
255255
if not org_name:
256256
return None
257-
257+
258258
gen = OrgReadmeGenerator(self.config, str(ctx.project), org_name)
259259
content = gen.generate()
260-
260+
261261
if ctx.dry_run:
262262
click.echo(f"\n--- {org_name} README ({len(content)} chars) ---")
263263
preview = content[:500] + "..." if len(content) > 500 else content
264264
click.echo(preview)
265265
return None
266-
266+
267267
readme_path = ctx.docs_dir / "README.md"
268268
gen.write(str(readme_path), content)
269269
return f"✅ {readme_path.relative_to(ctx.project)}"
270270

271271

272+
class IndexHtmlAdapter(BaseGenerator):
273+
"""Adapter for generating index.html for GitHub Pages browsing."""
274+
name = "index_html"
275+
276+
def should_run(self, *, readme_only: bool = False) -> bool:
277+
return not readme_only
278+
279+
def run(self, ctx: GenerateContext) -> Optional[str]:
280+
if ctx.dry_run:
281+
return "[dry-run] docs/index.html"
282+
283+
content = self._generate_html(ctx)
284+
(ctx.docs_dir / "index.html").write_text(content, encoding="utf-8")
285+
return "✅ docs/index.html"
286+
287+
def _generate_html(self, ctx: GenerateContext) -> str:
288+
project_name = self.config.project_name or ctx.project.name
289+
repo_url = self.config.repo_url
290+
291+
files = []
292+
if (ctx.docs_dir / "README.md").exists():
293+
files.append(("README.md", "Project Overview", "📖"))
294+
if (ctx.docs_dir / "getting-started.md").exists():
295+
files.append(("getting-started.md", "Getting Started", "🚀"))
296+
if (ctx.docs_dir / "api.md").exists():
297+
files.append(("api.md", "API Reference", "📚"))
298+
if (ctx.docs_dir / "modules.md").exists():
299+
files.append(("modules.md", "Module Documentation", "📦"))
300+
if (ctx.docs_dir / "architecture.md").exists():
301+
files.append(("architecture.md", "Architecture", "🏗️"))
302+
if (ctx.docs_dir / "dependency-graph.md").exists():
303+
files.append(("dependency-graph.md", "Dependency Graph", "🔗"))
304+
if (ctx.docs_dir / "coverage.md").exists():
305+
files.append(("coverage.md", "Code Coverage", "📊"))
306+
if (ctx.docs_dir / "api-changelog.md").exists():
307+
files.append(("api-changelog.md", "API Changelog", "📝"))
308+
if (ctx.docs_dir / "configuration.md").exists():
309+
files.append(("configuration.md", "Configuration", "⚙️"))
310+
if (ctx.docs_dir / "CONTRIBUTING.md").exists():
311+
files.append(("CONTRIBUTING.md", "Contributing Guide", "🤝"))
312+
if (ctx.docs_dir / "examples").is_dir():
313+
files.append(("examples/", "Examples", "💡"))
314+
315+
github_link = f'<a href="{repo_url}" class="github-link" target="_blank" rel="noopener">View on GitHub</a>' if repo_url else ""
316+
317+
files_html = "\n".join(
318+
f'<a href="{href}" class="doc-card"><span class="icon">{icon}</span><span class="title">{title}</span></a>'
319+
for href, title, icon in files
320+
)
321+
322+
return f'''<!DOCTYPE html>
323+
<html lang="en">
324+
<head>
325+
<meta charset="UTF-8">
326+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
327+
<title>{project_name} - Documentation</title>
328+
<style>
329+
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
330+
body {{
331+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
332+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
333+
min-height: 100vh;
334+
padding: 40px 20px;
335+
}}
336+
.container {{
337+
max-width: 900px;
338+
margin: 0 auto;
339+
}}
340+
.header {{
341+
text-align: center;
342+
margin-bottom: 40px;
343+
color: white;
344+
}}
345+
.header h1 {{
346+
font-size: 2.5rem;
347+
margin-bottom: 10px;
348+
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
349+
}}
350+
.header p {{
351+
font-size: 1.1rem;
352+
opacity: 0.9;
353+
}}
354+
.github-link {{
355+
display: inline-block;
356+
margin-top: 15px;
357+
padding: 10px 20px;
358+
background: rgba(255,255,255,0.2);
359+
color: white;
360+
text-decoration: none;
361+
border-radius: 25px;
362+
transition: background 0.3s;
363+
}}
364+
.github-link:hover {{ background: rgba(255,255,255,0.3); }}
365+
.docs-grid {{
366+
display: grid;
367+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
368+
gap: 20px;
369+
}}
370+
.doc-card {{
371+
background: white;
372+
border-radius: 12px;
373+
padding: 25px;
374+
text-decoration: none;
375+
color: #333;
376+
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
377+
transition: transform 0.2s, box-shadow 0.2s;
378+
display: flex;
379+
align-items: center;
380+
gap: 15px;
381+
}}
382+
.doc-card:hover {{
383+
transform: translateY(-3px);
384+
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
385+
}}
386+
.doc-card .icon {{
387+
font-size: 2rem;
388+
flex-shrink: 0;
389+
}}
390+
.doc-card .title {{
391+
font-size: 1.1rem;
392+
font-weight: 600;
393+
}}
394+
.footer {{
395+
text-align: center;
396+
margin-top: 40px;
397+
color: rgba(255,255,255,0.7);
398+
font-size: 0.9rem;
399+
}}
400+
@media (max-width: 600px) {{
401+
.header h1 {{ font-size: 1.8rem; }}
402+
.docs-grid {{ grid-template-columns: 1fr; }}
403+
}}
404+
</style>
405+
</head>
406+
<body>
407+
<div class="container">
408+
<div class="header">
409+
<h1>{project_name}</h1>
410+
<p>Generated Documentation</p>
411+
{github_link}
412+
</div>
413+
<div class="docs-grid">
414+
{files_html}
415+
</div>
416+
<div class="footer">
417+
Generated with <a href="https://github.com/wronai/code2docs" style="color: rgba(255,255,255,0.9);">code2docs</a>
418+
</div>
419+
</div>
420+
</body>
421+
</html>'''
422+
423+
424+
272425
ALL_ADAPTERS = [
273426
ReadmeGeneratorAdapter,
274427
ApiReferenceAdapter,
@@ -284,4 +437,5 @@ def run(self, ctx: GenerateContext) -> Optional[str]:
284437
MkDocsAdapter,
285438
Code2LlmAdapter,
286439
OrgReadmeAdapter,
440+
IndexHtmlAdapter,
287441
]

project.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
clear
33
pip install glon --upgrade
44
pip install goal --upgrade
5+
pip install code2logic --upgrade
56
pip install code2llm --upgrade
6-
#pip install code2docs --upgrade
7-
pip install -e .
8-
code2docs ./code2docs --output ../docs/
97
#code2llm ./ -f toon,evolution,code2logic,project-yaml -o ./project --no-chunk
108
code2llm ./ -f all -o ./project --no-chunk
119
#code2llm report --format all # → all views
1210
rm project/analysis.json
1311
rm project/analysis.yaml
1412

13+
pip install code2docs --upgrade
14+
code2docs ./ --readme-only
1515

16-
#code2docs ./code2docs --readme-only # Tylko README
17-
#code2docs ./code2docs --dry-run # Podgląd bez zapisu
18-
#code2docs sync ./code2docs # Tylko zmienione pliki
19-
#code2docs check ./code2docs # Sprawdź kompletność docs
16+
#code2docs ./ --dry-run # Podgląd bez zapisu
17+
#code2docs sync ./ # Tylko zmienione pliki
18+
#code2docs check ./ # Sprawdź kompletność docs

project/analysis.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

project/analysis.toon

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# CC̄=4.4 | critical:27/295 | dups:0 | cycles:1
33

44
HEALTH[11]:
5-
🟡 CC _extract_project_metadata CC=29 (limit:15)
65
🟡 CC _render_first_usage CC=15 (limit:15)
76
🟡 CC _generate_intro CC=16 (limit:15)
87
🟡 CC parse_gitignore CC=15 (limit:15)
@@ -13,6 +12,7 @@ HEALTH[11]:
1312
🟡 CC _render_module_section CC=25 (limit:15)
1413
🟡 CC _generate_advanced CC=22 (limit:15)
1514
🟡 CC _render_code_style CC=16 (limit:15)
15+
🟡 CC _extract_project_metadata CC=29 (limit:15)
1616

1717
REFACTOR[2]:
1818
1. split 11 high-CC methods (CC>15)
@@ -94,13 +94,13 @@ FUNCTIONS (CC≥10, 27 of 255):
9494
11.0 ApiReferenceGenerator.generate 10n 2exit loops+cond+ret
9595
11.0 ExamplesGenerator._example_from_type 18n 7exit cond+ret
9696
11.0 ArchitectureGenerator._generate_class_diagram 12n 2exit loops+cond+ret
97-
10.0 ConfigDocsGenerator._render_section 14n 2exit loops+cond+ret
9897
10.0 GettingStartedGenerator._render_prerequisites 15n 2exit cond+ret
98+
10.0 ConfigDocsGenerator._render_section 14n 2exit loops+cond+ret
9999
10.0 ApiReferenceGenerator._has_content 6n 3exit cond+ret
100-
10.0 _run_check 11n 1exit loops+cond
100+
10.0 Code2DocsConfig.from_yaml 20n 3exit cond+ret
101101
10.0 ApiChangelogGenerator._diff_functions 9n 1exit loops+cond
102102
10.0 ApiChangelogGenerator._diff_classes 15n 1exit loops+cond
103-
10.0 Code2DocsConfig.from_yaml 20n 3exit cond+ret
103+
10.0 _run_check 11n 1exit loops+cond
104104

105105
summary:
106106
critical(≥10): 27 | high(5-10): 58 | medium(2-5): 100 | low(<2): 70
@@ -143,8 +143,8 @@ CLASSES:
143143
Code2LlmGenerator █████ 4m CC̄=6.2 max=17 !!
144144
Code2DocsConfig █████ 4m CC̄=4.0 max=10
145145
BaseGenerator ████ 3m CC̄=1.0 max=1
146-
ProjectScanner ████ 3m CC̄=1.3 max=2
147146
EndpointDetector ████ 3m CC̄=4.0 max=5
147+
ProjectScanner ████ 3m CC̄=1.3 max=2
148148
Updater ██ 2m CC̄=3.0 max=4
149149
ReadmeGeneratorAdapter ██ 2m CC̄=2.5 max=4
150150
ApiReferenceAdapter ██ 2m CC̄=2.0 max=2
@@ -161,16 +161,16 @@ CLASSES:
161161
Code2LlmAdapter ██ 2m CC̄=4.0 max=7
162162
OrgReadmeAdapter ██ 2m CC̄=3.0 max=4
163163
ChangeInfo █ 1m CC̄=1.0 max=1
164-
DefaultGroup █ 1m CC̄=4.0 max=4
165164
LLMConfig █ 1m CC̄=1.0 max=1
165+
DefaultGroup █ 1m CC̄=4.0 max=4
166166
GenerateContext 0m CC̄=0.0 max=0.0
167167
ChangelogEntry 0m CC̄=0.0 max=0.0
168-
ApiChange 0m CC̄=0.0 max=0.0
169168
ReadmeConfig 0m CC̄=0.0 max=0.0
170169
DocsConfig 0m CC̄=0.0 max=0.0
171170
ExamplesConfig 0m CC̄=0.0 max=0.0
172171
SyncConfig 0m CC̄=0.0 max=0.0
173172
Code2LlmConfig 0m CC̄=0.0 max=0.0
173+
ApiChange 0m CC̄=0.0 max=0.0
174174
DependencyInfo 0m CC̄=0.0 max=0.0
175175
ProjectDependencies 0m CC̄=0.0 max=0.0
176176
Endpoint 0m CC̄=0.0 max=0.0
@@ -236,6 +236,18 @@ Thi...
236236
e: ConfigDocsGenerator
237237
ConfigDocsGenerator # Generate docs/configuration.md from Code2DocsConfig dataclas...
238238
__init__(2) CC=1.0
239+
code2docs/config.py:
240+
e: ReadmeConfig,DocsConfig,ExamplesConfig,SyncConfig,Code2LlmConfig,LLMConfig,Code2DocsConfig
241+
ReadmeConfig # Configuration for README generation....
242+
DocsConfig # Configuration for docs/ generation....
243+
ExamplesConfig # Configuration for examples/ generation....
244+
SyncConfig # Configuration for synchronization....
245+
Code2LlmConfig # Configuration for code2llm analysis generation....
246+
LLMConfig # Configuration for optional LLM-assisted documentation genera...
247+
from_env(0) CC=1.0
248+
Code2DocsConfig # Main configuration for code2docs....
249+
__post_init__(0) CC=2.0
250+
→ _detect_repo_url(-1) CC=3.0
239251
code2docs/cli.py:
240252
e: DefaultGroup,main,generate,sync,watch,init,check,diff,_load_config,_run_generate,_run_sync,_run_watch,_run_check,_run_diff
241253
DefaultGroup # Click Group that routes unknown subcommands to 'generate'....
@@ -254,18 +266,6 @@ Thi...
254266
_run_watch(project_path,config)
255267
_run_check(project_path,config,target)
256268
_run_diff(project_path,config)
257-
code2docs/config.py:
258-
e: ReadmeConfig,DocsConfig,ExamplesConfig,SyncConfig,Code2LlmConfig,LLMConfig,Code2DocsConfig
259-
ReadmeConfig # Configuration for README generation....
260-
DocsConfig # Configuration for docs/ generation....
261-
ExamplesConfig # Configuration for examples/ generation....
262-
SyncConfig # Configuration for synchronization....
263-
Code2LlmConfig # Configuration for code2llm analysis generation....
264-
LLMConfig # Configuration for optional LLM-assisted documentation genera...
265-
from_env(0) CC=1.0
266-
Code2DocsConfig # Main configuration for code2docs....
267-
__post_init__(0) CC=2.0
268-
→ _detect_repo_url(-1) CC=3.0
269269
examples/07_web_frameworks.py:
270270
e: detect_flask_endpoints,detect_fastapi_endpoints,generate_api_docs_from_endpoints,create_example_web_apps,document_web_project
271271
detect_flask_endpoints(project_path)

0 commit comments

Comments
 (0)