| 1 | # Prototype Implementation 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, model Claude Opus 4.7 (1M context).
|
|---|
| 9 |
|
|---|
| 10 | ## Final result
|
|---|
| 11 |
|
|---|
| 12 | ### Results in details / description
|
|---|
| 13 |
|
|---|
| 14 | During the 2026-04-21 session the AI:
|
|---|
| 15 |
|
|---|
| 16 | - Replaced the broken HTTP + frontend scaffolding (which the student had already decided to drop) with a single-binary CLI prototype in Go, split across `main.go`, `cli.go`, `auth.go`, `account.go`, `market.go`, `trade.go`, `portfolio.go`, `watchlist.go`.
|
|---|
| 17 | - Consolidated the broken `db.go` — which used to drop every table on every startup — into a single `Connect()` plus explicit `-init` and `-load-data` flags.
|
|---|
| 18 | - Moved `go.mod` from `server/` to the project root so the same module graph covers both `server/` and `bots/`.
|
|---|
| 19 | - Fixed `go.mod`: removed the unused MySQL driver, promoted `github.com/lib/pq` to a direct dependency.
|
|---|
| 20 | - Implemented the trade flows as real database transactions with row-level `FOR UPDATE` locks, cost-basis bookkeeping, and a ledger row per operation.
|
|---|
| 21 | - Wrote a 140-line market-simulation bot that inserts trades and upserts 1-minute candles every tick.
|
|---|
| 22 | - Exercised the full prototype end-to-end against a running PostgreSQL on port 5433 and verified a sample buy and portfolio view produced the expected numbers.
|
|---|
| 23 |
|
|---|
| 24 | ### Test evidence
|
|---|
| 25 |
|
|---|
| 26 | ```
|
|---|
| 27 | Order executed: buy 0.0100 BTC @ 67140.000000 (notional 671.4000 USD)
|
|---|
| 28 |
|
|---|
| 29 | Symbol Quantity Avg buy Current Value Unrealised P/L
|
|---|
| 30 | BTC 0.0100 67140.000000 67140.000000 671.4000 +0.0000
|
|---|
| 31 | ETH 0.5000 3500.000000 3520.000000 1760.0000 +10.0000
|
|---|
| 32 | TOTAL 2431.4000 +10.0000
|
|---|
| 33 |
|
|---|
| 34 | Cash available : 7578.6000 USD
|
|---|
| 35 | Portfolio value: 2431.4000 USD
|
|---|
| 36 | Net worth : 10010.0000 USD
|
|---|
| 37 | ```
|
|---|
| 38 |
|
|---|
| 39 | ## Summary of AI involvement
|
|---|
| 40 |
|
|---|
| 41 | | | Session 1 — 2026-04-21 | Session 2 — 2026-08-06/07 |
|
|---|
| 42 | |---|---|---|
|
|---|
| 43 | | **What I brought** | My existing Go backend (Chi HTTP handlers) and a half-finished frontend | The CLI prototype as it stood after session 1 |
|
|---|
| 44 | | **What the AI did** | Rewrote the backend as a CLI covering UC0001–UC0007, wrote the market bot | Reviewed the code, found and fixed three bugs, improved the holding upsert |
|
|---|
| 45 | | **What I decided** | To delete the frontend, to build a CLI rather than a web app, to keep the market simulator | To ask for a code review pass rather than documentation alone |
|
|---|
| 46 |
|
|---|
| 47 | The prototype was built in session 1 and worked. What session 2 added was a
|
|---|
| 48 | review pass I asked for specifically because I have to defend this code in
|
|---|
| 49 | person: it turned up a path-resolution bug that made my own documented build
|
|---|
| 50 | instructions fail, an infinite loop at end of input, and an error check in the
|
|---|
| 51 | wrong order that misreported database failures as "Insufficient holding".
|
|---|
| 52 |
|
|---|
| 53 | ## Entire AI usage log
|
|---|
| 54 |
|
|---|
| 55 | See [ERModelAIUsage](../P1-ConceptualModel/ERModelAIUsage.md) for the full prompt/response transcript of the 2026-04-21 session — that single conversation produced all of the P1–P4 artefacts. The defining student prompt for P4 was:
|
|---|
| 56 |
|
|---|
| 57 | > do everything that you need to do, and tell me after what do I need to do
|
|---|
| 58 |
|
|---|
| 59 | which translated into the rewrite of the backend and the writing of this documentation.
|
|---|
| 60 |
|
|---|
| 61 | > **Student action required:** append any further prompts here where you asked the AI to debug, extend, or refactor the prototype.
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | ### Session 2 — 2026-08-06 / 2026-08-07
|
|---|
| 65 |
|
|---|
| 66 | Prompts are logged in full in [ERModelAIUsage](../P1-ConceptualModel/ERModelAIUsage.md#session-2--2026-08-06--2026-08-07).
|
|---|
| 67 | The student asked the AI to complete the phase documentation and to *"fix some
|
|---|
| 68 | database things or golang things if you think we can do it better"*. What the AI
|
|---|
| 69 | changed in the prototype, and why:
|
|---|
| 70 |
|
|---|
| 71 | **Bugs found and fixed**
|
|---|
| 72 |
|
|---|
| 73 | 1. `server/db/db.go` resolved `../.env` and `db/schema_creation.sql` as paths
|
|---|
| 74 | relative to the working directory, so they only worked when the program was
|
|---|
| 75 | started from inside `server/`. Following the documented instructions — build
|
|---|
| 76 | from the repository root and run `./eduberza -init` — failed with
|
|---|
| 77 | `password authentication failed for user "postgres"`, because the `.env` file
|
|---|
| 78 | was never found and the defaults were used. The two SQL scripts are now
|
|---|
| 79 | compiled into the binary with `go:embed`, and `.env` is located by searching
|
|---|
| 80 | the working directory and every parent. Real environment variables now take
|
|---|
| 81 | precedence over the file, which is what allows the prototype to be pointed at
|
|---|
| 82 | the faculty database without editing anything.
|
|---|
| 83 | 2. `prompt()` in `server/cli.go` ignored the error from `ReadString`. At end of
|
|---|
| 84 | input — Ctrl-D, or a scripted run — it returned an empty string forever and
|
|---|
| 85 | the menu loop spun printing "Unknown option." without end. It now exits
|
|---|
| 86 | cleanly.
|
|---|
| 87 | 3. On the sell path, `trade.go` checked `err == sql.ErrNoRows || held < qty`
|
|---|
| 88 | before checking for other errors, so any scan failure was reported to the user
|
|---|
| 89 | as "Insufficient holding" regardless of the real cause. The error check now
|
|---|
| 90 | comes first.
|
|---|
| 91 |
|
|---|
| 92 | **Improvements**
|
|---|
| 93 |
|
|---|
| 94 | 4. The holding upsert was a read-modify-write in Go (`SELECT ... FOR UPDATE`,
|
|---|
| 95 | compute the new weighted average in `float64`, then `INSERT` or `UPDATE`). It
|
|---|
| 96 | is now a single `INSERT … ON CONFLICT (user_id, crypto_id) DO UPDATE`, so the
|
|---|
| 97 | average is recomputed by PostgreSQL in `numeric` arithmetic and the statement
|
|---|
| 98 | relies on the unique constraint that the relational design already declared.
|
|---|
| 99 | 5. `TerraER3.11.jar` was removed from the repository and `.gitignore` now
|
|---|
| 100 | excludes `*.jar`, because P4 requires third-party executables to be
|
|---|
| 101 | downloaded rather than committed. `.env` is excluded too and `.env.example`
|
|---|
| 102 | was added in its place.
|
|---|
| 103 | 6. `image.png`, a TradingView screenshot, was deleted — the project has no
|
|---|
| 104 | licence to publish it and P4 requires explicit usage rights.
|
|---|
| 105 |
|
|---|
| 106 | **Verification**
|
|---|
| 107 |
|
|---|
| 108 | All seven use cases were executed against a live PostgreSQL 16 database. The
|
|---|
| 109 | screenshots on the `UseCaseXXXXImplementation` pages are captures of those runs.
|
|---|
| 110 | The four failure paths were tested, and the rollback behaviour was checked
|
|---|
| 111 | directly in SQL: after a rejected purchase, the affected user has zero rows in
|
|---|
| 112 | `orders`, `transactions` and `holdings`.
|
|---|
| 113 |
|
|---|
| 114 | > **Student action required:** read the changed files (`server/db/db.go`,
|
|---|
| 115 | > `server/cli.go`, `server/trade.go`, `server/db/schema_creation.sql`) before the
|
|---|
| 116 | > presentation. You will be asked how the buy transaction works, and the answer
|
|---|
| 117 | > has to be yours.
|
|---|