Skip to content

Commit 381eb37

Browse files
authored
New GET /line/:lineid?text=blob Feature (#455)
* Gave the agent pipeline a try * Changes while testing and reviewing * No tests * Lines section for API.html * Lines section for API.html * oo bail on this, it needs to be its own task * simplify * Say less in AI assistant files * Changes while reviewing * Changes while reviewing * Remove this section * clean this up a little * clean this up a little * Ah I see this was trying to help how it fails through, but we need these to throw their errors like usual. * Now it fails through how it is supposed to * Now it fails through how it is supposed to * white space lint stuff * How about a redo for reasons * clean up function documentation * changes while reviewing * touchup for function documentation * const * changes during review * changes during review * shape of the refactor * Gotta fix this now then * Gotta fix this now then * Remove the fallback conditionals, the Class will handle it * Remove imported Line function. It is no longer required here * changes from getting demo to run * changes from getting demo to run * Working demo * Changes during review * Changes during review * Gimme those sweet sweet rerum errors * Gimme those sweet sweet rerum errors * Changes during review * changes while testing * oops bad docs * Really take the body from RERUM even if falsey * Changes during standup * Touchups during final review step * Touchups during final review step * Touchups during final review step
1 parent 1b40639 commit 381eb37

4 files changed

Lines changed: 164 additions & 368 deletions

File tree

.claude/CLAUDE.md

Lines changed: 9 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -6,209 +6,35 @@ This file provides guidance to AI Assistants when working with code in this repo
66

77
TPEN Services is a Node.js Express API service for TPEN3 (Transcription for Paleographical and Editorial Notation). This provides RESTful APIs for digital humanities, cultural heritage, annotation services, and IIIF manifest handling. The service supports multiple database backends (MongoDB, MariaDB) and uses Auth0 for authentication.
88

9-
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
10-
119
## Working Effectively
1210

1311
### Bootstrap, Build, and Test the Repository
14-
- Copy environment configuration: `cp .env.development .env`
12+
- Environment configuration is in .env. Do not overwrite the existing .env file. If an .env file does not exist then copy environment configuration: `cp .env.development .env`
1513
- Install dependencies: `npm install` -- takes up to 20 seconds. NEVER CANCEL. Set timeout to 60+ seconds.
16-
- Run unit tests: `npm run unitTests` -- takes 12 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
17-
- Run existence tests: `npm run existsTests` -- takes 7 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
18-
- Run all tests: `npm run allTests` -- takes 12 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
1914

2015
### Run the Application
2116
- ALWAYS run the bootstrapping steps first.
2217
- Production server: `npm start` -- starts on port 3011
2318
- Development server: `npm run dev` -- starts with nodemon auto-reload on port 3011
24-
- Test basic functionality: `curl http://localhost:3011/` should return "TPEN3 SERVICES BABY!!!"
25-
26-
### Environment Requirements
27-
- Node.js >= 22.20.0
28-
- MongoDB (for database tests and full functionality)
29-
- MariaDB (for database tests and full functionality)
30-
- Copy `.env.development` to `.env` for basic functionality
31-
- For full functionality, configure database connection strings in `.env`
19+
- Test basic functionality: `curl http://localhost:3011/API.html` should return the API page.
3220

3321
## Validation
3422

3523
### Always Validate Core Functionality After Changes
36-
- Start the application: `npm start` or `npm run dev`
37-
- Test the root endpoint: `curl http://localhost:3011/` -- should return HTML with "TPEN3 SERVICES BABY!!!"
38-
- Run unit tests that don't require databases: `npm run unitTests` -- many tests pass without database connections
39-
- Run existence tests: `npm run existsTests` -- validates route registration and class imports
40-
- ALWAYS wait for full test completion. Tests may appear to hang but will complete within 12 seconds.
41-
- NOTE: Application may crash after serving initial requests due to database connection attempts - this is expected behavior without running MongoDB/MariaDB.
42-
43-
### Test Categories Available
44-
- `npm run unitTests` -- Core unit tests (some require databases)
45-
- `npm run existsTests` -- Route and class existence validation (database-independent)
46-
- `npm run functionsTests` -- Function-level tests
47-
- `npm run E2Etests` -- End-to-end API tests
48-
- `npm run dbTests` -- Database-specific tests (require running databases)
49-
- `npm run authTest` -- Authentication tests (require Auth0 configuration)
24+
- Run `npm run allTests` once you have completed your task and need to verify correctness before continuing.
25+
- ALWAYS wait for full test completion. Tests can take minutes. NEVER CANCEL.
26+
- NOTE: Application may crash after serving initial requests due to database connection attempts - this is expected behavior without a connection to MongoDB.
5027

5128
### Expected Test Behavior
5229
- Tests requiring databases will timeout/fail without MongoDB/MariaDB running
5330
- Auth tests fail without proper AUDIENCE and DOMAIN environment variables
5431
- Core functionality tests (exists, basic units) should pass with minimal `.env` setup
55-
- Database-independent tests complete in 6-15 seconds
56-
57-
## Common Tasks
58-
59-
### Repository Structure
60-
```
61-
/home/runner/work/TPEN-services/TPEN-services/
62-
├── app.js # Express application setup
63-
├── bin/tpen3_services.js # Server entry point
64-
├── package.json # Dependencies and scripts
65-
├── jest.config.js # Test configuration
66-
├── config.env # Safe defaults (committed)
67-
├── .env.development # Development template
68-
├── .env.production # Production template
69-
├── API.md # API documentation
70-
├── classes/ # Domain model classes
71-
│ ├── Project/ # Project management
72-
│ ├── User/ # User management
73-
│ ├── Group/ # Group management
74-
│ ├── Layer/ # Annotation layers
75-
│ ├── Line/ # Text line handling
76-
│ ├── Page/ # Page management
77-
│ └── Manifest/ # IIIF manifest handling
78-
├── database/ # Database drivers
79-
│ ├── mongo/ # MongoDB controller
80-
│ ├── maria/ # MariaDB controller
81-
│ └── tiny/ # TinyPEN API controller
82-
├── auth/ # Auth0 authentication
83-
├── project/ # Project API routes
84-
├── userProfile/ # User API routes
85-
├── line/ # Line API routes
86-
├── page/ # Page API routes
87-
└── utilities/ # Helper functions
88-
```
89-
90-
### Key API Endpoints
91-
- `GET /` -- Service status (returns "TPEN3 SERVICES BABY!!!")
92-
- `GET /project/:id` -- Get project by ID (requires authentication)
93-
- `POST /project/create` -- Create new project (requires authentication)
94-
- `POST /project/import?createFrom=URL` -- Import project from IIIF manifest
95-
- `GET /user/:id` -- Get user profile (public)
96-
- `GET /my/profile` -- Get authenticated user profile
97-
- `GET /line/:id` -- Get text line annotation
98-
- `GET /page/:id` -- Get annotation page
99-
100-
### Authentication
101-
- Uses Auth0 JWT bearer tokens
102-
- Protected endpoints require `Authorization: Bearer <token>` header
103-
- Environment variables AUDIENCE and DOMAIN must be configured for auth tests
104-
- Public endpoints: `/`, `/user/:id`
105-
- Protected endpoints: `/project/*`, `/my/*`, most POST/PUT/DELETE operations
106-
107-
### Database Configuration
108-
- MongoDB: Configure MONGODB and MONGODBNAME in `.env`
109-
- MariaDB: Configure MARIADB, MARIADBNAME, MARIADBUSER, MARIADBPASSWORD in `.env`
110-
- TinyPEN API: Configure TINYPEN in `.env`
111-
- Default configurations in `config.env` point to localhost development services
112-
- MongoDB Collections: TPENPROJECTS, TPENGROUPS, TPENUSERS, TPENCOLUMNS (configured in `config.env`)
11332

11433
### Development Workflow
115-
1. Always start with: `cp .env.development .env && npm install`
34+
1. Ensure .env exists (if not: `cp .env.development .env`) and run `npm install`
11635
2. Make code changes
117-
3. Test with: `npm run existsTests` (fast, database-independent)
118-
4. For database changes: ensure MongoDB/MariaDB running, then `npm run dbTests`
119-
5. For API changes: `npm run E2Etests`
120-
6. Start dev server: `npm run dev`
121-
7. Test manually: `curl http://localhost:3011/` and relevant endpoints
122-
123-
### Debugging and Troubleshooting
124-
- Application logs appear in console when running `npm start` or `npm run dev`
125-
- Database connection errors indicate missing database services
126-
- Auth errors indicate missing AUDIENCE/DOMAIN environment variables
127-
- 404 errors on routes indicate route registration issues
128-
- Check `app.js` for middleware and route registration
129-
- Jest warnings about experimental VM modules are expected (ES module usage)
130-
131-
### CI/CD Integration
132-
- GitHub Actions workflows in `.github/workflows/`
133-
- `test_pushes.yaml` runs unit tests on pushes
134-
- `ci_dev.yaml` runs E2E tests on PRs to development
135-
- Tests require environment secrets configured in GitHub repository settings
136-
137-
### Performance Notes
138-
- Application startup: 2-3 seconds
139-
- npm install: ~1-20 seconds depending on cache (timeout: 60+ seconds)
140-
- Unit tests: ~12 seconds (timeout: 30+ seconds)
141-
- Existence tests: ~7 seconds (timeout: 30+ seconds)
142-
- Database tests: variable depending on database response times
143-
144-
### Critical Environment Variables
145-
Required for basic functionality:
146-
- `PORT` (default: 3011)
147-
- `SERVERURL` (default: http://localhost:3011)
148-
149-
Required for database functionality:
150-
- `MONGODB` (MongoDB connection string)
151-
- `MONGODBNAME` (MongoDB database name)
152-
- `MARIADB` (MariaDB host)
153-
- `MARIADBNAME`, `MARIADBUSER`, `MARIADBPASSWORD` (MariaDB credentials)
154-
155-
MongoDB collection names (configured in `config.env`):
156-
- `TPENPROJECTS` (default: projects) - Project documents collection
157-
- `TPENGROUPS` (default: groups) - User groups collection
158-
- `TPENUSERS` (default: users) - User profiles collection
159-
- `TPENCOLUMNS` (default: columns) - Column annotations collection
160-
161-
Required for authentication:
162-
- `AUDIENCE` (Auth0 audience)
163-
- `DOMAIN` (Auth0 domain)
164-
165-
Required for external services:
166-
- `TINYPEN` (TinyPEN API base URL)
167-
- `RERUMURL` (RERUM repository URL)
168-
169-
### Manual Testing Scenarios
170-
After making changes, always validate:
171-
1. **Basic Service**: Start server with `npm start`, test with `curl http://localhost:3011/` - should return HTML containing "TPEN3 SERVICES BABY!!!" in the response body
172-
2. **Route Registration**: `npm run existsTests` passes without errors
173-
3. **Core Logic**: `npm run unitTests` passes tests that don't require databases (some MongoDB tests will timeout - this is expected)
174-
4. **API Authentication**: Protected endpoints like `/my/profile` return 401 status code without valid tokens
175-
5. **Application Behavior**: Server may crash after serving requests when MongoDB is not available - this is expected and indicates database connection attempts are working correctly
176-
177-
### Complete Validation Workflow Example
178-
```bash
179-
# Basic setup
180-
cp .env.development .env
181-
npm install
182-
183-
# Test core functionality without databases
184-
npm run existsTests # Should pass completely
185-
npm run unitTests # Should pass most tests, MongoDB tests will timeout
186-
187-
# Test application serving
188-
npm start &
189-
sleep 3
190-
curl http://localhost:3011/ # Should return HTML with service name
191-
curl -w "Status: %{http_code}\n" http://localhost:3011/my/profile # Should return 401
192-
kill %1 # Stop the background server
193-
```
194-
195-
### Common File Locations
196-
- Main application entry: `bin/tpen3_services.js`
197-
- Express app setup: `app.js`
198-
- Route definitions: `project/index.js`, `userProfile/index.js`, etc.
199-
- Database controllers: `database/mongo/controller.js`, `database/maria/controller.js`
200-
- Authentication middleware: `auth/index.js`
201-
- Domain models: `classes/[Entity]/[Entity].js`
202-
- Configuration: `config.env` (safe defaults), `.env.development` and `.env.production` (templates), `.env` (local config, gitignored)
203-
204-
### Dependencies and Versions
205-
- Express.js for REST API framework
206-
- MongoDB driver for document storage
207-
- MariaDB driver for relational storage
208-
- Auth0 libraries for JWT authentication
209-
- Jest for testing framework
210-
- Nodemon for development auto-reload
211-
- IIIF libraries for manifest handling
36+
3. Once the task is complete and verification is needed: `npm run allTests`
37+
4. Start app if manual testing is needed.
21238

21339
### External Resources
21440
- [IIIF Presentation API](https://iiif.io/api/presentation/)
@@ -238,4 +64,4 @@ kill %1 # Stop the background server
23864
7. Use JDoc style for code documentation. Cleanup, fix, or generate documentation for the code you work on as you encounter it.
23965
8. We use `npm start` often to run the app locally. However, do not make code edits based on this assumption. Production and development load balance in the app with pm2, not by using `npm start`
24066
9. NEVER CANCEL long-running commands. Application builds and tests are designed to complete within documented timeouts. Always wait for completion to ensure accurate validation of changes.
241-
10. All work on issues for bugs, features, and enhancements will target the `development` branch. The `main` branch will only be targetted with hotfixes by admins or by PRs from the `development` branch. New work should branch from `development`.
67+
10. All work on issues for bugs, features, and enhancements will target the `development` branch. The `main` branch will only be targetted with hotfixes by admins or by PRs from the `development` branch. New work should branch from `development`.

0 commit comments

Comments
 (0)