This is a personal research project to reverse-engineer and reimplement the core recommendation algorithms used by X (formerly Twitter). The goal is to build a tunable, transparent, and interactive version of the ranking pipeline to understand how social media feeds are constructed.
The project consists of three main components:
- Backend (FastAPI): Handles API requests, user management, and the core ranking algorithm.
- Frontend (Next.js): A React-based web interface to view the feed and tune algorithm parameters.
- Simulation: A Python script using LLMs (Gemini/OpenAI) to generate synthetic users and tweets to populate the system.
- Python 3.11+
- Node.js 18+
- OpenAI or Google Gemini API Key
- Navigate to
backend/:cd backend - Create a virtual environment and install dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt - Run the server:
fastapi dev main.py
- Navigate to
frontend/:cd frontend - Install dependencies:
npm install
- Run the development server:
npm run dev
- Create a
.envfile in the root directory and add your API key:OPENAI_API_KEY=your_key_here # Alternative provider configuration GEMINI_API_KEY=your_key_here
- Run the backend script, you will need to have activated the virtual environment.
source backend/venv/bin/activate python -m uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000 - Run the frontend script
cd frontend npm run dev - Run the simulation script
python3 simulation/run_sim.py