Skip to content

A simple MVP to display the core idea of OnChain Sage. Walk with me.

Notifications You must be signed in to change notification settings

degenspot/onchainsage_mini

Repository files navigation

OnChain Sage — Monorepo

Apps:

  • API (NestJS) — REST + WebSocket
  • Worker (NestJS) — queues, ingestion, scoring, publishers
  • Frontend (Next.js) — optional for now

Prerequisites

  • Node 18+ (or latest LTS)
  • Redis (local redis://localhost:6379 or Upstash URL)

Install

npm install

Environment

Set env files as needed.

API (apps/api/.env):

PORT=3001
FRONTEND_ORIGIN=http://localhost:3000
# Optional: set if you have Redis
# REDIS_URL=redis://localhost:6379

Worker (apps/worker/.env):

# Optional: set if you have Redis (recommended for WS live)
# REDIS_URL=redis://localhost:6379

Note: API uses SQLite by default (no DB setup required). The DB file is apps/api/prisma/dev.db.

Initialize Database (first time)

cd apps/api
npm run db:setup
# runs prisma generate → migrate → seed (adds demo token/signals)

Run Services (local)

In two terminals:

  1. Worker (queues, ingestion, scoring)
cd apps/worker
npm run start:dev
  1. API (REST + WS)
cd apps/api
npm run start:dev

Optional 3) Frontend (if you want UI now)

cd apps/frontend
# ensure NEXT_PUBLIC_API_URL points to API, e.g. http://localhost:3001
npm run dev

Verify

npm i -g wscat
wscat -c ws://localhost:3001
# expect messages: {"type":"signals:live","data":{ tokenId, score, label, at }}

How data flows (local demo)

  • Worker enqueues market and scoring jobs on intervals.
  • Market snapshots are persisted; scoring computes Signal rows and publishes to signals:live via Redis if configured.
  • API serves REST from SQLite and relays WS events (falls back to mock if Redis not set).

Troubleshooting

  • Port already in use: stop previous processes or change PORT in .env.
  • No WS updates: ensure REDIS_URL is set for both API and worker or rely on API mock fallback.
  • See data: run npx prisma studio in apps/api to view tables.

Current Status (2025-09-04)

  • The monorepo contains apps/api (NestJS), apps/worker (NestJS worker), apps/frontend (Next.js), and shared packages/* TS libs.
  • DB schema and migrations (Prisma) were updated; run cd apps/api && npm run db:sync to apply migrations, regenerate client, and seed local DB.
  • For full realtime behaviour set REDIS_URL in both API and Worker environments.

Direction: prioritize developer DX (db sync script added), add CI checks to run db:sync before tests, and consider migrating from SQLite to Postgres for production.

About

A simple MVP to display the core idea of OnChain Sage. Walk with me.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published