FolkTheory Documentation

Technical documentation for the FolkTheory platform

View on GitHub

FolkTheory - Startup Ecosystem Platform

From Idea to Impact – a unified platform where founders find co‑founders, validate ideas, build startups, and connect with investors. FolkTheory blends community, collaboration, and capital into one focused workflow (no context‑switching between 5 fragmented tools).

Tagline: “From Idea to Impact – Build, Collaborate, Fund”

📚 Table of Contents

  1. Platform Overview
  2. Technical Architecture
  3. Platform Features
  4. Security Implementation
  5. Work in Progress
  6. Services & Integrations
  7. Development Setup
  8. Environment Variables
  9. Performance Optimization
  10. Platform Metrics
  11. Architecture Diagram
  12. Messaging Data Flow
  13. Contributing
  14. License

Deployed on Vercel Built with Next.js MongoDB Redis TypeScript

🎯 Platform Overview

FolkTheory is a comprehensive startup ecosystem platform that enables aspiring entrepreneurs to connect, collaborate, and secure funding. The platform combines the best aspects of:

🏗️ Technical Architecture

Core Technology Stack

Component Technology Version Purpose
Frontend Next.js 15.5.4 React-based web framework with SSR & Turbopack
UI Framework React 19.2.0 Component-based user interface
Language TypeScript 5+ Type-safe development with typed routes
Styling Tailwind CSS 3.4.17 Utility-first CSS framework
UI Components Radix UI Latest Accessible component library
Authentication NextAuth.js 4.24.11 Secure authentication system
Database MongoDB 7.0.20 Document-based database with real-time monitoring
ODM Mongoose 8.16.4 MongoDB object modeling
Cache Redis 7.2.5 High-performance caching with auto-pipelining
Redis Client IORedis 5.6.1 Node.js Redis client with enhanced TLS support
Validation Zod 3.24.1 TypeScript-first schema validation
Testing Vitest 2.1.9 Fast unit test framework
Logging Custom Logger - Structured logging with multiple levels
Hosting Vercel - Deployment and hosting platform
File Storage AWS S3 (R2) - Cloud file storage
Analytics Vercel Analytics 1.5.0 Performance monitoring
Theme System next-themes Latest Light/Dark/System theme switching
WebRTC Cloudflare Calls Latest Real-time voice and video calling
Video Infrastructure Cloudflare SFU - Global Selective Forwarding Unit for scalable media

Development Tools

Recent Updates (November 2025)

Code Quality & Refactoring:

Previous Updates (October 2025):

Framework Upgrades:

Code Quality Improvements:

🚀 Platform Features

✅ Implemented Core Features

1. User Authentication & Management

