Tractatus AI Safety Framework
Find a file
TheFlow ebfeadb900 feat: implement Koha donation system backend (Phase 3)
Backend API complete for NZD donation processing via Stripe.

**New Backend Components:**

Database Model:
- src/models/Donation.model.js - Donation schema with privacy-first design
  - Anonymous donations by default, opt-in public acknowledgement
  - Monthly recurring and one-time donation support
  - Stripe integration (customer, subscription, payment tracking)
  - Public transparency metrics aggregation
  - Admin statistics and reporting

Service Layer:
- src/services/koha.service.js - Stripe integration service
  - Checkout session creation (monthly + one-time)
  - Webhook event processing (8 event types)
  - Subscription management (cancel, update)
  - Receipt email generation (placeholder)
  - Transparency metrics calculation
  - Based on passport-consolidated StripeService pattern

Controller:
- src/controllers/koha.controller.js - HTTP request handlers
  - POST /api/koha/checkout - Create donation checkout
  - POST /api/koha/webhook - Stripe webhook receiver
  - GET /api/koha/transparency - Public metrics
  - POST /api/koha/cancel - Cancel recurring donation
  - GET /api/koha/verify/:sessionId - Verify payment status
  - GET /api/koha/statistics - Admin statistics

Routes:
- src/routes/koha.routes.js - API endpoint definitions
- src/routes/index.js - Koha routes registered

**Infrastructure:**

Server Configuration:
- src/server.js - Raw body parsing for Stripe webhooks
  - Required for webhook signature verification
  - Route-specific middleware for /api/koha/webhook

Environment Variables:
- .env.example - Koha/Stripe configuration template
  - Stripe API keys (reuses passport-consolidated account)
  - Price IDs for NZD monthly tiers ($5, $15, $50)
  - Webhook secret for signature verification
  - Frontend URL for payment redirects

**Documentation:**

- docs/KOHA_STRIPE_SETUP.md - Complete setup guide
  - Step-by-step Stripe Dashboard configuration
  - Product and price creation instructions
  - Webhook endpoint setup
  - Testing procedures with test cards
  - Security and compliance notes
  - Production deployment checklist

**Key Features:**

 Privacy-first design (anonymous by default)
 NZD currency support (New Zealand Dollars)
 Monthly recurring subscriptions ($5, $15, $50 NZD)
 One-time custom donations
 Public transparency dashboard metrics
 Stripe webhook signature verification
 Subscription cancellation support
 Receipt tracking (email generation ready)
 Admin statistics and reporting

**Architecture:**

- Reuses existing Stripe account from passport-consolidated
- Separate webhook endpoint (/api/koha/webhook vs /api/stripe/webhook)
- Separate MongoDB collection (koha_donations)
- Compatible with existing infrastructure

**Next Steps:**

- Create Stripe products in Dashboard (use setup guide)
- Build donation form frontend UI
- Create transparency dashboard page
- Implement receipt email service
- Test end-to-end with Stripe test cards
- Deploy to production

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-08 13:35:40 +13:00
audit-reports feat: complete Phase 2 - accessibility, performance, mobile polish 2025-10-08 13:29:26 +13:00
data/mongodb feat: initialize tractatus project with complete directory structure 2025-10-06 23:26:26 +13:00
docs feat: implement Koha donation system backend (Phase 3) 2025-10-08 13:35:40 +13:00
governance docs: Phase 2 kickoff materials & domain migration to agenticgovernance.digital 2025-10-07 13:17:42 +13:00
public feat: complete Phase 2 - accessibility, performance, mobile polish 2025-10-08 13:29:26 +13:00
scripts feat: complete Phase 2 - accessibility, performance, mobile polish 2025-10-08 13:29:26 +13:00
src feat: implement Koha donation system backend (Phase 3) 2025-10-08 13:35:40 +13:00
tests feat: complete Option A & B - infrastructure validation and content foundation 2025-10-07 11:52:38 +13:00
.env.example feat: implement Koha donation system backend (Phase 3) 2025-10-08 13:35:40 +13:00
.gitignore feat: initialize tractatus project with complete directory structure 2025-10-06 23:26:26 +13:00
CLAUDE.md docs: Phase 2 kickoff materials & domain migration to agenticgovernance.digital 2025-10-07 13:17:42 +13:00
ClaudeWeb conversation transcription.md feat: initialize tractatus project with complete directory structure 2025-10-06 23:26:26 +13:00
DEPLOYMENT-2025-10-08.md feat: complete Phase 2 - accessibility, performance, mobile polish 2025-10-08 13:29:26 +13:00
LICENSE docs: update LICENSE copyright to John G Stroh 2025-10-07 23:52:00 +13:00
NEXT_SESSION.md docs: add session handoff documentation 2025-10-07 00:10:24 +13:00
NOTICE legal: add Apache 2.0 copyright headers and NOTICE file 2025-10-08 00:03:12 +13:00
package.json feat: change license from MIT to Apache License 2.0 2025-10-07 23:43:20 +13:00
PERPLEXITY_REVIEW_FILES.md feat: complete Phase 2 - accessibility, performance, mobile polish 2025-10-08 13:29:26 +13:00
README.md feat: change license from MIT to Apache License 2.0 2025-10-07 23:43:20 +13:00
SESSION-HANDOFF-2025-10-08.md feat: complete Phase 2 - accessibility, performance, mobile polish 2025-10-08 13:29:26 +13:00
SESSION_CLOSEDOWN_20251006.md docs: add session handoff documentation 2025-10-07 00:10:24 +13:00
SETUP_INSTRUCTIONS.md feat: add governance document and core utilities 2025-10-06 23:34:40 +13:00
tailwind.config.js feat: fix CSP violations & implement three audience paths 2025-10-07 12:21:00 +13:00
Tractatus-Website-Complete-Specification-v2.0.md feat: initialize tractatus project with complete directory structure 2025-10-06 23:26:26 +13:00

