This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
TruthStake — an educational news credibility platform where users stake credits on whether news articles are credible, Polymarket-style. Features 3-hour market cycles, blind article evaluation (source hidden until resolution), threaded comments, and source reliability visualizations.
- Next.js with SSR and TypeScript (strict mode)
- Zod for runtime schema validation and type inference — use Zod schemas as the single source of truth for all data shapes (API responses, form inputs, env vars). Derive TypeScript types with
z.infer<>rather than writing separate interfaces. - TanStack Router for type-safe routing
- TanStack Form for form state/validation (integrate with Zod resolvers)
- shadcn/ui + Tailwind CSS for UI components
- GSAP for staking/payout animations
- Axios for API calls to backend
- Google OAuth for authentication
- Python FastAPI (async REST API), managed with uv
- Pydantic (v2, strict mode) for all request/response models and settings — enforce
model_config = ConfigDict(strict=True)on all models. UseAnnotatedtypes withField()constraints (e.g.,Field(gt=0)for credit amounts). Never pass raw dicts; always validate through Pydantic models. - OAuth2 / JWT for auth middleware
All Python commands must use uv. Never use raw pip, python, or venv directly.
# Project setup
uv init backend
cd backend
uv add fastapi pydantic[email] uvicorn sqlalchemy asyncpg
# Run dev server
uv run uvicorn app.main:app --reload
# Add a dependency
uv add <package>
# Add a dev dependency
uv add --dev <package>
# Run any Python script
uv run python <script.py>
# Run tests
uv run pytest
# Run linter/formatter
uv run ruff check .
uv run ruff format .- PostgreSQL — primary transactional database (users, credits, votes, rounds, comments)
- ClickHouse — analytical database for source visualization dashboards, synced from PostgreSQL
Core tables: sources, articles, article_back_sources, users, credit_transactions, rounds, votes, comments, comment_upvotes. Full schema in docs/schema-reference.md.
Key domain concepts:
- Round: A 3-hour voting window tied to one article. States:
open→closed→settled - Vote: One per user per round. User stakes credits on
credibleornot_credible - Settlement: Automated — reveals source, determines winner based on
sources.is_credible, distributes credits proportionally to winning pool - Credit transactions: Immutable ledger (
credit_transactions) is the source of truth for balances;users.creditsis a denormalized cache
docs/PRD.md— full product requirementsdocs/schema-reference.md— complete database schema with all columns, types, and relationships