PolarLearn is an educational web application for exploring polar codes interactively. It combines a FastAPI backend with a React frontend so students can generate masks, run encoding/decoding, inspect intermediate stages, and compare BER performance.
- Features
- Technology Stack
- Project Structure
- Prerequisites
- Quick Start (Recommended)
- Step-by-Step Manual Setup
- How to Use the Application
- Backend API Overview
- Testing
- Troubleshooting
- Configuration Notes
- Common Development Commands
- FAQ
- Interactive polarization analysis.
- Mask generation and visualization helpers.
- Polar encoder flow with stage-by-stage outputs.
- Successive Cancellation decoder tracing.
- BER simulation and comparison endpoints.
- Browser-based UI for running and understanding all modules.
- Python
- FastAPI
- Uvicorn
- Pydantic
- Pytest
- React
- Vite
- React Router
- Recharts
PolarLearn/
├── backend/
│ ├── app/
│ │ ├── api/ # FastAPI routes and schemas
│ │ ├── core/ # Config, logging, exceptions
│ │ ├── domain/ # Polar code logic and services
│ │ ├── tests/ # Backend tests (pytest)
│ │ └── main.py # FastAPI app entrypoint
│ └── requirements.txt # Python dependencies
├── frontend/
│ ├── src/
│ │ ├── api/ # HTTP client and API wrappers
│ │ ├── app/ # Router and app shell
│ │ ├── components/ # UI components
│ │ ├── hooks/ # Page/module hooks
│ │ ├── pages/ # Route-level pages
│ │ └── styles/ # CSS files
│ ├── index.html
│ └── package.json
├── docs/
├── docker-compose.yml
└── README.md
Install the following before you start:
- Git (for cloning)
- Python 3.10+ (3.11 recommended)
- Node.js 18+ (LTS recommended)
- npm 9+ (usually comes with Node)
To verify:
git --version
python3 --version
node --version
npm --versionIf you want the fastest route:
# 1) Clone
git clone <YOUR_REPO_URL>
cd PolarLearn
# 2) Backend
cd backend
python3 -m venv .venv
source .venv/bin/activate # Linux/macOS
pip install --upgrade pip
pip install -r requirements.txt
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000Open a second terminal:
cd PolarLearn/frontend
npm install
npm run dev -- --host 127.0.0.1 --port 5173Then open: http://127.0.0.1:5173
Backend API docs: http://127.0.0.1:8000/docs
git clone <YOUR_REPO_URL>
cd PolarLearnIf your default branch is not checked out automatically:
git branch -a
git checkout <branch_name>From project root:
cd backendCreate virtual environment:
python3 -m venv .venvActivate it:
- Linux/macOS:
source .venv/bin/activate - Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
- Windows (CMD):
.venv\Scripts\activate.bat
Install dependencies:
pip install --upgrade pip
pip install -r requirements.txtRun backend server:
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000Check health quickly:
curl http://127.0.0.1:8000/Expected behavior:
- Server starts without import errors.
- Swagger UI is available at
/docs.
Open a new terminal and go to frontend directory:
cd PolarLearn/frontendInstall dependencies:
npm installRun dev server:
npm run dev -- --host 127.0.0.1 --port 5173Open in browser:
- App:
http://127.0.0.1:5173
The app expects:
- Frontend at
http://127.0.0.1:5173 - Backend at
http://127.0.0.1:8000
Keep both terminals running while using the app.
- Start backend and frontend.
- Open frontend in browser.
- Navigate through modules in the sidebar.
- Enter polar-code parameters (
N,K, SNR/design values, vectors). - Submit forms to call backend endpoints.
- Inspect:
- generated masks,
- encoder stages,
- decoder steps,
- BER curves/tables,
- polarization visuals.
Tip: begin with smaller block lengths (e.g., N=8 or N=16) to understand transformations before larger configurations.
The backend registers the following route groups:
/(home)/api/theory/api/mask/api/encoder/api/decoder/api/ber/api/polarization
Use Swagger UI for interactive requests:
http://127.0.0.1:8000/docs
Use ReDoc:
http://127.0.0.1:8000/redoc
Run backend tests:
cd backend
pytest -qUseful options:
pytest -q -k encoder
pytest -q -k decoder
pytest -q -k berCause: missing dependencies or wrong venv.
Fix:
cd backend
source .venv/bin/activate # or Windows equivalent
pip install -r requirements.txt- Verify backend is running on port
8000. - Verify frontend uses
http://127.0.0.1:8000as API base. - Check browser devtools Network tab for failed requests.
Use different ports:
uvicorn app.main:app --reload --port 8001
npm run dev -- --port 5174If you change backend port, also update frontend API base URL accordingly.
- Ensure Node.js LTS is installed.
- Remove lockfile/modules and reinstall:
rm -rf node_modules package-lock.json npm install
Run with module form:
python -m pytest -q- Frontend API base URL is currently hardcoded in
frontend/src/api/client.js. - Backend CORS is configured to allow all origins for development convenience.
docker-compose.ymlcurrently exists as a placeholder and is not configured for full one-command startup.
# start server with reload
uvicorn app.main:app --reload
# run tests
pytest -q
# install/update deps
pip install -r requirements.txt# development
npm run dev
# production build
npm run build
# preview production build
npm run preview