System Architecture
The Community Engine is designed for high performance, scale, and extreme flexibility. It leverages the Server Components architecture from Next.js, along with a robust background processing pipeline.
Core Stack
- Framework: Next.js App Router (React Server Components)
- Database: PostgreSQL (interacted via Prisma ORM)
- Auth: Better-Auth
- Caching & Pipelines: Redis (ioredis)
- Styling: Tailwind CSS & Radix UI
Database Schema (Prisma)
The schema is built around highly relational concepts standard to community platforms. Key models include:
User
Manages identity, credentials (via Better-Auth), profile details, reputation scores, and site roles.
Question & Answer
Supports a typical Q&A format. Relationships include specific authors, tags, and upvote/downvote scores.
Vote
Tracks individual user votes (value: +1 or -1) polymorphically on Questions or Answers to calculate aggregate voteScore.
Notification
Stores system alerts for users (e.g., “@username mentioned you”, “Someone answered your question”).
Caching Strategy
We utilize robust caching mechanisms to ensure pages remain snappy regardless of concurrent load:
- Next.js Full Route Cache: Static pages and basic routing are cached at the edge.
- React Query: We use
@tanstack/react-queryto handle client-side pagination, fetching, and re-validation (like infinite-scrolling answers). - Redis Caching: Highly complex queries (like trending tags or popular posts) are cached to Redis.
Notification Pipeline
Notifications require background execution so they don’t block the main API response thread when users post content.
- Event Dispatch: When an action occurs (e.g., an answer is posted).
- Job Queue (Redis): We push a job payload out to Redis using
ioredis. - Worker Processing: Background workers pop the jobs, resolve the recipients (author, mentioned users, followers), and create records in the database.
- Real-time Indication: Users ping a lightweight GET polling endpoint to fetch updated bell notifications.
The Plugin Bus (Planned)
We are actively developing a highly extensible Plugin Bus. The system uses lightweight event emitters bound to the Next.js lifecycle. Developers will be able to inject server-side middleware for:
- Auto-moderation (e.g., AI checking questions for spam)
- Webhooks to trigger Slack/Discord integrations
- Custom achievement granting architectures