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