Files
iotlcm/docs/superpowers/plans/2026-07-13-sqlite-generated-cards.md
T

3.7 KiB

SQLite Generated Cards Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Replace the MySQL-backed card source with a local SQLite-backed mock data generator, fixed traffic values, and Excel export.

Architecture: The service will use SQLite as the runtime persistence layer and keep the existing in-memory Store shape for OneLink handlers. The admin sync action becomes card generation: it appends generated rows to SQLite and refreshes memory. Excel export maps stored card rows to the inbound workbook column format.

Tech Stack: Go net/http, database/sql, SQLite driver, Vue 3, Vite, simple XLSX generation via Go standard library zip/XML.


Task 1: Lock Generated Card Rules With Tests

Files:

  • Test: internal/app/generator_test.go

  • Create: internal/app/generator.go

  • Write tests that generated cards use timestamp-related unique identifiers, fixed monthly traffic 18432 KB, APN CMIOT, and export metadata matching the confirmed sample.

  • Run go test ./internal/app -run TestGenerated -count=1 and verify it fails because the generator does not exist.

  • Implement the minimal generator API and constants.

  • Run the focused test and verify it passes.

Task 2: Replace MySQL Backend With SQLite Backend

Files:

  • Modify: go.mod

  • Modify: internal/app/store_file.go

  • Create/modify: internal/app/store_sqlite.go

  • Modify: internal/app/store.go

  • Test: internal/app/store_test.go

  • Add tests that NewStoreManager no longer requires BAFFLE_DB_DSN, loads from SQLite, and appends generated cards without deleting existing rows.

  • Run focused tests and verify failure.

  • Implement SQLite schema creation, load, save, delete, and append generation behavior.

  • Remove runtime database reload from Snapshot() so normal reads do not hit external DB logic.

  • Run focused tests and verify pass.

Task 3: Admin API And Excel Export

Files:

  • Modify: internal/app/admin.go

  • Create: internal/app/export_xlsx.go

  • Test: internal/app/admin_test.go or existing app tests

  • Add tests for POST /api/generate with count, and GET /api/cards/export returning XLSX bytes with the confirmed headers.

  • Run focused tests and verify failure.

  • Implement generate and export handlers.

  • Run focused tests and verify pass.

Task 4: Remove Traffic Growth From Runtime

Files:

  • Modify: internal/app/store.go

  • Modify: internal/app/model.go

  • Modify: internal/app/admin.go

  • Test: internal/app/store_test.go

  • Add or update tests to prove snapshot does not increment traffic over time.

  • Remove applyGrowthLocked() calls and UI-facing settings behavior.

  • Keep fixed traffic values in generated card records.

  • Run focused tests and verify pass.

Task 5: Frontend Update

Files:

  • Modify: frontend/src/main.js

  • Modify: frontend/src/style.css

  • Replace "一键同步" with "一键生成".

  • Add generation count input.

  • Call POST /api/generate.

  • Add export button linking/downloading from /api/cards/export.

  • Remove traffic growth controls and growth column.

  • Run npm run build in frontend.

Task 6: Documentation And Verification

Files:

  • Modify: README.md

  • Modify: docker-compose.yaml

  • Modify: docker-compose.yaml if needed

  • Update docs to describe SQLite, generation, export, and fixed traffic.

  • Remove MySQL DSN instructions.

  • Run go test ./... with a writable GOCACHE.

  • Run frontend build.

  • Check git diff for unintended changes.