A comprehensive monorepo for building Decentralized Knowledge Graph (DKG) applications with a modern tech stack including Expo, Drizzle ORM, SQLite, and MCP (Model Context Protocol) integration.
This project consists of:
- Agent App: A full-stack DKG agent with Expo UI and MCP server
- Plugin System: Modular plugins for extending functionality
- Database Layer: SQLite with Drizzle ORM for data persistence
- Authentication: OAuth-based authentication system
- API Server: Express-based API with Swagger documentation
- Node.js >= 22
- npm package manager
- Turbo CLI (install globally)
npm i -g turbonpm install
npm run buildBefore running the project setup, you'll need to configure the following environment variables. The setup script will prompt you for these values, but you can also prepare them in advance:
DATABASE_URL: Database name for SQLite (e.g.,dkg.db)OPENAI_API_KEY: Your OpenAI API key for LLM integrationDKG_PUBLISH_WALLET: Private key for publishing to the DKG blockchain. This is used for:- Paying native token fees for blockchain transactions
- Paying TRAC tokens for publishing to the DKG
- Securing your node identity (keep your private keys secure!)
DKG_BLOCKCHAIN: Blockchain network identifier. Options:- Mainnet:
otp:2043 - Testnet:
otp:20430 - Default:
hardhat1:31337(local development)
- Mainnet:
DKG_OTNODE_URL: OT-node server URL. Options:- Testnet (safe testing with mock tokens):
https://v6-pegasus-node-02.origin-trail.network:8900 - Mainnet (production DKG interactions):
https://positron.origin-trail.network - Local development:
http://localhost:8900(default)
- Testnet (safe testing with mock tokens):
PORT: Server port (default:9200)EXPO_PUBLIC_APP_URL: Public app URL (default:http://localhost:9200)EXPO_PUBLIC_MCP_URL: MCP server URL (default:http://localhost:9200)
cd apps/agent
npm run build:scripts
npm run script:setupThe setup script will:
- Prompt for required environment variables
- Create
.envand.env.development.localfiles - Set up the SQLite database with migrations
- Create an admin user (username:
admin, password:admin123)
npm run devThat's it! Your DKG agent is now running with:
- Frontend: http://localhost:8081 (Expo app)
- Backend: http://localhost:9200 (MCP server + API)
- Database: SQLite with Drizzle Studio available
The application uses SQLite with the following tables:
users: User authentication and authorizationoauth_clients: OAuth client managementoauth_codes: OAuth authorization codesoauth_tokens: OAuth access tokens
# Generate new migrations
npm run build:migrations
# View database in Drizzle Studio
npm run drizzle:studio
# Create new user/token
npm run script:createUser
npm run script:createTokenAccess your database through the web interface:
npm run drizzle:studioThen open https://local.drizzle.studio
turbo gen plugin
# Name: plugin-<your-name>Edit packages/plugin-<your-name>/src/index.ts:
import { defineDkgPlugin } from "@dkg/plugins";
export default defineDkgPlugin((ctx, mcp, api) => {
// Register MCP tools/resources
mcp.tools.register("myTool", {
// Tool implementation
});
// Register API routes
api.get("/my-endpoint", (req, res) => {
// Route implementation
});
});cd apps/agent
npm install --save @dkg/plugin-<your-name>Then register in src/index.ts:
import myPlugin from "@dkg/plugin-<your-name>";
// In createPluginServer function
plugins: [myPlugin];Plugins receive three injected arguments:
ctx: DKG environment context (logger, DKG client, etc.)mcp: MCP Server instance for registering tools/resourcesapi: Express server for API routes
npm run dev # Start both app and server
npm run dev:app # Start Expo app only
npm run dev:server # Start MCP server onlynpm run build # Build all packages
npm run build:server # Build server code
npm run build:web # Build web app
npm run build:scripts # Build utility scripts
npm run build:migrations # Generate database migrationsThe project includes three testing layers for comprehensive coverage:
# API Tests - Individual plugin/endpoint testing
npm run test:api # Run all plugin API tests
# Integration Tests - Cross-plugin interaction testing
npm run test:integration # Run integration tests
# End-to-end user interface testing
npm run test:e2e # Run Playwright tests
# Run all tests
npm test # Run API, integration, and E2E testsnpm run build # Build all packages
npm run build:web # Build web app
npm run build:server # Build servercd apps/agent
node dist/index.js# Add to specific package
cd packages/your-package
npm install --save package-name
# Add to app
cd apps/agent
npm install --save package-name# Install local package in another package
npm install --save @dkg/your-package-name# Clean and rebuild
rm -rf node_modules package-lock.json
npm install
npm run build# Regenerate migrations
npm run build:migrations
# Reset database
rm *.db
npm run script:setup# Check types
npm run check-types
# Reinstall dependencies
npm install
npm run build- Check the Turborepo documentation
- Review existing plugins in
packages/plugin-* - Check the agent app README in
apps/agent/README.md
- Follow the existing code structure
- Use
turbo genfor new packages/apps - Run
turbo format check-types lint buildbefore committing - Follow the established patterns in existing plugins
This project is part of the DKG ecosystem. See individual package licenses for details.