A Next.js web application that analyzes Reddit users’ comments and posts to surface ideological contradictions, provides contextual explanations, and ranks users on a public leaderboard. Built with Next, TypeScript, Tailwind CSS, Prisma, and integrates with the Reddit OAuth API and OpenRouter’s LLM endpoints for AI-driven summarization and contradiction detection.
- Fetch and cache Reddit user comments & posts (up to 1 year back) via OAuth
- Hierarchical AI-powered summarization (batch → meta-summary)
- AI-driven contradiction detection with confidence scoring & categories
- Local fallback heuristics when budget/API unavailable
- Leaderboard, user profiles, and per-user stats (karma, account age, activity)
- Streaming analysis for progressive UI updates
- Token-budget management to control API usage & cost
- Dark mode, responsive UI with Tailwind CSS & Framer Motion animations
-
Frontend:
- Next.js App Router (
src/app/) - React components (
src/components/) - Tailwind CSS for styling
- Framer Motion for animations
- Next.js App Router (
-
Backend (Server-Side):
- Next.js API routes (
src/app/api/) redditApiservice: paginated OAuth requests to Reddit’s APImultiModelPipelineservice: AI summarization & contradiction detection (OpenRouter)analysisServiceclient: calls/api/analyze, wraps results for UItokenBudgetservice: tracks and limits LLM token costscacheService: caches analysis results to speed up repeat requests
- Next.js API routes (
-
Database:
- Prisma ORM (
prisma/schema.prisma) - Migrations stored in
prisma/migrations/ - Stores users, analysis reports, and cached data (optional)
- Prisma ORM (
.
├── .next/ # Next.js build artifacts
├── prisma/ # Prisma schema & migrations
│ ├── migrations/
│ └── schema.prisma
├── public/ # Static assets
│ └── thought-police-card.png
├── src/
│ ├── app/
│ │ ├── api/ # Next.js API routes
│ │ │ ├── analyze/route.ts
│ │ │ ├── reddit/… # Reddit proxy routes
│ │ ├── leaderboard/ # Leaderboard page
│ │ ├── login/ # Login page
│ │ ├── profile/ # Profile page
│ │ ├── stats/ # Stats page
│ │ ├── layout.tsx # Root layout
│ │ └── page.tsx # Home page
│ ├── components/ # Reusable React components
│ │ ├── AnalysisResults.tsx
│ │ ├── Leaderboard.tsx
│ │ ├── Navigation.tsx
│ │ └── …
│ ├── lib/
│ │ ├── services/
│ │ │ ├── redditApi.ts
│ │ │ ├── multiModelPipeline.ts
│ │ │ ├── analysisService.ts
│ │ │ ├── tokenBudget.ts
│ │ │ └── cacheService.ts
│ │ ├── contexts/ # React contexts (Auth, Theme)
│ │ └── types/ # Shared TypeScript types
│ └── globals.css # Global styles
├── next.config.js
├── tailwind.config.js
├── tsconfig.json
├── package.json
└── README.md
- Node.js v18+
- npm or Yarn
- (Optional) A PostgreSQL or SQLite database for Prisma
Create a .env.local in the project root with:
# .env.local
REDDIT_CLIENT_ID=<your_reddit_client_id>
REDDIT_CLIENT_SECRET=<your_reddit_client_secret>
OPENROUTER_API_KEY=<your_openrouter_api_key>
DATABASE_URL="postgresql://user:pass@localhost:5432/thought_police" # or SQLite
NEXT_PUBLIC_APP_URL=http://localhost:3000git clone https://github.com/yourusername/thought-police.git
cd thought-police
npm installnpx prisma migrate dev # Create database schema
npx prisma generate # Generate Prisma clientnpm run devVisit http://localhost:3000 in your browser.
npm run build
npm start- Login (if auth is enabled)
- Enter a Reddit username on the home page
- Submit to trigger analysis
- View:
- Executive summary of contradictions
- Detailed contradiction cards (earlier vs. later statements, dates, subreddits, context)
- Overall stats, confidence scores, and quality indicators
- Leaderboard to compare top users by number of contradictions
-
redditApi.ts
- OAuth 2.0 token fetching
- Paginated streaming of comments & posts with retry logic
-
multiModelPipeline.ts
- Deduplication & clustering of content
- Dynamic batching for summarization (7k+ token batches)
- Hierarchical meta-summarization for global context
- Contradiction detection with AI prompts
- Local fallback heuristics
-
tokenBudget.ts
- Tracks input/output token usage
- Enforces budget thresholds & warnings
- Persists usage in
localStorage
-
analysisService.ts
- Client-side wrapper for
/api/analyze - Streaming analysis for progress UI
- Weighted confidence scoring
- Client-side wrapper for
-
cacheService.ts
- Caches analysis reports by content hash
- Reduces duplicate API usage
- Fork the repository
- Create a feature branch:
git checkout -b feat/my-feature - Commit changes:
git commit -m "feat: add new feature" - Push branch:
git push origin feat/my-feature - Open a Pull Request
Please run npm test (if tests exist) and follow code style conventions.
This project is licensed under the MIT License. See LICENSE for details.