{"id":50472422,"url":"https://github.com/semcod/code2schema","last_synced_at":"2026-06-01T11:03:33.996Z","repository":{"id":355571028,"uuid":"1227812188","full_name":"semcod/code2schema","owner":"semcod","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-04T08:18:25.000Z","size":283,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-04T10:23:15.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semcod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-03T07:38:35.000Z","updated_at":"2026-05-04T08:18:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/semcod/code2schema","commit_stats":null,"previous_names":["semcod/code2schema"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/semcod/code2schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semcod","download_url":"https://codeload.github.com/semcod/code2schema/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semcod%2Fcode2schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33771630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-01T11:03:33.898Z","updated_at":"2026-06-01T11:03:33.989Z","avatar_url":"https://github.com/semcod.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# code2schema\n\n\n## AI Cost Tracking\n\n![PyPI](https://img.shields.io/badge/pypi-costs-blue) ![Version](https://img.shields.io/badge/version-0.1.7-blue) ![Python](https://img.shields.io/badge/python-3.9+-blue) ![License](https://img.shields.io/badge/license-Apache--2.0-green)\n![AI Cost](https://img.shields.io/badge/AI%20Cost-$0.75-orange) ![Human Time](https://img.shields.io/badge/Human%20Time-4.3h-blue) ![Model](https://img.shields.io/badge/Model-openrouter%2Fqwen%2Fqwen3--coder--next-lightgrey)\n\n- 🤖 **LLM usage:** $0.7500 (5 commits)\n- 👤 **Human dev:** ~$430 (4.3h @ $100/h, 30min dedup)\n\nGenerated on 2026-05-07 using [openrouter/qwen/qwen3-coder-next](https://openrouter.ai/qwen/qwen3-coder-next)\n\n---\n\n**Semantic Compiler for Software Systems**\n\nPrzekształca kod Python w model semantyczny CQRS → kontrakty API → graf architektury.\n\n```\nCODE (.py)\n  ⬇  AST extraction (built-in ast)\n  ⬇  CQRS inference (Query / Command / Orchestrator)\n  ⬇  Call Graph (NetworkX)\n  ⬇  Event Model (DDD / Event Sourcing)\n  ⬇  Workflow DAG\n  ⬇  Quality Rules\n  ↓\nJSON schema · .proto · Markdown · GraphML · DOT\n```\n\n## Instalacja\n\n```bash\npip install code2schema\n```\n\nOpcjonalne backendy:\n\n```bash\npip install \"code2schema[proto]\"   # grpcio-tools → kompilacja .proto\npip install \"code2schema[neo4j]\"   # eksport do bazy grafowej\npip install \"code2schema[viz]\"     # pyvis → wizualizacja HTML\npip install \"code2schema[dev]\"     # pytest + ruff + black\n```\n\n## Szybki start\n\n```bash\n# Analiza z auto-generowanymi nazwami plików (w katalogu bieżącym)\ncode2schema /home/tom/github/maskservice/c2004/backend\n# → c2004_schema.json\n\n# Pełna analiza ze wszystkimi formatami wyjściowymi\ncode2schema ./backend --proto --md --html\n# → backend_schema.json\n# → backend_api.proto\n# → backend_report.md\n# → backend_viz.html\n\n# Pełna analiza ze szczegółami\ncode2schema ./backend --proto --md --html --graph-summary --events --cycles\n```\n\nPrzykładowy output:\n\n```\n✅ Gotowe (1.8s)\n   Modules  : 607\n   Functions: 3142\n   Queries  : 1518\n   Commands : 505\n   Orchest. : 1119\n   Workflows: 1118\n   Rules    : 320\n   Graph    : 2922N / 5612E\n   → c2004_schema.json\n   → c2004_api.proto\n   → c2004_report.md\n```\n\n## Test na dużym projekcie (c2004 backend)\n\nAnaliza produkcyjnego projektu IoT (607 modułów, 3142 funkcje):\n\n```bash\ncode2schema /home/tom/github/maskservice/c2004/backend --proto --md --html\n# Pliki generowane w /home/tom/github/maskservice/c2004/ (katalog projektu)\n```\n\n**Wyniki:**\n```\n✅ Gotowe (1.8s)\n   Modules  : 607\n   Functions: 3142\n   Queries  : 1518\n   Commands : 505\n   Orchest. : 1119\n   Workflows: 1118\n   Rules    : 320\n   Graph    : 2922N / 5612E\n   → c2004_schema.json\n   → c2004_api.proto\n   → c2004_report.md\n   → c2004_viz.html\n```\n\n## Dokumentacja i przykłady\n\n- **[Dokumentacja](docs/)** — przykłady użycia CLI i Python API\n  - [CLI examples](docs/examples/cli/basic.sh)\n  - [Python API — basic](docs/examples/api/basic.py)\n  - [Python API — advanced](docs/examples/api/advanced.py)\n  - [Sample outputs](docs/examples/outputs/)\n\nWykryte cykle w architekturze CQRS (do refaktoryzacji):\n- `handle → publish → _execute → publish → handle`\n\n**Wygenerowane artefakty:**\n- `c2004_schema.json` (2.9MB) — pełny model\n- `c2004_api.proto` (188KB) — gRPC contracts\n- `c2004_report.md` (49KB) — podsumowanie jakości\n- `c2004_viz.html` (1.1MB) — **interaktywny graf D3.js** z wyszukiwaniem i filtrowaniem\n\n## Użycie w kodzie\n\n```python\nfrom code2schema import extract_project, analyze\nfrom code2schema.analyzer.graph import build_rich_graph, graph_summary\nfrom code2schema.analyzer.events import infer_event_model\nfrom code2schema.codegen import to_proto, to_markdown\nfrom pathlib import Path\n\n# Ekstrakcja + analiza\nmodules = extract_project(Path(\"./backend\"))\nschema  = analyze(modules)\n\n# CQRS\nprint(f\"Queries:      {len(schema.queries())}\")\nprint(f\"Commands:     {len(schema.commands())}\")\nprint(f\"Orchestrators:{len(schema.orchestrators())}\")\n\n# Graf\nG = build_rich_graph(schema)\nprint(graph_summary(G, schema))\n\n# Event Model (DDD)\nem = infer_event_model(modules)\nprint(em.summary())\n\n# Eksport\nprint(to_proto(schema))\nprint(to_markdown(schema))\n```\n\n## Wizualizacja HTML (`--html`)\n\nInteraktywny graf D3.js z funkcjami:\n- **Kolory ról**: 🟢 Query, 🟠 Command, 🟣 Orchestrator\n- **Wyszukiwanie** — filtruje węzły w czasie rzeczywistym\n- **Hover** — podświetla połączenia (call graph)\n- **Klik** — szczegóły funkcji (fan-out, side effects, reguły jakości)\n- **Filtry** — pokazuj/ukrywaj kategorie ról\n- **Force layout** — przeciąganie węzłów\n\n```bash\ncode2schema ./backend --html viz.html\n# Otwórz w przeglądarce: open viz.html\n```\n\n## Architektura paczki\n\n```\ncode2schema/\n├── core/\n│   ├── models.py       # IR: FunctionIR, ModuleIR, SchemaIR (Pydantic)\n│   └── extractor.py    # AST parser (stdlib ast, bez zależności)\n├── analyzer/\n│   ├── cqrs.py         # CQRS inference + WorkflowDAG + Rules\n│   ├── graph.py        # NetworkX: centrality, hubs, cycles, GraphML/DOT\n│   └── events.py       # DDD / Event Sourcing inference\n├── codegen/\n│   └── __init__.py     # JSON, .proto, Markdown generators\n└── cli.py              # entry point: code2schema \u003cpath\u003e [flags]\n```\n\n## Klasy CQRS\n\n| Rola | Kryterium |\n|------|-----------|\n| `query` | brak side-effectów, fan-out = 0 |\n| `command` | side-effects (IO, network, DB) |\n| `orchestrator` | fan-out ≥ 5 (wywołuje wiele funkcji) |\n\n## Reguły jakości\n\nAutomatycznie generowane:\n\n| ID | Warunek | Akcja |\n|----|---------|-------|\n| `HIGH_FAN_OUT` | fan-out ≥ 10 | refactor_to_service |\n| `LONG_FUNCTION` | lines \u003e 100 | split_function |\n| `QUERY_WITH_SIDE_EFFECTS` | query + IO | separate_command_from_query |\n\n## Graph export\n\nGraphML można otworzyć w **Gephi**, **yEd** lub zaimportować do **Neo4j**.  \nDOT renderuje **Graphviz**: `dot -Tsvg graph.dot -o graph.svg`\n\n## Biblioteki\n\n| Kategoria | Biblioteka | Po co |\n|-----------|-----------|-------|\n| Parsing | `ast` (stdlib) | Parsowanie Python bez zależności |\n| Parsing | `libcst` | Modyfikacja kodu z zachowaniem formatowania |\n| Parsing | `tree-sitter` | Multi-language (Go, TS, Rust) — v4 |\n| Graf | `networkx` | Call graph, centrality, cykle |\n| Graf | `neo4j` | Eksport do bazy grafowej |\n| Wizualizacja | `pyvis` | Interaktywny HTML |\n| Schema | `pydantic` | IR models + walidacja |\n| Proto | `grpcio-tools` | Kompilacja `.proto` → kod |\n\n## Roadmap\n\n- [x] v0.1 — AST extraction, CQRS inference, JSON/Proto/MD output\n- [x] v0.1 — NetworkX call graph, GraphML/DOT export, PageRank\n- [x] v0.1 — Event Model (DDD), layer violation detection\n- [ ] v0.2 — `libcst` extractor (zachowanie formatowania, transformacje)\n- [ ] v0.2 — `tree-sitter` multi-language (Go, TypeScript, Rust)\n- [ ] v0.3 — Neo4j export, pyvis HTML visualization\n- [ ] v0.3 — Cross-language code generator (proto → Go/TS stubs)\n- [ ] v0.4 — Data Flow Graph (DFG), State model extraction\n\n## Licencja\n\nMIT\n\n\n## License\n\nLicensed under Apache-2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemcod%2Fcode2schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemcod%2Fcode2schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemcod%2Fcode2schema/lists"}