Tractatus AI Safety Framework Website

Status: Development - Phase 1 Implementation Domain: agenticgovernance.digital Project Start: 2025-10-06


Overview

A world-class platform demonstrating the Tractatus-Based LLM Safety Framework through three audience paths (Researcher, Implementer, Advocate), AI-powered features with human oversight, and interactive demonstrations.

Key Innovation: The website implements the Tractatus framework to govern its own AI operations (dogfooding).


Project Structure

tractatus/
├── docs/               # Source markdown & governance documents
├── public/             # Frontend assets (CSS, JS, images)
├── src/                # Backend code (Express, MongoDB)
│   ├── routes/        # API route handlers
│   ├── controllers/   # Business logic
│   ├── models/        # MongoDB models
│   ├── middleware/    # Express middleware
│   │   └── tractatus/ # Framework enforcement
│   ├── services/      # Core services (AI, governance)
│   └── utils/         # Utility functions
├── scripts/            # Setup & migration scripts
├── tests/              # Test suites (unit, integration, security)
├── data/               # MongoDB data directory
└── logs/               # Application & MongoDB logs

Quick Start

Prerequisites

  • Node.js 18+
  • MongoDB 7+
  • Git

Installation

# Clone repository (once GitHub account is set up)
cd /home/theflow/projects/tractatus

# Install dependencies
npm install

# Copy environment variables
cp .env.example .env
# Edit .env with your configuration

# Initialize database
npm run init:db

# Migrate documents
npm run migrate:docs

# Create admin user
npm run seed:admin

# Start development server
npm run dev

The application will be available at http://localhost:9000


Technical Stack

  • Backend: Node.js, Express, MongoDB
  • Frontend: Vanilla JavaScript, Tailwind CSS
  • Authentication: JWT
  • AI Integration: Claude API (Sonnet 4.5) - Phase 2+
  • Testing: Jest, Supertest

Infrastructure

  • MongoDB Port: 27017
  • Application Port: 9000
  • Database: tractatus_dev
  • Systemd Service: mongodb-tractatus.service, tractatus.service

Phase 1 Deliverables (3-4 Months)

Must-Have for Complete Prototype:

  • Infrastructure setup
  • Document migration pipeline
  • Three audience paths (Researcher/Implementer/Advocate)
  • Tractatus governance services (Classifier, Validator, Boundary Enforcer)
  • AI-curated blog with human oversight
  • Media inquiry triage system
  • Case study submission portal
  • Resource directory
  • Interactive demonstrations (classification, 27027, boundary enforcement)
  • Human oversight dashboard
  • Comprehensive testing suite

Development Workflow

Running Tests

npm test                 # All tests with coverage
npm run test:unit        # Unit tests only
npm run test:integration # Integration tests
npm run test:security    # Security tests
npm run test:watch       # Watch mode

Code Quality

npm run lint            # Check code style
npm run lint:fix        # Fix linting issues

Database Operations

npm run init:db         # Initialize database & indexes
npm run migrate:docs    # Import markdown documents
npm run generate:pdfs   # Generate PDF downloads

Governance

This project adheres to the Tractatus framework principles:

  • Sovereignty & Self-determination: No tracking, user control, open source
  • Transparency & Honesty: Public moderation queue, AI reasoning visible
  • Harmlessness & Protection: Privacy-first design, security audits
  • Community & Accessibility: WCAG compliance, three audience paths

All AI actions are governed by:

  1. InstructionPersistenceClassifier
  2. CrossReferenceValidator
  3. BoundaryEnforcer
  4. ContextPressureMonitor
  5. MetacognitiveVerifier

Human Approval Required

All major decisions require human approval:

  • Architectural changes
  • Database schema modifications
  • Security implementations
  • Third-party integrations
  • Values-sensitive content
  • Cost-incurring services

See: CLAUDE.md for complete project context and conventions


Te Tiriti & Indigenous Perspective

This project acknowledges Te Tiriti o Waitangi and indigenous leadership in digital sovereignty. Implementation follows documented indigenous data sovereignty principles (CARE Principles) with respect and without tokenism.

No premature engagement: We will not approach Māori organizations until we have something valuable to offer post-launch.


  • Project Context: CLAUDE.md
  • Specification: Tractatus-Website-Complete-Specification-v2.0.md
  • Framework Documentation: /home/theflow/projects/sydigital/stochastic/innovation-exploration/
  • Governance References: /home/theflow/projects/sydigital/strategic/

License

Apache License 2.0 - See LICENSE file for details.

The Tractatus Framework is licensed under the Apache License 2.0, which provides:

  • Patent protection for users
  • Clear contribution terms
  • Permissive use (commercial, modification, distribution)
  • Compatibility with most other open source licenses

Contact

Project Owner: John Stroh Email: john.stroh.nz@pm.me Repository: GitHub (primary) + Codeberg/Gitea (mirrors)


Last Updated: 2025-10-06 Next Milestone: Complete MongoDB setup and systemd service