Signup Password Requirements:
✅ Minimum 6 characters
✅ At least 1 capital letter (A-Z)
✅ At least 1 special character (@#$%^&*!)
✅ At least 1 number (0-9)

2. Co-founder & Team Matching

3. Startup & Project Management

4. Investor Portal

5. Community Features

6. Dashboard & Analytics

7. Search & Discovery

8. Messaging SystemENTERPRISE-GRADE REDIS 7.2.5 POWERED

9. Admin Dashboard 🎛️ ENHANCED WITH REDIS 7.2.5

10. File Management

11. Modern UI/UX with Theme System 🎨

12. Real-Time Voice & Video Calling 📞 CLOUDFLARE CALLS POWERED

🔒 Security Implementation

Current Strengths

⚠️ Security Vulnerabilities

Priority Vulnerability Location Risk Level Impact
🔴 Critical Hardcoded DB Credentials lib/mongodb.ts High Full database access
🔴 Critical Hardcoded Redis Credentials lib/redis-client.ts High Cache/session access
🔴 Critical Weak/Hardcoded NEXTAUTH_SECRET lib/auth.ts High Session compromise
FIXED No Rate Limiting lib/rate-limit.ts Low Multiple presets implemented
FIXED Limited Input Sanitization lib/validation.ts Low Zod + sanitization utils
🟡 Medium Missing CSRF Protection Forms Medium Consider CSRF tokens
FIXED Exposed Error Details lib/logger.ts Low Structured logging

🚧 Work in Progress (WIP) Elements

Phase 2 Completed (Recent Updates)

Phase 3 Development (Next)

Phase 4 Planned Features

Missing Core Components

📊 Database & Caching Architecture

MongoDB Primary Database

The main data storage using MongoDB for document-based persistence with optimized indexing:

Redis Caching Layer ⚡ ENTERPRISE-GRADE

High-performance caching and real-time features using Redis ObjectRocket HA:

Performance Achievements:

Operation Before (Database) After (Redis Cache) Improvement
Message Retrieval ~300ms ~12ms 25x faster
Conversation Loading ~200ms ~8ms 25x faster
Rate Limiting ~50ms ~2ms 25x faster
Real-time Updates Polling (1000ms) Pub/Sub (~30ms) 33x faster
Search Results No caching Instant repeats Infinite improvement

Redis Features Implemented:

User Model Features

interface IUser {
  email: string              // Unique, validated email
  password: string          // bcrypt hashed (min 6 chars, 1 capital, 1 special @#$%^&*!, 1 number)
  firstName: string         // User's first name
  lastName: string          // User's last name
  userType: enum            // founder, investor, cofounder, mentor, advisor
  bio?: string              // Profile description
  location?: string         // Geographic location
  linkedinUrl?: string      // LinkedIn profile
  skills: string[]          // Technical and business skills
  experience: enum          // 0-1, 1-3, 3-5, 5-7, 7-10, 10+ years
  availability: enum        // full-time, part-time, consulting, not-available
  industries: string[]      // Focus industries
  startupId?: ObjectId      // Reference to associated startup
  isOnline?: boolean        // Online status
  lastSeen?: Date          // Last activity timestamp
}

Database & Cache Optimizations

MongoDB Optimizations:

Redis Performance Enhancements:

🌟 Platform Strengths

Technical Excellence

User Experience

Business Logic

Development Experience

📋 Recommendations

Recently Completed Improvements

  1. Message Cache Fix: ✅ COMPLETED - Fixed cache invalidation with specific key targeting
  2. Performance Optimization: ✅ COMPLETED - 25x faster messaging with Redis
  3. Log Cleanup: ✅ COMPLETED - Eliminated development log spam
  4. Theme System: ✅ COMPLETED - Modern Light/Dark theme toggle
  5. Mobile Navigation: ✅ COMPLETED - Responsive hamburger menu
  6. Header Optimization: ✅ COMPLETED - Black-translucent navigation bar

🔴 Immediate Security Fixes

  1. Environment Variables: Move all MongoDB/Redis credentials to secure vaults
  2. Input Sanitization: Add comprehensive XSS protection
  3. Secret Rotation: Generate strong NEXTAUTH_SECRET
  4. Error Handling: Remove sensitive information from remaining logs
  5. CSRF Protection: Implement cross-site request forgery protection

🟡 Short-term Improvements

  1. Testing Suite: Implement Jest/Cypress testing
  2. Error Monitoring: Add Sentry or similar service
  3. CI/CD Pipeline: Automated testing and deployment
  4. API Documentation: OpenAPI/Swagger documentation
  5. Performance Monitoring: Extend Redis cache analytics

🟢 Long-term Enhancements

  1. Microservices: Break into smaller, focused services
  2. CDN Implementation: Global content delivery
  3. WebSocket Integration: True real-time connections beyond pub/sub
  4. Analytics Platform: Custom analytics dashboard
  5. Machine Learning: AI-powered matching algorithms
  6. Mobile App: Native iOS/Android applications

🛠️ Services & Integrations

Current Integrations

Service Purpose Status Configuration
ObjectRocket MongoDB Primary database ✅ Active 50GB,iad2-c19 cluster
ObjectRocket Redis HA Caching & real-time messaging ✅ Active 20GB, SSL/TLS, Redis 3.2.0
Cloudflare Calls WebRTC voice/video ✅ Active Global SFU, 330+ edges
Vercel Hosting Application deployment ✅ Active Auto-deploy from Git
AWS S3 (R2) File storage ✅ Active SDK v3.848.0
NextAuth.js Authentication ✅ Active JWT strategy
Vercel Analytics Performance tracking ✅ Active Real-time metrics
next-themes Theme system ✅ Active Light/Dark/System modes

Planned Integrations

Service Purpose Priority Timeline
Stripe Payment processing High Phase 3
SendGrid/Mailchimp Email services High Phase 3
Zoom API Video meetings (backup) Low Phase 4
LinkedIn OAuth Social login Medium Phase 3
Sentry Error monitoring Medium Phase 3
WebSocket Server Extended real-time features Low Phase 4

Note: Cloudflare Calls already provides enterprise-grade video calling, so Zoom integration is now low priority.

🚀 Development Setup

Quick Start

git clone https://github.com/Imperialorg/folktheory.git
cd folktheory
pnpm install
cp .env.example .env.local   # create if missing; see vars below
pnpm dev

Visit: http://localhost:3000

Prerequisites

Installation

# Clone repository
git clone https://github.com/Imperialorg/folktheory.git
cd folktheory

# Install dependencies
pnpm install

# Configure environment
cp .env.example .env.local
# Edit .env.local with your configurations

# Set up database indexes (optional but recommended)
npx tsx scripts/setup-messaging-indexes.ts

# Run tests (optional)
pnpm test

# Run type check (optional)
npx tsc --noEmit

Available Scripts

# Development
pnpm dev              # Start development server with Turbopack
pnpm build            # Build for production
pnpm build:turbo      # Build with Turbopack (2-5x faster)
pnpm start            # Start production server
pnpm lint             # Run ESLint
pnpm test             # Run tests with Vitest
pnpm test:ui          # Run tests with UI
pnpm test:coverage    # Generate coverage report

Test Redis connection

npx tsx scripts/test-redis-connection.ts

Run development server

pnpm dev


### Environment Variables

See `.env.example` for the authoritative list. Summary:

| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| NEXTAUTH_URL | Yes (prod) | <http://localhost:3000> | Public base URL for auth callbacks |
| NEXTAUTH_SECRET | Yes | — | 32+ byte secret for JWT/session encryption |
| MONGODB_URI | Yes | — | MongoDB connection string |
| REDIS_HOST | Yes (if Redis) | — | Redis endpoint hostname |
| REDIS_PORT | No | 6380 | Redis port (TLS) |
| REDIS_PASSWORD | Yes (if Redis) | — | Redis auth password |
| REDIS_TLS | No | true | Enable TLS connection |
| REDIS_CA_PATH | No | ./app/rackspace-ca-2021.pem | CA cert for TLS |
| R2_ENDPOINT | Yes (if R2) | — | Cloudflare R2 S3-compatible endpoint |
| R2_ACCESS_KEY_ID | Yes (if R2) | — | R2 access key |
| R2_SECRET_ACCESS_KEY | Yes (if R2) | — | R2 secret key |
| R2_BUCKET_NAME | Yes (if R2) | folktheory | Asset bucket name |
| R2_PUBLIC_URL | No | <https://assets.folktheory.dev> | Public CDN/base URL |
| AWS_ACCESS_KEY_ID | Conditional | — | AWS key if using AWS services directly |
| AWS_SECRET_ACCESS_KEY | Conditional | — | AWS secret if using AWS services |
| CALLS_APP_ID | Yes (if video) | — | Cloudflare Calls application ID |
| CALLS_APP_SECRET | Yes (if video) | — | Cloudflare Calls API secret |
| ENABLE_DEMO_ENDPOINTS | No | false | Expose /api/demo/* endpoints (disabled in prod) |
| ENABLE_DEBUG_ENDPOINTS | No | false | Expose /api/debug* endpoints (disabled in prod) |

> Tip: copy `.env.example` to `.env.local` and fill in required secrets before running `pnpm dev`. Demo/debug endpoint flags are off by default; only enable temporarily when needed.

### Performance Optimization

#### Next.js 15.5 Performance Features

- **Turbopack Production Builds**: Available with `pnpm build --turbopack` (2-5x faster builds)
- **TypeScript Typed Routes**: Compile-time route validation prevents broken links
- **Node.js Middleware**: Full Node.js API access for enhanced middleware capabilities
- **Auto-Generated Types**: PageProps, LayoutProps, and RouteContext automatically typed

#### Application Performance

**Redis 7.2.5 Optimizations:**

```bash
# Test Redis 7.2.5 performance improvements
npx tsx scripts/test-redis-optimizations.js

# Test admin cache with Redis 7.2.5 features
npx tsx scripts/test-admin-cache.js

# Monitor Redis health and memory
npx tsx scripts/test-redis-connection.ts

Performance Results:

Monitoring & Observability:

Code Quality:

# Run tests
pnpm test

# Run tests with UI
pnpm test:ui

# Generate coverage report
pnpm test:coverage

# Type check
npx tsc --noEmit

# Lint code
pnpm lint

⚠️ Security Note: Credentials are currently hard-coded in lib/mongodb.ts and lib/redis-client.ts for development convenience. Before any production deployment:

  1. Move all secrets into environment variables (or a secret manager).
  2. Rotate the exposed credentials immediately.
  3. Add a .env.example file enumerating required keys (without values).
  4. Add automated secret scanning (GitHub Advanced Security / gitleaks) in CI.
  5. Strengthen NEXTAUTH_SECRET (min 32+ random bytes).

📊 Platform Metrics & Goals

Current Status

Recent Performance Achievements

Success Metrics

🚀 Deployment

Production Deployment

Platform: Vercel (Auto-deploy from Git)
Project: folktheory

Deployment Configuration

Features Available in Production

Redis 7.2.5 Optimizations - Auto-pipelining and enhanced TLS
Real-time Admin Dashboard - Redis memory monitoring
MongoDB 7.0.20 Statistics - Database health monitoring
Enterprise Messaging - Redis pub/sub real-time updates
Cloudflare Calls - WebRTC voice/video (330+ edge locations)
Performance Optimized UI - Smooth operation without GPU strain
Theme System - Light/Dark/System mode switching

Local Development

# Start development server
pnpm dev

# Access locally
http://localhost:3000

🤝 Contributing

Development Workflow

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

Code Standards

Performance Testing

# Test Redis messaging performance
npx tsx scripts/test-messaging-performance.ts

# Debug message cache
npx tsx scripts/debug-message-cache.js

# Test Redis connection
npx tsx scripts/test-redis-connection.ts

🧱 High-Level Architecture

┌──────────────────────────┐
│        Next.js App       │  (App Router + React 19)
│  UI / API Routes / SSR   │
└────────────┬─────────────┘
         │
  Auth (NextAuth.js) ─────────► JWT sessions / middleware protection
         │
  MongoDB 7.0.20 ─────────────► Primary persistence (Users, Startups, Messages, Notifications)
         │
  Redis 7.2.5 ────────────────► Caching, pub/sub (presence, typing, messages), rate limits
         │                        Auto-pipelining + Enhanced TLS
  Cloudflare Calls ───────────► WebRTC voice/video (Global SFU, 330+ edges)
         │
  Cloudflare R2 (S3 API) ─────► File & asset storage (decks, docs, uploads)
         │
  WSO2 Choreo Platform ───────► Production deployment + API management

Messaging Data Flow

  1. API route receives message
  2. Persist to MongoDB 7.0.20
  3. Write/update Redis 7.2.5 cache + publish channel (with auto-pipelining)
  4. Subscribers receive event -> UI updates
  5. Subsequent reads served from Redis (fallback to MongoDB on miss)

Project Structure

├── app/                    # Next.js App Router
│   ├── admin/             # Admin dashboard with Redis/MongoDB monitoring
│   ├── api/               # API routes including cache-health endpoints
│   └── ...                # Other app pages
├── components/            # React components
│   ├── redis-monitor.tsx  # Redis 7.2.5 memory monitoring
│   ├── mongo-monitor.tsx  # MongoDB 7.0.20 statistics
│   └── ...                # Other UI components
├── lib/                   # Core libraries
│   ├── admin-cache.ts     # Redis 7.2.5 admin caching system
│   ├── redis-client.ts    # Enhanced Redis client with auto-pipelining
│   ├── mongodb.ts         # MongoDB 7.0.20 connection
│   └── ...                # Other utilities
├── docs/                  # Documentation
│   ├── REDIS_725_OPTIMIZATIONS.md
│   ├── REDIS_725_ADMIN_OPTIMIZATIONS.md
│   └── ...                # Other documentation
└── scripts/               # Development and testing scripts
    ├── test-redis-optimizations.js
    ├── test-admin-cache.js
    └── ...                # Other scripts

Last Updated: 4th of November 2025
Platform Version: 0.2.1
Next.js Version: 15.2.4
MongoDB Version: 7.0.20
Redis Version: 7.2.5 (with auto-pipelining optimizations)
Major Updates: Code quality refactoring, CallOverlay component, custom hooks, WebRTC documentation, 100% SonarQube compliance

License

MIT — see LICENSE (add one if missing).