A containerized web application that allows users to visually simulate custom Turing machines and run Python code (using the turmachpy package) in a secure and self-hosted environment. This system was built with a microservices architecture using Docker, and includes monitoring and security best practices.
- Visual Turing Machine Simulator: Create, edit, and run custom Turing machines with an easy to use interface.
- Python Code Runner: Execute Python code relevant to Turing machines (provided by turmachpy) on the server.
- User Authentication: Secure signup, login, and profile management.
- Microservices Architecture: Isolated backend, frontend, database, and code execution environments.
- Reverse Proxy: Nginx is used as a reverse proxy, exposing only itself to the incoming traffic.
- Monitoring: Integrated the architecture with Prometheus and Grafana for metrics' visualization.
- Security: UFW firewall configuration and container isolation.
.
├── backend/ # Django REST API for users, machines, and authentication
│ ├── users/ # User management and authentication
│ ├── machines/ # Turing machine models and logic
│ ├── coderunner/ # Procy for the code execution microservice
│ └── ...
├── frontend/ # React frontend for the UI
│ ├── src/
│ │ ├── pages/ # Main app pages (Login, Signup, Dashboard, Editor, etc.)
│ │ ├── components/ # Reusable UI components (Layout and ProtectedRoute)
│ │ └── services/ # API service layer
│ └── ...
├── nginx/ # Nginx reverse proxy configuration
├── prometheus/ # Prometheus monitoring configuration
├── grafana/ # Grafana dashboards and provisioning
├── docker-compose.yml # Orchestration for all services
├── main.sh # Server setup and container orchestration script
└── README.md
- Docker & Docker Compose
-
Clone the repository:
git clone https://github.com/R2D2-08/tursim.git cd tursim -
Copy environment files and configure as needed:
cp backend/env.example backend/.env cp frontend/env.example frontend/.env # Edit the .env files relevantly to set the secrets and database credentials. -
Start all the services:
docker-compose up --build
-
Access the app:
- Frontend: http://localhost
- Grafana: http://localhost:3000
I've included a main.sh script to set up a firewall and configure the server for proper deployment of the web-app. To replicate this set-up (Ensure you've got root access):
- Clone the repository:
git clone https://github.com/R2D2-08/tursim.git cd tursim - Set REACT_APP_API_URL in
frontend/env.exampleto your server's IP address followed by/api:REACT_APP_API_URL=http://<server-ip>/api
3.Handle CORS:
Add your server's IP address to the ALLOWED_HOSTS in backend/backend/settings.py
Additionally, add http://<IP-Address> to CORS_ALLOWED_ORIGINS in backend/backend/settings.py
ALLOWED_HOSTS = [
'<server-ip>',
]
...
CORS_ALLOWED_ORIGINS = [
...
"http://<server-ip>",
]- Make the script executable:
chmod 744 main.sh
- Run the Script:
./main.sh
- Django REST Framework for API endpoints.
- users/: Handles user registration, login, JWT authentication, and profile.
- machines/: CRUD logic for Turing machines.
- coderunner/: Securely executes Python code using the
turmachpypackage by proxying requests to a local server.
- React + TypeScript.
- Pages: Login, Signup, Dashboard, Profile, Code Editor, Machine Editor, Documentation.
- API Layer: Handles communication with the backend.
- nginx/: Reverse proxy for secure routing.
- prometheus/ & grafana/: Monitoring and visualization.
- main.sh: Server setup, firewall, and container orchestration on a server, initializing everything from scratch.
- Only the Nginx container is exposed to the internet.
- UFW firewall restricts access to necessary ports.
- All sensitive credentials are managed via environment variables.
- Containers are isolated in a Docker network.