A full-stack real-time chat application with an integrated SymPy-powered math solver.
Stack: FastAPI · WebSockets · MongoDB · SymPy · React · Vite · TailwindCSS
webfastapi/
├── .env.example
├── README.md
├── backend/
│ ├── main.py # FastAPI app + WebSocket endpoint
│ ├── websocket_manager.py # Connection manager
│ ├── database.py # Motor/MongoDB setup
│ ├── models.py # Pydantic models
│ ├── requirements.txt
│ └── routes/
│ └── math.py # POST /api/math (SymPy solver)
└── frontend/
├── index.html
├── package.json
├── vite.config.js
├── tailwind.config.js
├── postcss.config.js
└── src/
├── main.jsx
├── App.jsx
├── api.js
├── styles/
│ └── globals.css
└── components/
├── Login.jsx
├── ChatPanel.jsx
└── MathSolver.jsx
| Tool | Version |
|---|---|
| Python | 3.10+ |
| Node.js | 18+ |
| MongoDB | 6+ (running locally on port 27017) |
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-communitysudo apt-get install -y mongodb
sudo systemctl start mongodbDownload from https://www.mongodb.com/try/download/community and start the service.
Verify MongoDB is running:
mongosh --eval "db.runCommand({ ping: 1 })"cp .env.example .env
# Edit .env if your MongoDB URI or DB name differsDefault .env:
MONGO_URI=mongodb://localhost:27017
DB_NAME=chatapp
cd backend
# Create and activate a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the server
uvicorn main:app --reload --port 8000Backend runs at → http://localhost:8000 Interactive API docs → http://localhost:8000/docs
Open a new terminal:
cd frontend
npm install
npm run devFrontend runs at → http://localhost:5173
- Open http://localhost:5173 in your browser (open multiple tabs to test multi-user chat).
- Enter a username and click Join Chat Room.
- Left panel — real-time chat shared across all connected users.
- Right panel — type any math expression and click Solve.
| Input | Output |
|---|---|
12 + 8 * 3 |
36 |
sqrt(144) |
12 |
2x + 5 = 15 |
x = 5 |
x**2 - 5*x + 6 = 0 |
x = 2, x = 3 |
2**10 |
1024 |
ws://localhost:8000/ws/{username}
- On connect: receives last 20 messages, all clients notified of join.
- Send:
{ "text": "hello" } - Receive:
{ "type": "message"|"system", "username": "...", "text": "...", "timestamp": "..." }
POST /api/math
Content-Type: application/json
{ "problem": "2x + 5 = 15" }
Response:
{ "result": "x = 5" }Install concurrently globally or use two terminals.
Using two terminals is the simplest approach — no extra tools needed.