|
| 1 | +# CodeClash React Viewer |
| 2 | + |
| 3 | +A modern React-based trajectory viewer for CodeClash game sessions. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Clean React + TypeScript frontend** with Vite for fast development |
| 8 | +- **RESTful Flask backend** with clear API endpoints |
| 9 | +- **Game Picker** - Browse and search all available games |
| 10 | +- **Game Viewer** - View game overview, rounds, and results |
| 11 | +- **Trajectory Viewer** - Inspect agent messages, diffs, and submissions |
| 12 | +- **Lazy Loading** - Trajectories and diffs load on demand for better performance |
| 13 | + |
| 14 | +## Setup |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +- Python 3.10+ |
| 19 | +- Node.js 18+ (for frontend development) |
| 20 | + |
| 21 | +### Installation |
| 22 | + |
| 23 | +1. Install Python dependencies (from project root): |
| 24 | +```bash |
| 25 | +pip install flask flask-cors |
| 26 | +``` |
| 27 | + |
| 28 | +2. Install frontend dependencies: |
| 29 | +```bash |
| 30 | +cd viewer_react/frontend |
| 31 | +npm install |
| 32 | +``` |
| 33 | + |
| 34 | +### Development |
| 35 | + |
| 36 | +For development with hot reload: |
| 37 | + |
| 38 | +1. Start the backend server (from project root): |
| 39 | +```bash |
| 40 | +python run_viewer_react.py |
| 41 | +``` |
| 42 | + |
| 43 | +2. In a separate terminal, start the frontend dev server: |
| 44 | +```bash |
| 45 | +cd viewer_react/frontend |
| 46 | +npm run dev |
| 47 | +``` |
| 48 | + |
| 49 | +The frontend will be available at http://localhost:3000 with hot reload. |
| 50 | +The backend API runs at http://localhost:5002. |
| 51 | + |
| 52 | +### Production |
| 53 | + |
| 54 | +Build the frontend and serve it from Flask: |
| 55 | + |
| 56 | +```bash |
| 57 | +cd viewer_react/frontend |
| 58 | +npm run build |
| 59 | +cd ../.. |
| 60 | +python run_viewer_react.py |
| 61 | +``` |
| 62 | + |
| 63 | +The app will be available at http://localhost:5002. |
| 64 | + |
| 65 | +## Usage |
| 66 | + |
| 67 | +```bash |
| 68 | +# Use default logs directory (./logs) |
| 69 | +python run_viewer_react.py |
| 70 | + |
| 71 | +# Use custom logs directory |
| 72 | +python run_viewer_react.py -d /path/to/logs |
| 73 | + |
| 74 | +# Use custom port |
| 75 | +python run_viewer_react.py --port 8000 |
| 76 | +``` |
| 77 | + |
| 78 | +## Architecture |
| 79 | + |
| 80 | +``` |
| 81 | +viewer_react/ |
| 82 | +├── backend.py # Flask REST API |
| 83 | +├── frontend/ # React + TypeScript app |
| 84 | +│ ├── src/ |
| 85 | +│ │ ├── components/ # React components |
| 86 | +│ │ ├── types/ # TypeScript types |
| 87 | +│ │ ├── utils/ # API client |
| 88 | +│ │ ├── App.tsx # Main app component |
| 89 | +│ │ └── main.tsx # Entry point |
| 90 | +│ ├── package.json |
| 91 | +│ └── vite.config.ts |
| 92 | +└── README.md |
| 93 | +``` |
| 94 | + |
| 95 | +## API Endpoints |
| 96 | + |
| 97 | +- `GET /api/folders` - List all game folders |
| 98 | +- `GET /api/game/<path>` - Get game metadata and rounds |
| 99 | +- `GET /api/trajectory/<path>/<player>/<round>` - Get trajectory data |
| 100 | +- `GET /api/analysis/line-counts/<path>` - Get line count analysis |
| 101 | +- `GET /api/analysis/sim-wins/<path>` - Get simulation wins per round |
| 102 | +- `POST /api/delete-folder` - Delete a game folder |
| 103 | + |
| 104 | +## Comparison with Original Viewer |
| 105 | + |
| 106 | +### Improvements |
| 107 | + |
| 108 | +- **Modern Stack**: React + TypeScript instead of Jinja templates |
| 109 | +- **Better Performance**: Lazy loading, component-based architecture |
| 110 | +- **Cleaner Code**: Separation of concerns between backend and frontend |
| 111 | +- **Type Safety**: Full TypeScript support |
| 112 | +- **Better UX**: Smooth interactions, clear visual hierarchy |
| 113 | + |
| 114 | +### Simplified Features |
| 115 | + |
| 116 | +- Removed static site generation (focus on live viewer) |
| 117 | +- Simplified keyboard shortcuts (can be added back if needed) |
| 118 | +- Removed some advanced features like matrix analysis display (can be added back) |
| 119 | +- No folder management features yet (rename, move, etc.) |
| 120 | + |
| 121 | +## Development Notes |
| 122 | + |
| 123 | +The viewer focuses on core functionality with a clean, maintainable codebase. Additional features from the original viewer can be added incrementally as needed. |
0 commit comments