Skip to content

Setting up a local development environment

This guide explains how to set up a local environment for developing custom services or states for PERSEUS. It covers the directory structure, dependencies, and how to run both the backend (core) and frontend components locally.

We recommend checking out the PERSEUS repositories in a shared project directory like this:

my-perseus-dev/
├── core/ ← PERSEUS core (Python - FastAPI)
├── frontend/ ← PERSEUS frontend (TypeScript - React)
└── my-extension/ ← Your custom states/services

In your custom repo (my-extension/), you can define:

  • Custom services: my-extension/services/
  • Custom states: my-extension/states/

Then link them into the core project using symbolic links:

Terminal window
# Inside core/
ln -s ../../my-extension/services/ perseus/services/custom
ln -s ../../my-extension/states/ perseus/states/custom

This allows the core service to discover and load your custom components automatically during development.


PERSEUS requires a MongoDB instance. For local development, the easiest option is to run MongoDB in a Docker container:

Terminal window
docker run -d \
--name perseus-mongo \
-p 27017:27017 \
mongo:7

This exposes MongoDB on localhost:27017.

The core service is written in Python using FastAPI, and uses Pipenv to manage dependencies.

Inside the core/ directory:

Terminal window
pip install pipenv
pipenv install --dev

You need to create a .env file to define environment variables. At a minimum, you should set the MongoDB connection string:

Terminal window
MONGODB_URI=mongodb://localhost:27017
MONGODB_DATABASE_NAME=perseus
MONGODB_DATABASE_GRID_FS_NAME=perseus_fs

Other variables like FIRST_OWNER, DEMO, or LDAP-related values can also be added. Read more about the other configuration options here.

Terminal window
source .env
pipenv run fastapi dev perseus/main.py

This will start the core on http://localhost:8000.


The frontend is a React + TypeScript project powered by Vite.

Inside the frontend/ directory:

Terminal window
npm install

For local development and proxying to the backend, we recommend using perseus.localhost as the local domain. Add the following line to your /etc/hosts file:

127.0.0.1 perseus.localhost

This allows the frontend to be served under a custom domain, avoiding CORS issues.

The frontend will automatically load a file called vite.proxy.local.ts if it exists.

Create the file frontend/vite.proxy.local.ts with the following content:

import type { ProxyOptions } from "vite";
export const proxy: Record<string, string | ProxyOptions> = {
"/api": {
target: "http://perseus.localhost:8000",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
};

Replace perseus.localhost with the domain where your local core service is running (default: localhost:8000).

Terminal window
npx vite serve --host perseus.localhost --port 5173

You can now access the frontend in your browser at:

http://perseus.localhost:5173

It will proxy API requests to the backend at /api.


  • To reload your FastAPI backend automatically on code changes, make sure to use fastapi dev (not uvicorn) and install your dependencies in --dev mode.
  • Both frontend and core are hot-reload capable if started with the commands above.
  • You can run MongoDB with a persistent volume using -v perseus-mongo:/data/db if needed.

ComponentTech StackStart Command
MongoDBDockerdocker run -p 27017:27017 mongo:7
Backend (core)FastAPI + Pipenvsource .env && pipenv run fastapi dev perseus/main.py
FrontendReact + Vite + TypeScriptnpx vite serve --host perseus.localhost --port 5173