mathen 0.0.1__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.
mathen-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,451 @@
1
+ Metadata-Version: 2.3
2
+ Name: mathen
3
+ Version: 0.0.1
4
+ Summary: Evidence-backed architecture knowledge base and CLI
5
+ Requires-Python: >=3.12
6
+ Description-Content-Type: text/markdown
7
+
8
+ # Mathen
9
+
10
+ Mathen is an evidence-backed, temporal knowledge graph for software
11
+ architecture.
12
+
13
+ It studies software systems from two complementary directions:
14
+
15
+ 1. **Analysis:** translate systems into reusable architectural features,
16
+ state models, invariants, trade-offs, and mathematical views.
17
+ 2. **Synthesis:** compose those features under explicit requirements and
18
+ constraints to explore candidate architectures for new systems.
19
+
20
+ Mathen treats architecture as an evolving network rather than a static list of
21
+ products. Systems acquire new features, dependencies, relationships, and
22
+ community memberships over time. New systems are often formed by recombining
23
+ existing ideas under a new workload, deployment boundary, hardware context, or
24
+ set of operational constraints.
25
+
26
+ > **Mathen turns software architecture into a time-aware, evidence-backed,
27
+ > mathematically informed intermediate representation that can be compared,
28
+ > composed, and validated.**
29
+
30
+ ## Why Mathen exists
31
+
32
+ Architecture knowledge is scattered across source code, design documents,
33
+ papers, benchmarks, protocol specifications, and operational experience. This
34
+ makes it difficult to answer questions such as:
35
+
36
+ - Which design properties do SQLite and DuckDB share, and where do they
37
+ diverge?
38
+ - How does PostgreSQL connect relational databases, extensibility, indexing,
39
+ replication, and domain-specific extensions?
40
+ - Which existing structures are composed by Supabase or Firecracker?
41
+ - Which properties are preserved when two architectural patterns are combined?
42
+ - What new conflicts, assumptions, and costs appear in the combination?
43
+ - How did a system's architecture and relationships change between versions?
44
+
45
+ Mathen makes these questions machine-readable without reducing architecture to
46
+ ungrounded labels or a single oversimplified definition.
47
+
48
+ ## Project status
49
+
50
+ This repository is a research prototype. Architecture Cards are structured,
51
+ evidence-backed models, not automatic formal proofs of the corresponding
52
+ implementations.
53
+
54
+ Source code and the browser client are available in the
55
+ [Mathen GitHub repository](https://github.com/Xuepoo/mathen).
56
+
57
+ ## The core model
58
+
59
+ Mathen represents a system through several complementary views:
60
+
61
+ ```text
62
+ System and version
63
+ ├── data model and types
64
+ ├── state space and transitions
65
+ ├── operations and composition laws
66
+ ├── dependency and causality graph
67
+ ├── consistency and convergence model
68
+ ├── storage and execution model
69
+ ├── isolation and security boundary
70
+ ├── failure and recovery model
71
+ ├── resource, performance, and cost model
72
+ └── evolution, migration, and composition history
73
+ ```
74
+
75
+ No single mathematical structure is expected to explain an entire system. A
76
+ mathematical view is useful only when it answers a concrete question and states
77
+ its assumptions. Depending on the question, a view may use:
78
+
79
+ | Architecture question | Candidate mathematical view |
80
+ | ------------------------------- | ------------------------------------------ |
81
+ | What are the data and objects? | Sets, types, algebraic data types |
82
+ | How are objects related? | Graphs, DAGs, partial orders |
83
+ | How does the system evolve? | State machines, transition systems |
84
+ | Which operations compose? | Monoids, algebras, compositional semantics |
85
+ | Does state converge? | Semilattices, monotone systems |
86
+ | Is an optimization transparent? | Refinement, simulation, bisimulation |
87
+ | How do failures affect service? | Probability, queueing, reliability models |
88
+ | How are resources bounded? | Complexity and cost models |
89
+
90
+ These are candidate abstractions, not automatic proofs. Each claim is labeled
91
+ as a `fact`, `inference`, `hypothesis`, or `analogy`, and remains connected to
92
+ its evidence and scope.
93
+
94
+ ## A temporal, multi-layer architecture graph
95
+
96
+ The long-term knowledge graph contains more than software names. It can include
97
+ systems, versions, features, primitives, mathematical models, programming
98
+ languages, operating systems, protocols, organizations, evidence, and candidate
99
+ architectures.
100
+
101
+ Relationships are typed rather than collapsed into a generic similarity edge:
102
+
103
+ ```text
104
+ implements uses extends
105
+ composes resembles influenced-by
106
+ depends-on conflicts-with optimizes-for
107
+ evolves-to verified-by constrained-by
108
+ ```
109
+
110
+ This distinction matters. Historical influence needs historical evidence;
111
+ structural similarity can be inferred from architecture analysis; a dependency
112
+ should be supported by implementation or documentation evidence.
113
+
114
+ The graph is temporal:
115
+
116
+ ```text
117
+ version A ──evolves-to──> version B ──adds──> feature C
118
+ │ └──uses──> primitive D
119
+ └──belongs-to──> community E
120
+ ```
121
+
122
+ It can represent the first appearance of a feature, version-specific changes,
123
+ new dependencies, community membership, composition lineage, and candidate
124
+ architectures that have not yet been implemented. Systems can belong to many
125
+ overlapping communities: PostgreSQL can connect relational databases, MVCC,
126
+ database extensibility, geospatial data, vector search, replication, and
127
+ backend platforms at the same time.
128
+
129
+ ## From analysis to synthesis
130
+
131
+ Mathen uses a staged workflow:
132
+
133
+ ```text
134
+ source code / documents / papers / experiments
135
+ ↓
136
+ fixed evidence and provenance
137
+ ↓
138
+ deterministic repository observations
139
+ ↓
140
+ semantic features, mathematical views, trade-offs
141
+ ↓
142
+ reviewed temporal architecture graph
143
+ ↓
144
+ constraint-based comparison and composition
145
+ ↓
146
+ prototype, benchmark, and failure tests
147
+ ```
148
+
149
+ When exploring a new architecture, Mathen records more than its input
150
+ features:
151
+
152
+ ```text
153
+ inputs
154
+ new constraints
155
+ target workload
156
+ preserved properties
157
+ introduced conflicts
158
+ new trade-offs
159
+ unverified assumptions
160
+ validation plan
161
+ ```
162
+
163
+ Architecture synthesis is not feature shopping. For example, combining
164
+ embedded execution, columnar vectorization, append-only recovery, and
165
+ content-addressed snapshots requires checking the write model, transaction
166
+ boundary, recovery protocol, update pattern, and storage costs.
167
+
168
+ ## Representative examples
169
+
170
+ The current cards and repository analyses use systems that expose different
171
+ architectural patterns:
172
+
173
+ | System | Reusable structure being studied |
174
+ | ----------- | ----------------------------------------------------------------------- |
175
+ | Git | Immutable content-addressed objects, mutable references, causal history |
176
+ | SQLite | Embedded execution, layered storage, atomic commit, WAL snapshots |
177
+ | DuckDB | Embedded analytical execution, columnar data, vectorized operators |
178
+ | PostgreSQL | Extensible relational engine, MVCC, process isolation, extensions |
179
+ | Kafka | Durable append-only logs, ordered offsets, replay-oriented consumption |
180
+ | Kubernetes | Declarative state, reconciliation loops, control-plane convergence |
181
+ | Firecracker | Minimal virtual machine model, KVM isolation, event-driven VMM |
182
+ | Supabase | Database-centered platform composition, API, auth, and data policy |
183
+
184
+ These are starting points for extracting structures that can be compared across
185
+ databases, distributed systems, operating systems, runtimes, network protocols,
186
+ compilers, media systems, and programming languages. They are not claimed to
187
+ be complete formal models or evidence of historical influence.
188
+
189
+ ## Evidence and review boundary
190
+
191
+ Mathen separates observations, interpretations, and reviewed knowledge:
192
+
193
+ ```text
194
+ data/systems/ reviewed canonical Architecture Cards
195
+ data/drafts/ unreviewed generated cards
196
+ data/modeling/ fixed-commit evidence bundles and prompts
197
+ data/analyses/ ignored deterministic repository reports
198
+ ```
199
+
200
+ The project follows these rules:
201
+
202
+ 1. Extract observable facts before assigning mathematical terminology.
203
+ 2. Cite primary evidence wherever possible.
204
+ 3. Give every mathematical view a question and assumptions.
205
+ 4. Record benefits, costs, preconditions, failure modes, and counterexamples.
206
+ 5. Keep structural similarity separate from historical influence.
207
+ 6. Never let LLM output overwrite reviewed cards.
208
+ 7. Treat candidate compositions as hypotheses until implemented or validated.
209
+
210
+ An LLM proposes abstractions and comparisons; deterministic tools provide
211
+ provenance and observations; schema and semantic validation constrain output;
212
+ human review decides what becomes canonical.
213
+
214
+ ## Current implementation
215
+
216
+ The repository currently provides:
217
+
218
+ - a versioned Architecture Card schema and semantic validator;
219
+ - a representative repository catalog across databases, logs,
220
+ orchestration, isolation, virtualization, networking, compilers, media, and
221
+ backend platforms;
222
+ - fixed-commit repository analysis with Git and GitHub archive transports;
223
+ - deterministic repository observations for source structure, build surfaces,
224
+ and navigation signals without assigning semantic facts;
225
+ - portable modeling bundles and a provider-neutral OpenAI-compatible LLM
226
+ adapter;
227
+ - a bounded composition candidate explorer whose results remain
228
+ `proven: false`;
229
+ - a Cloudflare-first Hono Worker API backed by D1;
230
+ - a Vite browser client for browsing reviewed architecture cards;
231
+ - read-only API queries for source-card-owned feature relations and composition
232
+ proposals;
233
+ - a read-only stdio MCP server with filesystem and API backends;
234
+ - optional Cloudflare Turnstile protection, signed browser access sessions,
235
+ service-token API access, and per-IP limits;
236
+ - explicit separation between reviewed cards, drafts, and modeling evidence.
237
+
238
+ The canonical tree currently contains 219 reviewed cards. The representative
239
+ repository manifest contains 62 entries, all with matching canonical cards.
240
+
241
+ The current knowledge graph is intentionally relational and small. D1 is the
242
+ canonical structured store. Vectorize is an optional rebuildable semantic
243
+ index, and a dedicated graph database remains a future adapter rather than a
244
+ first-milestone dependency.
245
+
246
+ ## Quick start: Python card tooling
247
+
248
+ ```bash
249
+ uv tool install mathen
250
+ mathen version
251
+ mathen config init
252
+ uv run mathen validate
253
+ uv run mathen list
254
+ uv run mathen show git
255
+ ```
256
+
257
+ The CLI supports a cross-platform TOML configuration under the user's standard
258
+ configuration directory. Configure paths and an OpenAI-compatible LLM endpoint
259
+ with `mathen config set`; see [`docs/configuration.md`](docs/configuration.md).
260
+ The repository's first package release is `v0.0.1`. Pushing a matching version
261
+ tag builds and publishes the Python distributions to PyPI through the
262
+ `PYPI_API_TOKEN` GitHub Actions secret.
263
+
264
+ Analyze the representative repository catalog into reviewable draft cards:
265
+
266
+ ```bash
267
+ uv run mathen analyze data/repositories/representative.json \
268
+ --cache-dir /tmp/mathen/repos \
269
+ --output-dir data/drafts
270
+ ```
271
+
272
+ The command uses shallow, blob-filtered Git checkouts and reads tracked tree
273
+ metadata without materializing the full worktree. Existing cached checkouts are
274
+ reused by default; pass `--refresh` only when a network update is required.
275
+ The source cache is not committed. Reports are written to the ignored
276
+ `data/analyses/` directory, while draft cards are written to `data/drafts/` and
277
+ must be reviewed before promotion to `data/systems/`.
278
+
279
+ When GitHub's Git transport is unavailable, use the source archive transport:
280
+
281
+ ```bash
282
+ uv run mathen analyze data/repositories/representative.json \
283
+ --transport archive \
284
+ --continue-on-error
285
+ ```
286
+
287
+ Prepare evidence bundles for LLM-assisted architecture modeling:
288
+
289
+ ```bash
290
+ uv run mathen prepare-modeling --write-prompts
291
+ ```
292
+
293
+ This writes fixed-commit JSON bundles to `data/modeling/` and portable prompts
294
+ to `data/modeling/prompts/`. The bundle is the input to the semantic modeling
295
+ step; its output remains a draft until evidence and claims are reviewed.
296
+
297
+ Run the provider-neutral adapter against those bundles:
298
+
299
+ ```bash
300
+ export OPENAI_API_KEY=...
301
+ export MATHEN_LLM_MODEL=gpt-4.1-mini
302
+ uv run mathen model --system git
303
+ ```
304
+
305
+ Generated cards are written under `data/drafts/llm/`. The adapter checks card
306
+ semantics and prevents model output from introducing or changing evidence
307
+ records. Configure an OpenAI-compatible endpoint with `MATHEN_LLM_BASE_URL`,
308
+ or use the explicit `--api-key`, `--model`, and `--base-url` flags. See
309
+ [`docs/llm-modeling.md`](docs/llm-modeling.md) for the full workflow.
310
+
311
+ ## Quick start: Cloudflare application
312
+
313
+ Prerequisites: Bun and Wrangler.
314
+
315
+ The repository also provides a `just` command layer for the common local
316
+ workflows below. The existing `bun` and `uv` commands remain the underlying
317
+ implementation commands.
318
+
319
+ ```bash
320
+ bun install
321
+ just db-reset
322
+ just dev
323
+ ```
324
+
325
+ The local API runs at `http://localhost:8787` and the Vite client runs at
326
+ `http://localhost:5173`. The Vite development server proxies `/api` requests
327
+ to the Worker.
328
+
329
+ The application deliberately uses D1 as the source of truth. Vectorize is an
330
+ optional search index and is not required for local structured browsing. A
331
+ local MCP server exposes read-only system, feature, and modeling-bundle tools;
332
+ see [`docs/mcp.md`](docs/mcp.md). Set `MATHEN_API_URL=http://localhost:8787/api`
333
+ to make it read reviewed data and modeling bundles through the Hono/D1 API;
334
+ without that variable it uses the local filesystem. A future hosted MCP server
335
+ can call the same API and submit reviewed Architecture Cards generated from a
336
+ local repository.
337
+
338
+ Run the standard checks:
339
+
340
+ ```bash
341
+ just check
342
+ ```
343
+
344
+ Run `just` or `just --list` from the repository root to see all available
345
+ recipes. Useful focused commands include `just python-check`, `just api-test`,
346
+ `just typescript-check`, `just build`, and `just mcp`.
347
+
348
+ The Python development toolchain, including Ruff, is declared in
349
+ `pyproject.toml` and installed by `uv sync --locked`.
350
+
351
+ ## Quick start: MCP
352
+
353
+ Start the local read-only MCP server from the repository root:
354
+
355
+ ```bash
356
+ bun run mcp
357
+ ```
358
+
359
+ By default it reads the local filesystem. To read reviewed systems and fixed
360
+ modeling bundles through the Hono/D1 API instead:
361
+
362
+ ```bash
363
+ MATHEN_API_URL=http://localhost:8787/api bun run mcp
364
+ ```
365
+
366
+ The server exposes `list_systems`, `get_system`, `search_features`,
367
+ `list_feature_relations`, and `get_modeling_bundle`. API mode does not expose
368
+ drafts; filesystem mode exposes them only when explicitly requested. See
369
+ [`docs/mcp.md`](docs/mcp.md).
370
+
371
+ ## Repository layout
372
+
373
+ ```text
374
+ docs/ Research and modeling documentation
375
+ schemas/ JSON Schema for architecture cards
376
+ data/systems/ Evidence-backed system cards
377
+ data/repositories/ Representative repository analysis catalog
378
+ data/drafts/ Unreviewed generated Architecture Cards
379
+ data/modeling/ Fixed-commit modeling bundles
380
+ data/analyses/ Ignored deterministic inspection reports
381
+ src/mathen/ Validation, analysis, and LLM tooling
382
+ tests/ Unit tests
383
+ apps/api/ Hono Worker and D1 migrations
384
+ apps/web/ Bun/Vite browser client
385
+ apps/mcp/ Read-only stdio MCP server
386
+ ```
387
+
388
+ ## Design principles
389
+
390
+ 1. **Evidence before abstraction**: every non-trivial claim should link to a
391
+ primary source or be explicitly marked as an inference.
392
+ 2. **Views rather than one essence**: a system may have several valid
393
+ mathematical views, each tied to a question and assumptions.
394
+ 3. **Claims have boundaries**: benefits, costs, preconditions, and counter-
395
+ examples are stored together.
396
+ 4. **Structure is reusable**: cards describe transferable features rather than
397
+ only product-specific descriptions.
398
+ 5. **Validation precedes automation**: LLM output must pass schema and semantic
399
+ checks before entering the knowledge base.
400
+
401
+ ## Roadmap
402
+
403
+ The project is developed in stages:
404
+
405
+ 1. **Representation and evidence:** stabilize Architecture Cards and review
406
+ rules.
407
+ 2. **Assisted extraction:** turn fixed-commit evidence into constrained drafts.
408
+ 3. **Application and retrieval:** provide D1, API, browser, semantic search,
409
+ and MCP access.
410
+ 4. **Temporal and relational graph:** model versions, evolution, communities,
411
+ composition, constraints, and evidence lineage.
412
+ 5. **Architecture synthesis:** query requirements, generate candidate
413
+ compositions, expose conflicts, and validate candidates with prototypes,
414
+ benchmarks, and failure tests.
415
+
416
+ The long-term goal is a disciplined intermediate layer between implementation
417
+ and design reasoning:
418
+
419
+ ```text
420
+ existing systems → reusable architectural structures → candidate designs
421
+ ```
422
+
423
+ ## Non-goals
424
+
425
+ Mathen does not currently aim to:
426
+
427
+ - automatically prove that an implementation satisfies a mathematical model;
428
+ - claim originality from structural similarity alone;
429
+ - replace source review, experiments, benchmarks, or human architecture
430
+ judgment;
431
+ - treat every mathematical analogy as a formal equivalence;
432
+ - operate a general-purpose graph database before relational query patterns
433
+ demonstrate that it is necessary.
434
+
435
+ ## Documentation
436
+
437
+ - [`docs/user-manual.md`](docs/user-manual.md) — schemas, data flow, and
438
+ operating procedures
439
+ - [`docs/catalog.md`](docs/catalog.md) — long-term Mathen catalog backlog
440
+ - [`docs/vision.md`](docs/vision.md) — project motivation and modeling views
441
+ - [`docs/methodology.md`](docs/methodology.md) — evidence and validation rules
442
+ - [`docs/repository-catalog.md`](docs/repository-catalog.md) — repository
443
+ analysis policy and catalog
444
+ - [`docs/llm-modeling.md`](docs/llm-modeling.md) — constrained LLM modeling
445
+ - [`docs/mcp.md`](docs/mcp.md) — read-only agent access
446
+ - [`docs/hosting.md`](docs/hosting.md) — Cloudflare deployment boundary
447
+ - [`docs/roadmap.md`](docs/roadmap.md) — staged implementation plan
448
+
449
+ ## License
450
+
451
+ See [`LICENSE`](LICENSE).