Skip to main content

Architecture

Answer Overflow is built as a TypeScript monorepo using Bun and Turbo for orchestration. The project follows a clean separation between applications and shared packages.

Monorepo structure

answer-overflow/
├── apps/
│   ├── discord-bot/    # Discord bot application
│   ├── main-site/      # Next.js web application
│   ├── docs/           # Documentation site
│   └── bot-e2e/        # End-to-end bot tests

├── packages/
│   ├── database/       # Convex backend + auth
│   ├── agent/          # AI agent system
│   ├── ai/             # AI features and integrations
│   ├── ui/             # Shared React components
│   ├── discord-api/    # Discord API wrappers
│   ├── github-api/     # GitHub API integrations
│   ├── observability/  # Monitoring and logging
│   ├── reacord/        # React for Discord messages
│   ├── confect/        # Convex utilities
│   └── ...

Applications

Discord bot

The Discord bot (apps/discord-bot) is the core service that:
  • Monitors Discord servers for new threads and messages
  • Processes thread data for indexing
  • Responds to slash commands
  • Manages channel settings and permissions
Key technologies:
  • discord.js for Discord API integration
  • Effect for functional programming patterns
  • Bun runtime for fast execution
Entry point example:
apps/discord-bot/index.ts
import { S3StorageLayer } from "@packages/database/storage";
import { program } from "./src/bot";
import { createAppLayer, runMain } from "./src/core/runtime";

const AppLayer = createAppLayer(S3StorageLayer);

runMain(program, AppLayer);

Main site

The web application (apps/main-site) provides:
  • Public-facing thread pages for SEO
  • Server and channel management dashboard
  • User authentication and settings
  • MCP (Model Context Protocol) server for AI agents
Key technologies:
  • Next.js 16 with App Router
  • Better Auth for authentication
  • Convex for real-time data
  • Tailwind CSS for styling

Core packages

Database package

The @packages/database package contains:
  • Convex schema definitions
  • Database queries and mutations
  • Authentication configuration
  • Storage layer (S3) integration
Schema example:
packages/database/convex/schema.ts
const ServerPreferencesSchema = Schema.Struct({
  serverId: Schema.BigIntFromSelf,
  stripeCustomerId: Schema.optional(Schema.String),
  stripeSubscriptionId: Schema.optional(Schema.String),
  plan: PlanSchema,
  readTheRulesConsentEnabled: Schema.optional(Schema.Boolean),
  considerAllMessagesPublicEnabled: Schema.optional(Schema.Boolean),
  anonymizeMessagesEnabled: Schema.optional(Schema.Boolean),
  customDomain: Schema.optional(Schema.String),
  // ...
});
Scripts:
  • bun dev - Start Convex in development mode
  • bun deploy - Deploy to production
  • bun codegen - Generate type definitions

Agent package

The @packages/agent package provides:
  • AI agent framework built on Convex
  • Tool definitions for AI interactions
  • React hooks for agent state management
  • HTTP endpoints for agent communication

AI package

The @packages/ai package includes:
  • AI SDK integrations (OpenAI, Anthropic)
  • Prompt templates and utilities
  • Content generation helpers

Data flow

1

Discord event

A message or thread is created in Discord
2

Bot processing

The Discord bot receives the event and processes it using Effect
3

Database storage

Thread and message data is stored in Convex
4

Web indexing

Next.js generates static pages for public threads
5

Search discovery

Search engines crawl and index the pages

Build orchestration

The project uses Turbo for monorepo task orchestration:
turbo.json
{
  "tasks": {
    "build": {
      "outputs": ["dist/**", ".next/**"],
      "dependsOn": ["^build"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    },
    "typecheck": {
      "cache": true
    }
  }
}

Environment variables

Key environment variables used across the monorepo:
  • DISCORD_TOKEN - Discord bot token
  • DISCORD_CLIENT_ID / DISCORD_CLIENT_SECRET - OAuth credentials
  • CONVEX_DEPLOYMENT - Convex deployment URL
  • NEXT_PUBLIC_CONVEX_URL - Public Convex endpoint
  • BETTER_AUTH_SECRET - Authentication secret
  • STRIPE_SECRET_KEY - Payment processing
Never commit .env files to version control. Use .env.example as a template.

Deployment

  • Discord bot: Deployed as a long-running service
  • Main site: Deployed on Vercel with edge functions
  • Database: Convex handles serverless deployment automatically
The monorepo structure allows packages to be shared between apps while maintaining clear boundaries.