source: docs/P1-ConceptualModel/ERModelAIUsage.md@ 9577c79

main
Last change on this file since 9577c79 was 9577c79, checked in by Stefan <trsunovstefan@…>, 13 days ago

add reserved_quantity and modify the phases, add v_03.png and v_03.xml for P1

  • Property mode set to 100644
File size: 16.0 KB
Line 
1# Entity-Relationship Model AI Usage
2
3## Name of AI service/solution that was used
4
5**Claude Code** (Anthropic)
6
7- **URL:** https://claude.com/claude-code
8- **Type of service/subscription:** Claude subscription. Session 1 used model
9 Claude Opus 4.7 (1M context); session 2 used Claude Opus 5 (1M context).
10
11## Final result
12
13### Diagram
14
15`ERModel_v01.xml` / `ERModel_v01.png`.
16
17**Declaration of how the diagram was produced.** The initial model is the
18student's own: the entity and attribute list in [`ep-diagram.md`](ep-diagram.md),
19written in Macedonian before any AI was involved. In session 2 the AI turned that
20list into the TerraER diagram file, and while doing so proposed three changes to
21the initial model, all three listed in the model history on
22[ERModel](ERModel.md#entity-relationship-model-history):
23promoting `Markets` to its own entity set, re-expressing `holdings` and
24`watchlist_items` as M:N relationships with attributes rather than entity sets
25with foreign keys, and marking `avg_price` as derived.
26
27The diagram was not drawn by hand in the TerraER GUI. It was generated
28programmatically by constructing TerraER's own figure objects
29(`EntidadeFigure`, `RelacionamentoFigure`, `AtributoFigure`,
30`AtributoChaveFigure`, `AtributoDerivadoFigure` and the labelled line-connection
31figures) and serialising them with TerraER's own
32`DOMStorableInputOutputFormat` — the same writer the application uses when you
33choose *Save*. The file is therefore a normal TerraER document: it was verified
34by reading it back through TerraER's own reader and comparing the figure count
35(144), and it opens and can be edited in TerraER 3.11 like any hand-drawn
36diagram. `ERModel_v02.xml` is the student's own review pass over v01, done by
37hand in the GUI.
38
39`ERModel_v03.xml` / `ERModel_v03.png` (session 3, 2026-09-16) were produced the
40same way, this time as a genuine load–modify–save round trip through TerraER's
41own classes rather than a from-scratch build: `ERModel_v02.xml` was read with
42the application's real `DrawFigureFactory` and `DOMStorableInputOutputFormat`
43into a live `QuadTreeDrawing`, one `AtributoFigure` was cloned from the
44existing `quantity` attribute of `Holds` (to inherit its exact styling) and
45relabelled `reserved_quantity`, a matching `LabeledLineConnectionFigure` was
46added between it and the `Holds` diamond (`ChopDiamondConnector` /
47`ChopEllipseConnector`, the same connector pair every other attribute of
48`Holds` uses), and every entity and relationship — together with its own
49attributes, moved by the same offset — was translated proportionally toward
50the diagram's centroid to close up excess canvas space, after which every
51connection figure had `updateConnection()` called so its drawn path follows
52the moved figures. The result was written with the real writer and rendered to
53PNG with TerraER's own `ImageOutputFormat`, and re-verified by reading
54`ERModel_v03.xml` back and confirming the figure count (146 = 144 + the new
55attribute + its line) and that all five attributes of `Holds` resolve with the
56expected connector classes. No figure was hand-edited in XML.
57
58### Model description
59
60See [ERModel](ERModel.md).
61
62## Summary of AI involvement
63
64Work on this project happened in three working sessions.
65
66| | Session 1 | Session 2 | Session 3 |
67|---|---|---|---|
68| **When** | 2026-04-21 | 2026-08-06 / 2026-08-07 | 2026-09-16 |
69| **Model** | Claude Opus 4.7 (1M context) | Claude Opus 5 (1M context) | Claude Sonnet 5 |
70| **Phases advanced** | P1, P2, P3 and the first working prototype | The ER diagram file, P4 documentation, bug fixes | `Holds.reserved_quantity` added across P1–P4 |
71| **My starting material** | `ep-diagram.md`, `opis.md`, my existing Go backend and draft SQL | Everything from session 1, plus the phase rubric | Everything from sessions 1–2, plus a design review of the sell-order flow |
72
73In **session 1** I brought my own data model (`ep-diagram.md`, written in
74Macedonian before any AI was involved) and my own draft schema and Go backend. I
75used the AI to review them, and it found real errors in my SQL that I had missed
76— most seriously that I had declared `crypto_id` as a foreign key to two
77different tables at once, in three separate tables. I decided the corrections to
78adopt, chose to go solo, chose a CLI prototype over an HTTP one, and chose
79English for the documentation. The output of that session was the corrected
80schema, the sample-data script, the use-case model and the working prototype.
81
82In **session 2** I came back to produce the deliverable I was still missing — the
83TerraER diagram file itself — and to finish the P4 documentation. I also asked
84for a review pass over the database and Go code, which turned up three further
85bugs (see [PrototypeImplementationAIUsage](../P4-Prototype/PrototypeImplementationAIUsage.md)).
86
87In **session 3** I described a concrete edge case I'd spotted in the sell flow
88— nothing stopped a user from placing a second sell order against crypto
89already promised to a first, unsettled one — and asked the AI to fix it
90starting from P1 and carry the fix through every phase. This added
91`reserved_quantity` to `Holds` and changed the sell path in `trade.go` to use
92it; see the model history on
93[ERModel](ERModel.md#entity-relationship-model-history) (v03) and the log
94below.
95
96Below is the log, one entry per exchange. My prompts are quoted as **excerpts**:
97the wording is my own, unaltered, but I have left out scheduling remarks and
98other working chatter that says nothing about the model or the code. Typos are
99kept as they were. The *Intent* line above each prompt is my own note on what I
100was trying to achieve. AI responses are summarised rather than quoted in full,
101because several ran to many pages of code and file edits. The complete
102unabridged transcript is in my Claude Code session history and can be produced
103on request.
104
105## Entire AI usage log
106
107---
108
109### Session 1 — 2026-04-21
110
111**Intent:** hand the AI the whole project and the course rubric, and have it
112audit my existing model and code against the phase requirements before I commit
113to anything.
114
115**Prompt (student, excerpt):**
116> This is my project for my exam Database, go to the docs folder and README.md there you will find all of the documentation, afterwards take a look at the whole project. Delete everything you want add everything you want just make it work and make it fill in or to follow all of the needed instructions. Ask me anything, also tell me what do I need to do
117
118**Response (AI, summarised):**
119- Read `docs/opis.md`, `docs/ep-diagram.md`, `docs/dbdiagram.md`, `server/db/db.sql`, `server/db/schema.sql`, all Go sources.
120- Flagged bugs in the initial schema:
121 - `holdings.crypto_id` declared as a foreign key to both `users(id)` and `crypto(id)`; should be a separate `user_id` column.
122 - Same mistake in `orders` and `transactions`.
123 - `market_candles` referenced a non-existent `markets` table.
124 - `main.go` dropped and recreated all tables on every startup, wiping data.
125- Proposed a single authoritative schema, to be placed in `server/db/schema_creation.sql`, based on `docs/ep-diagram.md` and `docs/dbdiagram.md` with the above issues fixed.
126- Asked the student for decisions: team composition, prototype shape (CLI vs HTTP), whether to keep `available_balance`, `invested_balance`, `secret_question`, `secret_answer`, which use cases to implement, language of documentation.
127
128**Intent:** I had just pasted the course rubric into `README.md` and removed the
129half-finished frontend, so that the AI would plan against the actual phase
130requirements and against a backend-only prototype.
131
132**Prompt (student, excerpt):**
133> Read it now, just filled it in, also deleted the frontend we don' need that
134
135**Response (AI, summarised):**
136- Re-read `docs/README.md`, which now contained the course phase rubric (P0–P9).
137- Explained the constraints each phase places on AI usage (P0 forbids AI; P1–P4 allow AI only to improve the student's own initial model and require an AIUsage log).
138- Listed the deliverables per phase and asked the remaining questions.
139
140---
141
142### Session 2 — 2026-08-06 / 2026-08-07
143
144**Intent:** re-read the rubric from scratch after the gap, reduce it to a
145checklist of what each phase actually has to produce, confirm TerraER runs on
146this machine.
147
148**Prompt (student, excerpt):**
149> We will start from the begining in some ways, please read first docs/insturctions.md
150> The goal is to finish with milestone 0 so I can publish it […]
151> Read the Instuctions.md like I said and delete everything that you think we don't need
152> and for each phrase tell me what do I need to submit and how to do it. and can you also
153> do the thing with TerraER3.11.jar?
154
155**Response (AI, summarised):**
156- Read the phase rubric and condensed `Instructions.md` to a per-phase checklist
157 of deliverables, keeping every requirement and every load-bearing filename.
158- Confirmed TerraER 3.11 runs on the installed OpenJDK 21 and launched it.
159- Listed, per phase, what has to be submitted and how; flagged that P0's
160 deliverables are wiki pages, that the EPRMS proposal is a prerequisite.
161- Flagged `image.png` (a TradingView screenshot) as material the project has no
162 licence to publish.
163
164**Intent:** produce the artefacts still missing for P1–P4 — above all the TerraER
165diagram — while keeping P0 for myself, since AI use is forbidden there.
166
167**Prompt (student, excerpt):**
168> […] do all of the other Phases till m0.
169> opis.md It's p0 so I will take care of that. Delete anything that we don't need,
170> make all of the phases and terra diagram if you can, and delete anything
171> that we don't need and make a documentation about how to start it.
172
173**Intent:** ask for a review pass over the schema and the Go code rather than
174only documentation, on the grounds that a prototype I have to defend in person
175should not have known defects in it.
176
177**Prompt (student, excerpt, follow-up):**
178> Also fix some database things or golang things if you think we can do it better,
179
180**Response (AI, summarised) — the part relevant to P1:**
181- Read `ep-diagram.md` (the student's own initial model) and the existing
182 `schema_creation.sql`.
183- Reverse-engineered TerraER's file format from the distributed jar to learn the
184 element names it stores figures under (`ent`, `rel`, `atr`, `atrchave`,
185 `atrderivado`, `llabelUm`, `llabelMuitos`, `llabelDoubleUm`,
186 `llabelDoubleMuitos`, …).
187- Generated `ERModel_v01.xml` and `ERModel_v01.png` as described above, in Chen
188 notation: 8 entity sets, 10 relationships, 57 attributes, cardinality labels
189 on every relationship line and double lines for total participation.
190- Proposed the three changes to the initial model recorded in the model history.
191- Rewrote [ERModel](ERModel.md) with the per-entity documentation, candidate-key
192 justifications and attribute types the phase template requires.
193
194---
195
196> **Student action required.** Two things, in this order:
197>
198> 1. Open `ERModel_v01.xml` in TerraER, read the whole diagram, and change what
199> you disagree with. Save the result as `ERModel_v02.xml` with a matching PNG
200> and add a history line. The phase rules require that the model be yours;
201> the generated v01 is a starting point to review and take over, not an
202> answer to submit unread.
203> 2. Verify that this log matches your recollection and append the full text of
204> any further prompts. The complete transcript is in your Claude Code session
205> history.
206
207---
208
209### Session 3 — 2026-09-16
210
211**Intent:** describe a concrete gap I'd found in the sell-order design — the
212model had no way to represent crypto committed to an order that had not yet
213settled — and have the AI trace the fix through every phase rather than patch
214`trade.go` alone.
215
216**Prompt (student, excerpt):**
217> Suppose the user owns 2 BTC and wants to sell 0.5 BTC at market price. […] You
218> currently have Holds: quantity, avg_price but you don't have a concept of
219> reserved/committed crypto. For cash, you already explicitly distinguish
220> available_balance, invested_balance. For crypto, you probably want the
221> equivalent: quantity, reserved_quantity, avg_price. […] Can you please start
222> from Phase 1 and modify everything to make it work like it should, modify
223> the AIUsage.md in every Phase, and can you make the ConceptualModel a little
224> bit more put together not that much spread out.
225
226**Response (AI, summarised):**
227- Read every phase document and the live `server/trade.go`, `portfolio.go` and
228 `schema_creation.sql` to confirm the actual gap: the sell path checked
229 `holdings.quantity` directly, with nothing recording that part of a position
230 was already promised to another order.
231- Added `reserved_quantity` to `Holds` (P1), `holdings` (P2), the sell scenario
232 SQL (P3), and `trade.go`/`portfolio.go`/`schema_creation.sql` (P4) — one
233 attribute threaded consistently through all four phases rather than a
234 patch confined to the Go code.
235- Changed the sell path to lock the holding row, compute
236 `available = quantity − reserved_quantity`, reserve (`reserved_quantity +=
237 qty`) and then settle (`quantity -= qty; reserved_quantity -= qty`) inside
238 the same transaction — keeping the existing all-or-nothing guarantee rather
239 than splitting into two commits, which would leave an unresolvable `open`
240 order if the process died in between and there is no cancel use case to
241 recover it.
242- Made both buy and sell orders genuinely pass through `status='open'` before
243 `status='executed'`, instead of being inserted as `'executed'` directly, so
244 the lifecycle the ER model already claimed for `Orders` is real.
245- Added a `CHECK (reserved_quantity >= 0 AND reserved_quantity <= quantity)`
246 constraint and exposed `reserved_quantity`/`available_quantity` on
247 `v_portfolio` and in the CLI's portfolio table, so the new field is
248 observable rather than a column nobody can see.
249- Restructured this phase's [ERModel](ERModel.md) into short rationale + a
250 compact attribute table per entity/relationship, per the "more put together,
251 not that much spread out" request — no content was removed, only
252 reformatted.
253- Verified the fix against the live database (`bp_database` on `localhost:5433`):
254 ran two concurrent `sell 1.0 BTC` attempts against a holding with only 1.5
255 BTC available — exactly one succeeded, the other correctly reported
256 insufficient holding — and ran the reserve/settle sequence by hand in `psql`
257 to show `reserved_quantity` at 0.5 mid-transaction. Both are recorded in
258 [UseCase0005Implementation](../P4-Prototype/UseCase0005Implementation.md).
259
260**What I decided:** to keep reserve and settle inside one transaction rather
261than two (see the AI's reasoning above — I agreed with it, since a stuck
262`open` order with no cancel command would be a worse bug than the one being
263fixed).
264
265**Follow-up, same day:** I asked for `ERModel_v03.xml`/`.png` after all,
266having noticed the PNG still showed v02 with no `reserved_quantity` on it, and
267asked at the same time for the diagram to be a little more compact — it had a
268lot of empty canvas in the middle. The AI drove TerraER's own classes directly
269(load → clone the `quantity` attribute → relabel it → add its connecting line
270→ pull every cluster toward the centroid → save → render), described in full
271under [Diagram](#diagram) above, rather than hand-editing the XML or asking me
272to do it in the GUI. I reviewed the rendered PNG before accepting it.
273
274**Second follow-up, same day:** the first `ERModel_v03.png` rendered with a
275black background instead of white, unlike v01/v02. Cause: TerraER's
276`ImageOutputFormat` defaults to an ARGB image and paints its background with
277zero alpha (transparent), not opaque white; whatever displayed the PNG then
278flattened that transparency onto black instead of white. Fixed by exporting
279through the same `ImageOutputFormat.toImage(...)` call for figure geometry,
280but compositing its result onto an explicitly white-filled opaque `RGB` image
281before saving, rather than trusting the library's own (transparent) output.
282Verified the fix by reading back the corner pixel of the written PNG as pure
283white `(255,255,255)`, matching `ERModel_v02.png`.
284
285> **Student action required.** Open `ERModel_v03.xml` in TerraER and read it
286> end to end before submission — see the note at the end of
287> [ERModel](ERModel.md). Everything else in this session's diff is already
288> applied to the docs and to `server/`.
Note: See TracBrowser for help on using the repository browser.