A full-stack application for monitoring and controlling a robot using an HTTP-based API, built with FastAPI (backend) and React (frontend). WebSockets are also implemented in the backend for extensibility, though the frontend currently communicates via HTTP.
- Project Overview
- 🧠 Project Decisions
- 🚀 Setup
- 🧪 Testing
- ⚡ WebSocket Support
- ⚙️ Configuration and Environment
The goal of this project is to create a simple, functional interface to control and monitor the state of a robot. The backend provides an API to retrieve the robot's state and logs, control the fan speed, and toggle the robot's power. The frontend displays this data and allows the user to interact with the robot.
This section highlights important architectural and design decisions made during the development of the project.
- Stateless Backend: Logs and robot state are not stored in global variables or shared memory. Instead, a logging mechanism is used to persist logs, and robot state is managed through a dedicated
RobotServiceclass. - Logging over State: Instead of holding logs in memory or the app state, Python’s built-in
loggingis used for simplicity and scalability. - WebSockets Ready: Although the frontend uses HTTP polling (as specified), WebSocket support is partially implemented and works for most use cases.
- Strict Modularity: The frontend follows a component-based structure for clarity and maintainability. Backend needs some refactoring.
- CORS Configuration: The backend is set up to handle cross-origin requests during local development using FastAPI’s middleware.
-
Clone the repository:
git clone https://github.com/Sztakler/clone
-
Set up a virtual environment for the backend:
- Install
venvif you don't have it:python3 -m pip install --user virtualenv
- Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
- Install
-
Install the backend dependencies:
cd backend pip install -r requirements.txt -
Start the backend server:
python app/main.py
- Server can be configured using CLI options:
-h, --help show this help message and exit --host HOST Host for the server --port PORT Port for the server --log-level LOG_LEVEL Log level for the application --refresh-rate REFRESH_RATE Frequency of state updates in Hz (default 10Hz) - Example:
python app/main.py --refresh-rate=10
- Server can be configured using CLI options:
-
Install the frontend dependencies:
cd frontend npm install -
Start the frontend development server:
npm start
Now you can access the application in your browser at http://localhost:3000.
To run the application with Docker, you'll need to build and start the containers using Docker Compose.
-
Make sure you have Docker and Docker Compose installed.
-
Clone the repository:
git clone https://github.com/Sztakler/clone
-
Navigate to the
backenddirectory and build the container:cd backend docker-compose up --build -
Navigate to the
frontenddirectory and build the container:cd frontend docker-compose up --build -
This will start both the backend and frontend containers. The application will be accessible at
http://localhost:3000. -
To shut down the container:
docker-compose down
Backend uses pytest for tests. To run them:
cd backend
pip install -r requirements.txt
pytestFrontend uses jest for tests. To run them:
cd frontend
npm install
npm testWebSocket support is partially implemented in the backend and works for most use cases. It was initially developed to enable proper real-time updates, which would be ideal for a robot control app. However, due to project specification requirements, the final implementation uses HTTP polling only.
-
Default Ports:
- Backend: runs on
5487 - Frontend: runs on
3000 - You can change them by editing the
.envfiles inbackend/.envandfrontend/.envrespectively.
- Backend: runs on
-
.env Setup:
- Each part of the app can be configured with environment variables using a
.envfile. - Example
.envfile for the backend (backend/.env):PORT=5487 ENV=development
- Example
.envfile for the frontend (frontend/.env):REACT_APP_PORT=3000
These values are automatically loaded by Docker Compose or can be used manually when running the app locally.
- Each part of the app can be configured with environment variables using a