spartastruct 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. spartastruct-0.1.0/PKG-INFO +442 -0
  2. spartastruct-0.1.0/README.md +409 -0
  3. spartastruct-0.1.0/pyproject.toml +62 -0
  4. spartastruct-0.1.0/setup.cfg +4 -0
  5. spartastruct-0.1.0/spartastruct/__init__.py +3 -0
  6. spartastruct-0.1.0/spartastruct/analyzer/__init__.py +1 -0
  7. spartastruct-0.1.0/spartastruct/analyzer/base.py +127 -0
  8. spartastruct-0.1.0/spartastruct/analyzer/base_analyzer.py +20 -0
  9. spartastruct-0.1.0/spartastruct/analyzer/js_analyzer.py +233 -0
  10. spartastruct-0.1.0/spartastruct/analyzer/python_analyzer.py +577 -0
  11. spartastruct-0.1.0/spartastruct/cli.py +261 -0
  12. spartastruct-0.1.0/spartastruct/config.py +51 -0
  13. spartastruct-0.1.0/spartastruct/diagrams/__init__.py +1 -0
  14. spartastruct-0.1.0/spartastruct/diagrams/class_diagram.py +64 -0
  15. spartastruct-0.1.0/spartastruct/diagrams/dfd.py +61 -0
  16. spartastruct-0.1.0/spartastruct/diagrams/er_diagram.py +72 -0
  17. spartastruct-0.1.0/spartastruct/diagrams/flowchart.py +81 -0
  18. spartastruct-0.1.0/spartastruct/diagrams/function_graph.py +122 -0
  19. spartastruct-0.1.0/spartastruct/diagrams/module_graph.py +113 -0
  20. spartastruct-0.1.0/spartastruct/llm/__init__.py +1 -0
  21. spartastruct-0.1.0/spartastruct/llm/client.py +173 -0
  22. spartastruct-0.1.0/spartastruct/llm/prompts.py +75 -0
  23. spartastruct-0.1.0/spartastruct/renderer/__init__.py +1 -0
  24. spartastruct-0.1.0/spartastruct/renderer/markdown_renderer.py +89 -0
  25. spartastruct-0.1.0/spartastruct/renderer/pdf_exporter.py +150 -0
  26. spartastruct-0.1.0/spartastruct/templates/structure.md.j2 +31 -0
  27. spartastruct-0.1.0/spartastruct/utils/__init__.py +1 -0
  28. spartastruct-0.1.0/spartastruct/utils/file_walker.py +96 -0
  29. spartastruct-0.1.0/spartastruct/utils/framework_detector.py +98 -0
  30. spartastruct-0.1.0/spartastruct.egg-info/PKG-INFO +442 -0
  31. spartastruct-0.1.0/spartastruct.egg-info/SOURCES.txt +40 -0
  32. spartastruct-0.1.0/spartastruct.egg-info/dependency_links.txt +1 -0
  33. spartastruct-0.1.0/spartastruct.egg-info/entry_points.txt +2 -0
  34. spartastruct-0.1.0/spartastruct.egg-info/requires.txt +14 -0
  35. spartastruct-0.1.0/spartastruct.egg-info/top_level.txt +1 -0
  36. spartastruct-0.1.0/tests/test_analyzer.py +175 -0
  37. spartastruct-0.1.0/tests/test_cli.py +162 -0
  38. spartastruct-0.1.0/tests/test_diagrams.py +288 -0
  39. spartastruct-0.1.0/tests/test_js_analyzer.py +253 -0
  40. spartastruct-0.1.0/tests/test_llm.py +118 -0
  41. spartastruct-0.1.0/tests/test_pdf_exporter.py +243 -0
  42. spartastruct-0.1.0/tests/test_renderer.py +76 -0
