Skip to content

Backend Overview

The backend is a Flask API server that handles authentication, simulation job orchestration, and result persistence. It uses Celery for async task execution and PostgreSQL for storage.

ComponentTechnology
Web frameworkFlask + Flask-RESTful
Task queueCelery (Redis broker, eventlet pool)
DatabasePostgreSQL via SQLAlchemy + Flask-SQLAlchemy
MigrationsFlask-Migrate (Alembic)
AuthJWT (PyJWT), Keycloak OIDC
Reverse proxyNginx (TLS)
PackagingPoetry
yaptide/
├── yaptide/
│ ├── __init__.py
│ ├── application.py # Flask app factory
│ ├── routes/
│ │ ├── main_routes.py # Route registration
│ │ ├── auth_routes.py # Native auth (register/login/refresh)
│ │ ├── keycloak_routes.py # Keycloak SSO auth
│ │ ├── simulation_routes.py # Jobs (direct + batch)
│ │ ├── result_routes.py # Results, estimators, logfiles
│ │ ├── user_routes.py # User simulation management
│ │ └── utils/
│ │ └── decorators.py # @requires_auth decorator
│ ├── persistence/
│ │ ├── models.py # SQLAlchemy models (12 tables)
│ │ └── db_methods.py # Database access layer
│ ├── celery/
│ │ ├── simulation_worker.py # Celery app + run_single_simulation task
│ │ └── helper_worker.py # Batch submission + cleanup tasks
│ ├── batch/
│ │ ├── batch_methods.py # SSH connection + Slurm job management
│ │ └── watcher_scripts/ # Scripts deployed to HPC clusters
│ ├── utils/
│ │ ├── enums.py # PlatformType, EntityState, InputType
│ │ └── sim_utils.py # Simulation preparation utilities
│ └── admin/
│ ├── db_manage.py # CLI: user management
│ └── simulators.py # CLI: simulator binary management
├── migrations/
│ └── versions/ # Alembic migration scripts
├── tests/
│ ├── conftest.py # Fixtures (Flask app, test client, sample data)
│ ├── integration/ # Full-stack tests
│ └── ... # Unit tests
├── pyproject.toml
├── pytest.ini
└── docker-compose.yml

The app is created via yaptide.application using the Flask factory pattern. It initializes:

  • SQLAlchemy database connection
  • Flask-Migrate for schema migrations
  • Flask-RESTful for REST endpoint routing
  • CORS (when FLASK_USE_CORS=true)
  • JWT secret key for token signing

All routes are registered in routes/main_routes.py. Each route is a Flask-RESTful Resource class with get(), post(), put(), delete() methods.

Two Celery workers with separate queues:

WorkerQueue(s)Responsibility
simulation_workerceleryRun simulator binaries, monitor progress, merge results
helper_workerhelper, helper-shortSubmit batch jobs to HPC, handle cleanup

Workers communicate back to Flask via HTTP callbacks (POST /tasks, POST /results).

All large data (input files, simulation results, logs) is gzip-compressed before storage in PostgreSQL. The compress() and decompress() helpers handle this transparently.

VariableDescription
FLASK_SQLALCHEMY_DATABASE_URIPostgreSQL connection string
CELERY_BROKER_URLRedis broker URL
CELERY_RESULT_BACKENDRedis result backend URL
BACKEND_INTERNAL_URLFlask URL for worker callbacks
BACKEND_EXTERNAL_URLPublic-facing URL
FLASK_USE_CORSEnable CORS for local dev
KEYCLOAK_BASE_URLKeycloak server URL
KEYCLOAK_REALMKeycloak realm
CERT_AUTH_URLPLGrid SSH cert service URL
MAX_CORESCPU limit for simulation worker
LOG_LEVEL_ROOTLogging verbosity