1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! The BREP PLM server.
//!
//! Parts have a permanent identity and a configurable number; revisions carry
//! the lifecycle and the CAD document; a draft is edited under an explicit
//! checkout; a released revision is immutable. The HTTP surface is in
//! [`api`], the rules are in [`db`] and [`lifecycle`], and the records are in
//! [`model`].
//!
//! # What is built
//!
//! The spine, plus the administrator's scripting layer ([`scripting`]): part
//! types number by counter, free text, pattern or script
//! ([`model::NumberMode`]); revision labels are free text; every part carries a
//! fixed [`model::DocumentClass`]; and hooks — part number, revision label,
//! before release, after release, review reviewers and review events — let an
//! organization override the defaults with JavaScript files in a directory it
//! can keep in git.
//!
//! The catalog ([`catalog`]): a tree of categories, each adding typed
//! attributes to what it inherits from its parent; every part sits in one
//! category, carries free tags, and holds attribute values that are
//! type-checked when written and must be complete before a release.
//!
//! Sourcing ([`sourcing`]): manufacturers and suppliers, and on each part its
//! manufacturer parts with their supplier offers. Administrator settings
//! ([`model::Settings`]) decide whether a part may have several revisions in
//! work and whether a released part's catalog values lock.
//!
//! Families and templates ([`family`], [`seed`]): the family page, Generate
//! from the family table's rows — from the CAD app with its documents, or
//! assembled here and queued for a headless CAD worker's bake ([`bake_worker`])
//! — CSV import into a family's table, and template spin-out.
//!
//! Assembly structure ([`bom`], [`bom_config`]): each revision's "uses" list —
//! the one the CAD app publishes on save — and the indented and flat BOM, named
//! BOM column configurations, the diff between
//! two revisions' lists, where-used, and an administrator's release gate on
//! unreleased children, all computed from it.
//!
//! Security ([`security`], `api::credentials`, [`tls`]): CSRF tokens on browser
//! sessions, scoped API tokens for everything else, a sign-in throttle, session
//! limits, password change and sign-out everywhere, response headers, `Secure`
//! cookies, optional native TLS, and a switch for the in-browser script editor.
//!
//! The audit log ([`audit`]): every change the store commits, found by diffing
//! what the change touched before and after, attributed to the request's
//! actor, committed with the change and read through `/api/audit`.
//!
//! Storage ([`sql`], [`table`]): the metadata in one SQLite file, each change
//! one transaction with its audit events; a trigram full-text index over what
//! a person searches a part by; and paged part listings. A data directory's
//! schema version must match exactly; there is no upgrade path. Attachments
//! ([`attach`]), per-user workspaces ([`workspace`]) and backups, restore and
//! export ([`backup`]) sit beside it.
//!
//! Review and approval ([`review`]): submitting a revision opens a review
//! round judged by the settings' rule or the nearest override, reviewers
//! approve or reject, a rejection sends the revision back to Draft, release
//! waits for the rule, and every revision carries a threaded discussion. One
//! process holds a data directory at a time ([`dirlock`]).
//!
//! Workflows ([`workflow`]): versioned workflow definitions and durable
//! executions with forms, reviews and script steps. Jobs ([`jobs`]): shop-floor
//! builds of released manufacturing instructions, signed off step by step. The
//! tools library ([`tools`]): the hand tools and fixtures instruction steps
//! name.
//!
//! A part records where it came from ([`model::Origin`]) and an
//! external reference; the KiCad library setup stamps the parts it imports.
//!
//! # The document API
//!
//! `/api/store/*` is deliberately shaped to what the CAD app's `StoreBackend`
//! requires of a remote backend: a metadata-only index (so a client never
//! hydrates the corpus), a per-key read, a write, a delete, and a monotonic
//! change sequence with a "what moved" feed. The CAD app's PLM client stores
//! through it.
//!
//! [`api::router`] builds the `axum` router over a [`db::Db`] (opened with
//! [`db::Db::open`]); the `brep-plm` binary serves it. See the README for the
//! command line and an embedding example.
use StatusCode;
use ;
use Json;
/// A refusal, with the status the API answers it with and the message a person
/// reads. Every refusal in this server carries a reason — a bare status code
/// tells the user nothing about what to do next.