@@ -0,0 +1,442 @@
1
+ Metadata-Version: 2.4
2
+ Name: spartastruct
3
+ Version: 0.1.0
4
+ Summary: Instant architecture diagrams for any Python, JavaScript, or TypeScript project
5
+ Author-email: Yash Randive <yash.randive11@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yashrandive11/spartastruct
8
+ Project-URL: Repository, https://github.com/yashrandive11/spartastruct
9
+ Project-URL: Issues, https://github.com/yashrandive11/spartastruct/issues
10
+ Keywords: architecture,diagrams,mermaid,code-analysis,documentation
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Documentation
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: click>=8.1
23
+ Requires-Dist: rich>=13.0
24
+ Requires-Dist: litellm>=1.40
25
+ Requires-Dist: jinja2>=3.1
26
+ Requires-Dist: astroid>=3.0
27
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
28
+ Requires-Dist: tomli-w>=1.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
32
+ Requires-Dist: ruff>=0.1; extra == "dev"
33
+
34
+ <div align="center">
35
+ <img src="assets/banner.svg" alt="SpartaStruct" width="800"/>
36
+
37
+ <br/>
38
+
39
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-3776AB?style=flat-square&logo=python&logoColor=white)](https://python.org)
40
+ [![JS/TS](https://img.shields.io/badge/JS%2FTS-supported-f7df1e?style=flat-square&logo=typescript&logoColor=black)](spartastruct/analyzer/js_analyzer.py)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-6366f1?style=flat-square)](LICENSE)
42
+ [![Tests](https://img.shields.io/badge/Tests-106%20passing-22c55e?style=flat-square)](tests/)
43
+ [![Diagrams](https://img.shields.io/badge/Diagrams-6%20types-a855f7?style=flat-square)](spartastruct/diagrams/)
44
+ [![LLM](https://img.shields.io/badge/LLM-litellm%20%E2%80%94%20any%20provider-f59e0b?style=flat-square)](https://docs.litellm.ai/)
45
+
46
+ <br/>
47
+
48
+ **Point SpartaStruct at any Python, JavaScript, or TypeScript project and get 6 architecture diagrams in under a minute.**
49
+ PDF and PNG export. Works offline. Optionally enriched by any LLM.
50
+
51
+ </div>
52
+
53
+ ---
54
+
55
+ ## ⚡ Quick Start
56
+
57
+ > **Estimated time: 2 minutes**
58
+
59
+ **Step 1 — Install the dependencies**
60
+
61
+ ```bash
62
+ # Install SpartaStruct
63
+ pip install spartastruct
64
+
65
+ # Install the Mermaid CLI (needs Node.js — https://nodejs.org)
66
+ npm install -g @mermaid-js/mermaid-cli
67
+ ```
68
+
69
+ **Step 2 — Run it on your project**
70
+
71
+ ```bash
72
+ spartastruct analyze /path/to/your/python/project --no-llm
73
+ ```
74
+
75
+ That's it. Six PDF files appear in a `spartadocs/` folder inside your project.
76
+
77
+ ```
78
+ your-project/
79
+ └── spartadocs/
80
+ ├── class_diagram.pdf ← all your classes and how they relate
81
+ ├── er_diagram.pdf ← database tables and relationships
82
+ ├── dfd.pdf ← HTTP routes → services → database
83
+ ├── flowchart.pdf ← app logic and entry points
84
+ ├── function_graph.pdf ← which functions call which
85
+ └── module_graph.pdf ← which files import which
86
+ ```
87
+
88
+ **Step 3 — Add LLM enrichment (optional)**
89
+
90
+ ```bash
91
+ spartastruct init # creates ~/.spartastruct/config.toml
92
+ spartastruct config --api-key anthropic YOUR_KEY # store your API key
93
+ spartastruct analyze /path/to/your/project # runs with LLM enrichment
94
+ ```
95
+
96
+ The LLM improves diagram labels, adds descriptions, and connects the dots between related components.
97
+
98
+ ---
99
+
100
+ ## How It Works
101
+
102
+ <div align="center">
103
+ <img src="assets/pipeline.svg" alt="SpartaStruct pipeline" width="760"/>
104
+ </div>
105
+
106
+ <br/>
107
+
108
+ SpartaStruct works in four stages:
109
+
110
+ 1. **Walk** — finds every `.py` file in your project, skipping `venv`, `__pycache__`, migrations, etc.
111
+ 2. **Analyze** — reads each file using Python's AST (Abstract Syntax Tree). No code is executed. It extracts classes, functions, routes, database models, imports, and call relationships.
112
+ 3. **Enrich** (optional) — sends the analysis to an LLM, which improves the diagram and adds a plain-English description.
113
+ 4. **Export** — converts each Mermaid diagram to a PDF using the `mmdc` CLI tool.
114
+
115
+ ---
116
+
117
+ ## The 6 Diagrams Explained
118
+
119
+ Each diagram answers a different question about your codebase.
120
+
121
+ <details>
122
+ <summary><strong>📦 Class Diagram</strong> — "What classes exist and how do they relate?"</summary>
123
+
124
+ <br/>
125
+
126
+ Shows every class in your project, its attributes (variables), its methods (functions), and whether it inherits from another class.
127
+
128
+ ```mermaid
129
+ classDiagram
130
+ class UserService {
131
+ +db: Database
132
+ +get_user(id) User
133
+ +create_user(data) User
134
+ }
135
+ class AdminService {
136
+ +promote(user_id)
137
+ }
138
+ AdminService --|> UserService : extends
139
+ ```
140
+
141
+ **Useful for:** Understanding the shape of your code, onboarding new developers, spotting classes that do too much.
142
+
143
+ </details>
144
+
145
+ <details>
146
+ <summary><strong>🗄️ ER Diagram</strong> — "What does the database look like?"</summary>
147
+
148
+ <br/>
149
+
150
+ Shows your database tables (ORM models) and the relationships between them — one-to-many, many-to-many, foreign keys, etc.
151
+
152
+ Supports: **SQLAlchemy**, **Django ORM**, **Tortoise ORM**, **Peewee**.
153
+
154
+ ```mermaid
155
+ erDiagram
156
+ User {
157
+ int id PK
158
+ string email
159
+ string name
160
+ }
161
+ Order {
162
+ int id PK
163
+ int user_id FK
164
+ float total
165
+ }
166
+ User ||--o{ Order : "places"
167
+ ```
168
+
169
+ **Useful for:** Database design reviews, writing migrations, explaining the data model to non-engineers.
170
+
171
+ </details>
172
+
173
+ <details>
174
+ <summary><strong>🌊 Data Flow Diagram (DFD)</strong> — "How does data move through the app?"</summary>
175
+
176
+ <br/>
177
+
178
+ Traces the path from an HTTP request → controller/handler → service layer → database. Particularly useful for API-heavy projects.
179
+
180
+ Supports: **FastAPI**, **Flask**, **Django**.
181
+
182
+ **Useful for:** Security reviews, debugging unexpected behaviour, understanding which routes hit which tables.
183
+
184
+ </details>
185
+
186
+ <details>
187
+ <summary><strong>🔄 Flowchart</strong> — "What does the app actually do step by step?"</summary>
188
+
189
+ <br/>
190
+
191
+ A top-down flow diagram starting from your entry points (`main()`, `run()`, CLI handlers, etc.) showing the sequence of processing.
192
+
193
+ **Useful for:** Explaining app logic to stakeholders, spotting dead code, documenting workflows.
194
+
195
+ </details>
196
+
197
+ <details>
198
+ <summary><strong>🕸️ Function Graph</strong> — "Which functions call which?"</summary>
199
+
200
+ <br/>
201
+
202
+ A left-to-right call graph grouping functions by file. Async functions are highlighted in blue. Entry-point functions are highlighted in yellow.
203
+
204
+ ```mermaid
205
+ graph LR
206
+ subgraph main["main.py"]
207
+ fn0["async handle_request()"]:::async
208
+ fn1["validate()"]
209
+ fn2["save()"]
210
+ fn0 --> fn1
211
+ fn0 --> fn2
212
+ end
213
+ classDef async fill:#e8f4fd,stroke:#2196f3
214
+ ```
215
+
216
+ > Edges are automatically deduplicated and capped at 8 per node to keep the diagram readable.
217
+
218
+ **Useful for:** Finding tightly-coupled functions, understanding call depth, refactoring planning.
219
+
220
+ </details>
221
+
222
+ <details>
223
+ <summary><strong>🗺️ Module Graph</strong> — "Which files import which?"</summary>
224
+
225
+ <br/>
226
+
227
+ A top-down dependency graph of your project's files. Local imports (your own code) are shown with solid lines. Third-party imports are shown with dashed lines.
228
+
229
+ **Useful for:** Identifying circular imports, understanding coupling between modules, planning a refactor.
230
+
231
+ </details>
232
+
233
+ ---
234
+
235
+ ## Full CLI Reference
236
+
237
+ ### `spartastruct analyze [PATH]`
238
+
239
+ Analyzes a project and writes PDFs.
240
+
241
+ ```bash
242
+ spartastruct analyze . # analyze current directory
243
+ spartastruct analyze /path/to/project # analyze a specific path
244
+ spartastruct analyze . --no-llm # skip LLM (fast, offline)
245
+ spartastruct analyze . --model openai/gpt-4o # use a different LLM
246
+ spartastruct analyze . --output ./my-docs # write PDFs to a custom folder
247
+ ```
248
+
249
+ | Flag | Default | What it does |
250
+ |------|---------|-------------|
251
+ | `--no-llm` | off | Skip LLM enrichment entirely. Static diagrams only. Fully offline. |
252
+ | `--model MODEL` | from config | Use a different LLM model just for this run. Uses litellm format: `provider/model`. |
253
+ | `--output DIR` | `spartadocs` | Write PDFs/PNGs here instead of the default `spartadocs/` folder. |
254
+ | `--format FORMAT` | `pdf` | Output format: `pdf`, `png` (transparent background, 3× scale), or `both`. |
255
+
256
+ ---
257
+
258
+ ### `spartastruct init`
259
+
260
+ Creates the config file at `~/.spartastruct/config.toml` with default settings. Run this once before using LLM features.
261
+
262
+ ```bash
263
+ spartastruct init
264
+ ```
265
+
266
+ ---
267
+
268
+ ### `spartastruct config`
269
+
270
+ View or update your settings.
271
+
272
+ ```bash
273
+ spartastruct config --show # print current settings
274
+ spartastruct config --model anthropic/claude-opus-4-7 # change the default model
275
+ spartastruct config --output-dir ./architecture-docs # change the default output folder
276
+ spartastruct config --api-key anthropic sk-ant-... # save an API key
277
+ spartastruct config --api-key openai sk-... # save multiple keys
278
+ ```
279
+
280
+ | Flag | What it does |
281
+ |------|-------------|
282
+ | `--show` | Print your current config. Use this to verify settings. |
283
+ | `--model MODEL` | Set the default LLM model. Accepts any litellm-format string. |
284
+ | `--output-dir DIR` | Set where PDFs are saved by default. |
285
+ | `--api-key PROVIDER KEY` | Save an API key for a provider. Provider name must match the litellm prefix. |
286
+
287
+ ---
288
+
289
+ ## LLM Setup
290
+
291
+ SpartaStruct uses [litellm](https://docs.litellm.ai/) under the hood, which means it works with almost any LLM provider.
292
+
293
+ ### Supported Providers
294
+
295
+ | Provider | Config key | Model format |
296
+ |----------|-----------|-------------|
297
+ | Anthropic | `anthropic` | `anthropic/claude-haiku-4-5-20251001` |
298
+ | OpenAI | `openai` | `openai/gpt-4o` |
299
+ | Google Gemini | `gemini` | `gemini/gemini-2.0-flash` |
300
+ | Groq | `groq` | `groq/llama-3.1-70b-versatile` |
301
+ | Mistral | `mistral` | `mistral/mistral-large-latest` |
302
+ | Cohere | `cohere` | `cohere/command-r-plus` |
303
+ | Together AI | `together` | `together/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo` |
304
+ | Ollama (local) | `ollama` | `ollama/llama3.2` |
305
+
306
+ **Default model:** `anthropic/claude-haiku-4-5-20251001` (fast and cheap)
307
+
308
+ ### Setting Up Anthropic (example)
309
+
310
+ ```bash
311
+ # 1. Get your API key from https://console.anthropic.com
312
+ # 2. Store it
313
+ spartastruct config --api-key anthropic sk-ant-...
314
+ # 3. Verify
315
+ spartastruct config --show
316
+ # 4. Run
317
+ spartastruct analyze /path/to/project
318
+ ```
319
+
320
+ ### Using Ollama (fully local, no API key needed)
321
+
322
+ ```bash
323
+ # Install Ollama from https://ollama.com, then pull a model
324
+ ollama pull llama3.2
325
+
326
+ # Tell SpartaStruct to use it
327
+ spartastruct config --model ollama/llama3.2
328
+
329
+ # Run — no internet connection needed
330
+ spartastruct analyze /path/to/project
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Supported Languages
336
+
337
+ SpartaStruct auto-detects your project's primary language and picks the right analyzer. For polyglot projects (e.g. a Python API with a TypeScript frontend in the same repo), both analyzers run and results are merged into a single set of diagrams.
338
+
339
+ | Language | Extensions | Analyzer |
340
+ |----------|-----------|---------|
341
+ | Python | `.py` | AST-based — classes, functions, routes, ORM models, imports |
342
+ | JavaScript | `.js`, `.jsx` | Regex-based — classes, functions, Express routes, imports |
343
+ | TypeScript | `.ts`, `.tsx` | Regex-based — classes, interfaces, functions, NestJS routes, imports |
344
+
345
+ **Detected JS/TS frameworks:** Express, NestJS, Next.js, React, Vue, Angular, Nuxt, TypeORM, Sequelize, Mongoose, Prisma, GraphQL, Apollo, Socket.IO, Axios, Jest, Vitest, RxJS
346
+
347
+ **How auto-detection works:** SpartaStruct counts `.py` vs JS/TS files in your project. Python-only → Python analyzer. JS/TS-only → JS/TS analyzer. Both present → both analyzers run and results are merged.
348
+
349
+ ---
350
+
351
+ ## Supported Frameworks
352
+
353
+ SpartaStruct auto-detects which frameworks your project uses and includes that in the analysis.
354
+
355
+ | Category | Frameworks |
356
+ |----------|-----------|
357
+ | **Web** | FastAPI, Flask, Django |
358
+ | **Database / ORM** | SQLAlchemy, Django ORM, Tortoise ORM, Peewee, Alembic |
359
+ | **Task Queues** | Celery |
360
+ | **Validation** | Pydantic |
361
+ | **Testing** | Pytest |
362
+ | **HTTP Clients** | Requests, HTTPX |
363
+ | **Data Science** | NumPy, Pandas, PyTorch, TensorFlow |
364
+
365
+ Detection is automatic — you don't need to tell SpartaStruct which frameworks you use.
366
+
367
+ ---
368
+
369
+ ## Requirements
370
+
371
+ | Tool | Version | Install |
372
+ |------|---------|---------|
373
+ | Python | 3.10+ | [python.org](https://python.org) |
374
+ | Node.js | 18+ | [nodejs.org](https://nodejs.org) |
375
+ | Mermaid CLI (`mmdc`) | latest | `npm install -g @mermaid-js/mermaid-cli` |
376
+
377
+ > `mmdc` is only needed for PDF export. The analysis and diagram generation work without it.
378
+
379
+ ---
380
+
381
+ ## Config File Reference
382
+
383
+ The config lives at `~/.spartastruct/config.toml`. You can edit it directly or use `spartastruct config`.
384
+
385
+ ```toml
386
+ model = "anthropic/claude-haiku-4-5-20251001"
387
+ output_dir = "spartadocs"
388
+
389
+ [api_keys]
390
+ anthropic = "sk-ant-..."
391
+ openai = "sk-..."
392
+ ```
393
+
394
+ ---
395
+
396
+ ## Project Structure
397
+
398
+ ```
399
+ spartastruct/
400
+ ├── analyzer/
401
+ │ ├── base.py # data types: FileResult, ClassInfo, FunctionInfo, etc.
402
+ │ └── python_analyzer.py # AST walking, class/function/route extraction
403
+ ├── diagrams/
404
+ │ ├── class_diagram.py # classDiagram generator
405
+ │ ├── er_diagram.py # erDiagram generator
406
+ │ ├── dfd.py # data flow diagram generator
407
+ │ ├── flowchart.py # flowchart generator
408
+ │ ├── function_graph.py # function call graph generator
409
+ │ └── module_graph.py # module dependency graph generator
410
+ ├── llm/
411
+ │ ├── client.py # litellm wrapper, failure tracking
412
+ │ └── prompts.py # system prompts per diagram type
413
+ ├── renderer/
414
+ │ ├── markdown_renderer.py # assembles sections from diagram results
415
+ │ └── pdf_exporter.py # calls mmdc to convert Mermaid → PDF
416
+ ├── utils/
417
+ │ ├── file_walker.py # finds .py files, respects ignore patterns
418
+ │ └── framework_detector.py# detects frameworks from imports
419
+ ├── templates/
420
+ │ └── structure.md.j2 # Jinja2 template for markdown layout
421
+ ├── config.py # TOML config load/save
422
+ └── cli.py # Click CLI (analyze, init, config)
423
+ ```
424
+
425
+ ---
426
+
427
+ ## Contributing
428
+
429
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
430
+
431
+ ```bash
432
+ git clone https://github.com/yashrandive11/spartastruct
433
+ cd spartastruct
434
+ pip install -e ".[dev]"
435
+ pytest
436
+ ```
437
+
438
+ ---
439
+
440
+ <div align="center">
441
+ <sub>Built with Python · Mermaid.js · litellm · Rich · Click</sub>
442
+ </div>