This document provides essential information for developers working on the TTRPG Handler project.
The application requires several environment variables to function properly. Create a .env file in the project root with the following variables:
# Database Locations
FIREHOSE_SQLITE_LOCATION=path/to/firehose.sqlite
TTRPG_SQLITE_LOCATION=path/to/ttrpg.sqlite
# Bluesky/AT Protocol Configuration
FEEDGEN_SUBSCRIPTION_ENDPOINT="wss://bsky.network"
AGENT_PASSWORD=your_password_here
# Optional: Service DID (if different from did:web)
# FEEDGEN_SERVICE_DID="did:plc:abcde..."
# Performance Settings
FEEDGEN_SUBSCRIPTION_RECONNECT_DELAY=3000
CRAWL_DELAY=500
# Logging Configuration
OZONE_ENABLED=0
LOG_DESTINATION=logs/app.log
LOG_ENABLED=1
LOG_LEVEL=info
The project uses TypeScript and requires compilation before running:
# Install dependencies
yarn
# Build the project
yarn buildThe compiled output will be in the dist directory.
# Development mode (with ts-node)
yarn start
# Production mode (after building)
node dist/index.jsThe project includes Docker configuration for containerized deployment:
-
Build the Docker image:
docker build -t ttrpg-handler . -
Run with Docker Compose:
docker-compose up -d
Note: The Docker setup expects environment variables to be provided through the .env file. The .env file is mounted into the container, not baked into the image.
The project uses Kysely for database migrations. To run migrations:
yarn migrateThis will apply all pending migrations to the TTRPG database.
Tests use Jest as the testing framework. Test-specific environment variables can be set in test.env:
LOG_ENABLED=true
LOG_DESTINATION=test.log
# Run all tests
yarn test
# Run specific test file
yarn test tests/path/to/test.js
# Run tests with coverage
yarn test --coverageTests are located in the tests directory. The project follows these testing patterns:
-
Service Tests: Test service-level functionality in isolation
- Located in
tests/services/ - Example:
character-service.test.ts
- Located in
-
Integration Tests: Test interaction between components
- Located in the root of the
testsdirectory - Example:
event-handler.test.ts
- Located in the root of the
import { SomeService } from '../src/services/some-service'
import { createTtrpgDb, migrateTtrpgToLatest, TtrpgDatabase } from '../src/db'
describe('Service Tests', () => {
let db: TtrpgDatabase
beforeAll(async () => {
// Use in-memory database for tests
db = createTtrpgDb(':memory:')
await migrateTtrpgToLatest(db)
// Set up test data
// ...
})
beforeEach(() => {
// Set up mocks or spies
// ...
})
afterEach(() => {
// Clean up mocks
jest.restoreAllMocks()
})
it('should perform some action', async () => {
// Arrange
const service = new SomeService(db)
const input = { /* ... */ }
// Act
const result = await service.someMethod(input)
// Assert
expect(result).toEqual(/* expected output */)
})
})The project uses Jest's mocking capabilities. Common patterns include:
-
Function Mocks:
const mockFunction = jest.spyOn(module, 'function').mockImplementation(() => mockReturn)
-
Module Mocks:
jest.mock('../path/to/module', () => ({ function: jest.fn().mockReturnValue(mockValue) }))
src/: Source codedb/: Database-related code (schema, migrations)services/: Business logic servicesutil/: Utility functionsvo/: Value objects (data structures)helpers/: Helper functions for specific domains
-
Database Layer:
- Uses Kysely for type-safe SQL queries
- Schema defined in
src/db/schema.ts - Migrations in
src/db/migrations.ts
-
Service Layer:
- Services handle business logic
- Examples:
character-service.ts,adventure-service.ts
-
AT Protocol Integration:
- Agent configuration in
src/agent.ts - Bluesky-specific functionality
- Agent configuration in
The application uses Pino for logging:
import { logger } from './util/logger'
logger.info('Some message')
logger.error({ err }, 'Error occurred')Configure logging behavior through environment variables:
LOG_ENABLED: Enable/disable logging (true/false)LOG_LEVEL: Set log level (debug, info, warn, error)LOG_DESTINATION: Log file path (logs to console if not set)
-
Database Inspection:
- SQLite databases can be inspected with tools like SQLite Browser
- Use
sqlite3CLI for quick queries
-
Logging:
- Set
LOG_LEVEL=debugfor verbose logging - Check log files for detailed operation information
- Set
-
Common Issues:
- If the application fails to connect to Bluesky, check
AGENT_PASSWORDand network connectivity - Database errors often relate to missing migrations or incorrect paths in environment variables
- If the application fails to connect to Bluesky, check