Core Values (TRA-VAL-0001): - Adapt STR-VAL-0001 for Tractatus AI Safety Framework - Define 6 core values: Sovereignty, Transparency, Harmlessness, Human Judgment Primacy, Community, Biodiversity - Establish AI governance principles and decision framework - Document Te Tiriti commitment as strategic baseline - Create values alignment metrics and review process Database Utilities: - MongoDB connection with retry logic and health checks - Singleton pattern for connection management - Comprehensive error handling and reconnection Logger Utility: - Winston-based logging (console + file) - Request logging middleware - Error log separation - Configurable log levels JWT Utility: - Token generation and verification - Secure admin authentication - Header extraction methods Markdown Utility: - Markdown to HTML conversion with syntax highlighting - XSS protection via sanitization - Table of contents extraction - Front matter parsing - Slug generation Status: Core infrastructure utilities complete
5.1 KiB
Tractatus Infrastructure Setup - Terminal Commands
Run these commands in a separate terminal window
Current directory: /home/theflow/projects/tractatus
Step 1: Install Node.js Dependencies
cd /home/theflow/projects/tractatus
npm install
Expected output: Installation of ~20 packages (express, mongodb, jwt, etc.) Time: ~30-60 seconds
Step 2: Create Environment Configuration
cp .env.example .env
Optional: Edit .env if you need custom settings (defaults are fine for development)
nano .env # or use your preferred editor
The defaults are:
PORT=9000MONGODB_URI=mongodb://localhost:27017/tractatus_devNODE_ENV=development
Press Ctrl+X to exit nano if you opened it
Step 3: Install MongoDB Systemd Service
cd /home/theflow/projects/tractatus/scripts
sudo ./install-mongodb-service.sh
Expected output:
Installing MongoDB Tractatus systemd service...
Copying service file to /etc/systemd/system...
Reloading systemd daemon...
Enabling service to start on boot...
MongoDB Tractatus service installed successfully!
You will be prompted for your sudo password
Step 4: Start MongoDB Service
sudo systemctl start mongodb-tractatus
Verify it's running:
sudo systemctl status mongodb-tractatus
Expected output: Active: active (running) in green
Check the logs:
tail -f /home/theflow/projects/tractatus/logs/mongodb.log
You should see: MongoDB startup messages Press Ctrl+C to exit tail
Step 5: Verify MongoDB Port
lsof -i :27017
Expected output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod xxxxx theflow xx IPv4 xxxxxx 0t0 TCP localhost:27017 (LISTEN)
Verify it's on port 27017, NOT 27027 (family-history)
Step 6: Initialize Database
cd /home/theflow/projects/tractatus
npm run init:db
Expected output:
🚀 Starting Tractatus database initialization...
✅ Connected to MongoDB
📦 Processing collection: documents
✓ Created collection
✓ Created index: slug_1
...
✨ Database initialization complete!
This creates 10 collections with indexes
Step 7: Verify Database Setup
mongosh mongodb://localhost:27017/tractatus_dev --eval "db.getCollectionNames()"
Expected output: Array of 10 collection names
Alternative verification:
mongosh mongodb://localhost:27017/tractatus_dev
Then in the MongoDB shell:
show collections
db.documents.getIndexes()
exit
Step 8: Check Application Readiness
cd /home/theflow/projects/tractatus
npm run dev
Expected: Server will fail because we haven't built src/server.js yet
This is normal! Claude Code is building it now.
Press Ctrl+C to stop if it started
Troubleshooting
MongoDB won't start?
Check if port 27017 is already in use:
lsof -i :27017
If something else is using it, we'll use port 27029 instead:
# Edit the service file
sudo nano /etc/systemd/system/mongodb-tractatus.service
# Change all instances of 27017 to 27029
# Save and exit
# Reload and restart
sudo systemctl daemon-reload
sudo systemctl restart mongodb-tractatus
Permission errors?
Ensure MongoDB data directory is owned by your user:
sudo chown -R theflow:theflow /home/theflow/projects/tractatus/data/mongodb
sudo chown -R theflow:theflow /home/theflow/projects/tractatus/logs
npm install fails?
Check Node.js version (must be 18+):
node --version
If < 18, update Node.js first
Infrastructure Status Checklist
After completing steps above, verify:
npm installcompleted successfully.envfile created- MongoDB systemd service installed
- MongoDB service running on port 27017
- Database initialized (10 collections created)
- No port conflicts with family-history (27027)
What Claude Code is Building Now
While you run these commands, Claude Code is:
- ✅ Adapting governance documents (TRA-VAL-0001 from STR-VAL-0001)
- ✅ Building database utilities and models
- ✅ Creating Express server foundation
- ✅ Implementing Tractatus governance services
- ✅ Building core API routes
- ⏳ Will continue with features...
When Setup is Complete
Run this to verify everything:
cd /home/theflow/projects/tractatus
npm run dev
Expected output:
🚀 Tractatus server starting...
✅ Connected to MongoDB: tractatus_dev
✅ Server listening on port 9000
✨ Ready for development
Open browser: http://localhost:9000 (will show basic response)
Service Management Commands
Start MongoDB:
sudo systemctl start mongodb-tractatus
Stop MongoDB:
sudo systemctl stop mongodb-tractatus
Restart MongoDB:
sudo systemctl restart mongodb-tractatus
Check status:
sudo systemctl status mongodb-tractatus
View logs:
sudo journalctl -u mongodb-tractatus -f
Questions? Check CLAUDE.md or ask during next session.