buildlog 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ # Build Journal: User Authentication API
2
+
3
+ **Date:** 2026-01-01
4
+ **Duration:** 4 hours
5
+ **Status:** Complete
6
+
7
+ ---
8
+
9
+ ## The Goal
10
+
11
+ Add JWT-based authentication to our REST API. Users need to register, login, and access protected endpoints. We're using Express.js with a PostgreSQL database.
12
+
13
+ This is foundational infrastructure - every future feature depends on knowing who the user is.
14
+
15
+ ---
16
+
17
+ ## What We Built
18
+
19
+ ### Architecture
20
+
21
+ ```
22
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
23
+ │ Client │────▶│ Express │────▶│ PostgreSQL │
24
+ │ │ │ + JWT │ │ (users) │
25
+ └─────────────┘ └─────────────┘ └─────────────┘
26
+
27
+ ┌─────▼─────┐
28
+ │ bcrypt │
29
+ │ (hashing) │
30
+ └───────────┘
31
+ ```
32
+
33
+ ### Components
34
+
35
+ | Component | Status | Notes |
36
+ |-----------|--------|-------|
37
+ | POST /auth/register | Working | Creates user, returns JWT |
38
+ | POST /auth/login | Working | Validates creds, returns JWT |
39
+ | GET /auth/me | Working | Returns current user from token |
40
+ | authMiddleware | Working | Protects routes |
41
+ | User model | Working | email, password_hash, created_at |
42
+
43
+ ---
44
+
45
+ ## The Journey
46
+
47
+ ### Phase 1: Database Setup
48
+
49
+ **What we tried:**
50
+ Set up the users table with a simple schema.
51
+
52
+ **What happened:**
53
+ Forgot to add a unique constraint on email. Found out when registration started silently creating duplicate users.
54
+
55
+ ```
56
+ ERROR: duplicate key value violates unique constraint "users_email_key"
57
+ ```
58
+
59
+ Wait, no - we didn't get this error. That's the problem. Duplicates were allowed.
60
+
61
+ **The fix:**
62
+ ```sql
63
+ ALTER TABLE users ADD CONSTRAINT users_email_unique UNIQUE (email);
64
+ ```
65
+
66
+ **Lesson:**
67
+ Always add unique constraints at the database level, not just application validation.
68
+
69
+ ---
70
+
71
+ ### Phase 2: Password Hashing
72
+
73
+ **What we tried:**
74
+ Used bcrypt to hash passwords on registration.
75
+
76
+ **What happened:**
77
+ Login always failed. Spent 30 minutes debugging before realizing we were comparing the plaintext password to itself, not to the hash.
78
+
79
+ ```javascript
80
+ // Wrong - comparing password to password
81
+ const valid = await bcrypt.compare(password, password);
82
+
83
+ // Right - comparing password to stored hash
84
+ const valid = await bcrypt.compare(password, user.password_hash);
85
+ ```
86
+
87
+ **The fix:**
88
+ Actually read the bcrypt docs. `compare(plaintext, hash)` - order matters.
89
+
90
+ **Lesson:**
91
+ When auth fails silently, log what you're actually comparing (redacted).
92
+
93
+ ---
94
+
95
+ ### Phase 3: JWT Middleware
96
+
97
+ **What we tried:**
98
+ Created middleware to verify JWT and attach user to request.
99
+
100
+ **What happened:**
101
+ Tokens from yesterday stopped working. Turns out we set expiry to 1 hour but were testing with day-old tokens from our notes.
102
+
103
+ ```
104
+ JsonWebTokenError: jwt expired
105
+ ```
106
+
107
+ **The fix:**
108
+ Set expiry to 7 days for development, added refresh token TODO for production.
109
+
110
+ **Lesson:**
111
+ Use short expiry in tests, longer in dev. Don't copy-paste tokens between sessions.
112
+
113
+ ---
114
+
115
+ ## Test Results
116
+
117
+ ### Registration
118
+
119
+ **Command:**
120
+ ```bash
121
+ curl -X POST http://localhost:3000/auth/register \
122
+ -H "Content-Type: application/json" \
123
+ -d '{"email": "test@example.com", "password": "secretpass123"}'
124
+ ```
125
+
126
+ **Response:**
127
+ ```json
128
+ {
129
+ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
130
+ "user": {
131
+ "id": 1,
132
+ "email": "test@example.com",
133
+ "created_at": "2026-01-01T10:30:00Z"
134
+ }
135
+ }
136
+ ```
137
+
138
+ **Result:** Pass - user created, token returned
139
+
140
+ ### Protected Route
141
+
142
+ **Command:**
143
+ ```bash
144
+ curl http://localhost:3000/auth/me \
145
+ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
146
+ ```
147
+
148
+ **Response:**
149
+ ```json
150
+ {
151
+ "id": 1,
152
+ "email": "test@example.com"
153
+ }
154
+ ```
155
+
156
+ **Result:** Pass - user data returned from token
157
+
158
+ ---
159
+
160
+ ## Code Samples
161
+
162
+ ### Auth Middleware
163
+
164
+ ```javascript
165
+ const authMiddleware = async (req, res, next) => {
166
+ const header = req.headers.authorization;
167
+ if (!header?.startsWith('Bearer ')) {
168
+ return res.status(401).json({ error: 'No token provided' });
169
+ }
170
+
171
+ try {
172
+ const token = header.slice(7);
173
+ const payload = jwt.verify(token, process.env.JWT_SECRET);
174
+ req.user = await User.findById(payload.userId);
175
+ next();
176
+ } catch (err) {
177
+ res.status(401).json({ error: 'Invalid token' });
178
+ }
179
+ };
180
+ ```
181
+
182
+ This middleware extracts the JWT, verifies it, and attaches the full user object to the request. The `?.` optional chaining handles missing headers gracefully.
183
+
184
+ ---
185
+
186
+ ## What's Left
187
+
188
+ - [ ] Refresh token implementation
189
+ - [ ] Password reset flow
190
+ - [ ] Rate limiting on auth endpoints
191
+ - [ ] Email verification
192
+
193
+ ---
194
+
195
+ ## Cost/Performance Analysis
196
+
197
+ | Metric | Value | Notes |
198
+ |--------|-------|-------|
199
+ | bcrypt rounds | 12 | ~250ms hash time, good balance |
200
+ | JWT expiry | 7 days | Too long for prod, fine for dev |
201
+ | Token size | 284 bytes | Acceptable for headers |
202
+
203
+ ---
204
+
205
+ ## AI Experience Reflection
206
+
207
+ ### What Worked Well
208
+
209
+ - Incremental approach: got each endpoint working before moving to the next
210
+ - Agent suggested adding the unique constraint after I described the duplicate user bug
211
+ - Quick iteration on the curl commands for testing
212
+
213
+ ### What Was Frustrating
214
+
215
+ - Spent too long on the bcrypt comparison bug - should have asked for help sooner
216
+ - Context about the existing database schema was lost mid-conversation
217
+
218
+ ### Communication Notes
219
+
220
+ - Worked best when I described the symptom ("login always fails") rather than my guess ("I think JWT is broken")
221
+ - Breaking the work into phases helped maintain focus
222
+
223
+ ---
224
+
225
+ ## Improvements
226
+
227
+ *Actionable learnings for future work.*
228
+
229
+ ### Architectural
230
+
231
+ - Should have added database constraints BEFORE writing application code - the schema is the source of truth
232
+ - Password hashing belongs in the User model (as a pre-save hook), not in the route handler
233
+
234
+ ### Workflow
235
+
236
+ - Write the curl test commands FIRST, then implement to make them pass - TDD but for APIs
237
+ - Test with fresh tokens, not ones from previous sessions
238
+
239
+ ### Tool Usage
240
+
241
+ - Use `jwt.io` to decode tokens when debugging - faster than console.log
242
+ - The `--verbose` flag on curl shows headers, useful for auth debugging
243
+
244
+ ### Domain Knowledge
245
+
246
+ - bcrypt.compare() argument order is (plaintext, hash) - not obvious
247
+ - JWT expiry is in seconds when using jsonwebtoken library, not milliseconds
248
+ - PostgreSQL unique constraints create an index automatically - no need to add one separately
249
+
250
+ ---
251
+
252
+ ## Files Changed
253
+
254
+ ```
255
+ src/
256
+ ├── routes/
257
+ │ └── auth.js # Register, login, me endpoints
258
+ ├── middleware/
259
+ │ └── auth.js # JWT verification middleware
260
+ ├── models/
261
+ │ └── user.js # User model with password hashing
262
+ └── db/
263
+ └── migrations/
264
+ └── 001_users.sql # Users table with constraints
265
+ ```
266
+
267
+ ---
268
+
269
+ *Next entry: Adding role-based access control (admin vs regular users)*
@@ -0,0 +1,114 @@
1
+ # Build Journal System
2
+
3
+ A documentation-as-code system for capturing development work as publishable content.
4
+
5
+ ## Philosophy
6
+
7
+ 1. **Write fast, not pretty** - "Refrigerator to-do list" energy
8
+ 2. **Never delete mistakes** - They're the most valuable teaching content
9
+ 3. **Include the journey** - Wrong turns > polished outcomes
10
+ 4. **AI reflection is required** - Meta-commentary on the collaboration itself
11
+
12
+ ## Directory Structure
13
+
14
+ ```
15
+ buildlog/
16
+ ├── BUILDLOG_SYSTEM.md # This file (system docs)
17
+ ├── _TEMPLATE.md # Entry template
18
+ ├── 2026-01-15-runpod-deploy.md # Entries by date + slug
19
+ ├── 2026-01-16-supabase-storage.md
20
+ └── assets/ # Screenshots, outputs
21
+ ├── viking-portrait.png
22
+ └── error-screenshot.png
23
+ ```
24
+
25
+ ## Entry Template
26
+
27
+ Copy `_TEMPLATE.md` for each new entry. Sections:
28
+
29
+ ### Required Sections
30
+
31
+ | Section | Purpose |
32
+ |---------|---------|
33
+ | **The Goal** | What we're building and why (1-2 paragraphs) |
34
+ | **What We Built** | Architecture, components table |
35
+ | **The Journey** | Chronological, including fuckups |
36
+ | **Test Results** | Actual commands, actual outputs |
37
+ | **Code Samples** | Key snippets, not full files |
38
+ | **AI Experience** | Reflection on collaboration |
39
+ | **Improvements** | Actionable learnings for next time (see below) |
40
+
41
+ ### Optional Sections
42
+
43
+ | Section | When to Include |
44
+ |---------|-----------------|
45
+ | **Cost Analysis** | Infrastructure/API costs involved |
46
+ | **Performance** | Benchmarks, timing data |
47
+ | **What's Left** | If work is incomplete |
48
+ | **Screenshots** | When visual context helps |
49
+
50
+ ### The Improvements Section
51
+
52
+ The **Improvements** section is critical for accumulating knowledge over time. It captures actionable learnings in four categories:
53
+
54
+ | Category | What to Capture |
55
+ |----------|-----------------|
56
+ | **Architectural** | Better design patterns, abstractions, system structure |
57
+ | **Workflow** | Better development process, order of operations |
58
+ | **Tool Usage** | More effective use of available tools and capabilities |
59
+ | **Domain Knowledge** | Technology-specific facts that apply broadly |
60
+
61
+ Write these as **concrete, reusable insights** - not vague observations. Bad: "Should have planned better." Good: "Should have defined the API contract before implementing the client."
62
+
63
+ These entries form the substrate for future knowledge extraction. Even raw natural language thoughts are valuable here.
64
+
65
+ ## When to Write Entries
66
+
67
+ Write an entry when:
68
+ - Major feature/component completed
69
+ - Significant debugging session resolved
70
+ - Infrastructure deployed
71
+ - After any 2+ hour focused session
72
+ - Before context-switching to different work
73
+
74
+ ## Quality Bar
75
+
76
+ Each entry should be **publishable** as:
77
+ - Envato Tuts+ tutorial ($500-750 value)
78
+ - Manning/O'Reilly book chapter
79
+ - Dev.to / Hashnode article
80
+ - Internal team knowledge base
81
+
82
+ This means:
83
+ - Complete code samples that actually run
84
+ - Real error messages, not sanitized versions
85
+ - Honest reflection on what didn't work
86
+
87
+ ## AI Instructions (for CLAUDE.md)
88
+
89
+ Add to your project's CLAUDE.md:
90
+
91
+ ```markdown
92
+ ## Build Journal
93
+
94
+ After completing significant work (features, debugging sessions, deployments),
95
+ write a build journal entry to `buildlog/YYYY-MM-DD-{slug}.md`.
96
+
97
+ Use the template at `buildlog/_TEMPLATE.md`. Include:
98
+ - The goal and what was built
99
+ - The journey INCLUDING mistakes and wrong turns
100
+ - Actual test commands and outputs
101
+ - Code samples with context
102
+ - AI Experience reflection on the collaboration
103
+
104
+ Quality bar: Publishable as a $500+ tutorial article.
105
+
106
+ Ask user: "Should I write a build journal entry for this work?"
107
+ ```
108
+
109
+ ## Maintenance
110
+
111
+ - Review monthly for patterns/themes
112
+ - Extract recurring mistakes into "lessons learned"
113
+ - Consider publishing standout entries
114
+ - Link related entries together
@@ -0,0 +1,162 @@
1
+ # Build Journal: [TITLE]
2
+
3
+ **Date:** [YYYY-MM-DD]
4
+ **Duration:** [X hours]
5
+ **Status:** [Complete | Partial | Blocked]
6
+
7
+ ---
8
+
9
+ ## The Goal
10
+
11
+ [1-2 paragraphs: What are we building? Why does it matter? What problem does it solve?]
12
+
13
+ ---
14
+
15
+ ## What We Built
16
+
17
+ ### Architecture
18
+
19
+ ```
20
+ [ASCII diagram of the system/component]
21
+ ```
22
+
23
+ ### Components
24
+
25
+ | Component | Status | Notes |
26
+ |-----------|--------|-------|
27
+ | [Name] | [Working/Pending/Blocked] | [Brief note] |
28
+
29
+ ---
30
+
31
+ ## The Journey
32
+
33
+ ### [Phase/Hour 1]: [Title]
34
+
35
+ **What we tried:**
36
+ [Approach taken]
37
+
38
+ **What happened:**
39
+ [Actual result, including errors]
40
+
41
+ ```
42
+ [Actual error message or output]
43
+ ```
44
+
45
+ **The fix:**
46
+ [What resolved it]
47
+
48
+ **Lesson:**
49
+ [One-liner takeaway]
50
+
51
+ ---
52
+
53
+ ### [Phase/Hour 2]: [Title]
54
+
55
+ [Repeat pattern...]
56
+
57
+ ---
58
+
59
+ ## Test Results
60
+
61
+ ### [Test Name]
62
+
63
+ **Command:**
64
+ ```bash
65
+ [Actual command run]
66
+ ```
67
+
68
+ **Response:**
69
+ ```json
70
+ [Actual response received]
71
+ ```
72
+
73
+ **Result:** [Pass/Fail + brief assessment]
74
+
75
+ ---
76
+
77
+ ## Code Samples
78
+
79
+ ### [Component/Function Name]
80
+
81
+ ```[language]
82
+ [Key code snippet - not entire file, just the important parts]
83
+ ```
84
+
85
+ [Brief explanation of why this code matters]
86
+
87
+ ---
88
+
89
+ ## What's Left
90
+
91
+ - [ ] [Pending task 1]
92
+ - [ ] [Pending task 2]
93
+ - [ ] [Blocker or dependency]
94
+
95
+ ---
96
+
97
+ ## Cost/Performance Analysis
98
+
99
+ | Metric | Value | Notes |
100
+ |--------|-------|-------|
101
+ | [Time/Cost/Memory] | [Value] | [Context] |
102
+
103
+ ---
104
+
105
+ ## AI Experience Reflection
106
+
107
+ ### What Worked Well
108
+
109
+ [Specific things about the collaboration that were effective]
110
+
111
+ ### What Was Frustrating
112
+
113
+ [Pain points, unclear instructions, context loss]
114
+
115
+ ### Communication Notes
116
+
117
+ [Observations about pace, tone, information density, interruptions]
118
+
119
+ ---
120
+
121
+ ## Improvements
122
+
123
+ *Actionable learnings for future work. This section accumulates knowledge that can improve agent practices over time.*
124
+
125
+ ### Architectural
126
+
127
+ [Things to do differently in system design, abstractions, patterns]
128
+ - [e.g., "Should have used a plugin architecture from the start instead of hardcoding backends"]
129
+ - [e.g., "The retry logic belongs in a shared util, not duplicated across services"]
130
+
131
+ ### Workflow
132
+
133
+ [Better approaches to the development process itself]
134
+ - [e.g., "Run the type checker before committing, not after"]
135
+ - [e.g., "Should have written the integration test first to clarify the API contract"]
136
+
137
+ ### Tool Usage
138
+
139
+ [More effective ways to use available tools and capabilities]
140
+ - [e.g., "Use grep with -C flag for context instead of reading entire files"]
141
+ - [e.g., "The batch endpoint would have been faster than individual requests"]
142
+
143
+ ### Domain Knowledge
144
+
145
+ [Things learned about the specific technology/domain that apply broadly]
146
+ - [e.g., "ComfyUI node IDs must be strings, not integers"]
147
+ - [e.g., "Supabase storage returns 400 not 404 for missing files"]
148
+
149
+ ---
150
+
151
+ ## Files Changed
152
+
153
+ ```
154
+ path/to/
155
+ ├── changed/
156
+ │ └── file.ext # Brief description
157
+ └── another.ext # Brief description
158
+ ```
159
+
160
+ ---
161
+
162
+ *Next entry: [Preview of what's coming]*