Development Environment Setup - bcgov/lcfs GitHub Wiki
Development Environment Setup
This guide walks through setting up the local development environment for the LCFS project. It combines information from the original "01. Gettings Started" wiki page with current project structure and dependencies.
1. Prerequisites
Before you begin, ensure you have the following installed on your system:
- Git: For cloning the repository and version control.
- Docker and Docker Compose: For running the application services in containers. (Install Docker, Docker Compose is typically included).
- Node.js and npm: For frontend development.
- It's recommended to use a Node version manager like
nvm
to easily switch Node versions. - Check
frontend/.nvmrc
(if it exists) orfrontend/package.json
(engines
field) for the specific Node.js version recommended for the project. If not specified, a recent LTS version is generally a good choice. - npm (Node Package Manager) is included with Node.js.
- It's recommended to use a Node version manager like
- Python and Poetry: For backend development.
- Python version is specified in
backend/.python-version
(e.g., 3.9+). - Poetry is used for Python dependency management. (Install Poetry).
- Python version is specified in
- OpenShift CLI (
oc
): Optional, but required for certain tasks like data transfer to/from OpenShift environments using scripts in theetl/
directory. (Install OpenShift CLI).
2. Cloning the Repository
Clone the LCFS repository to your local machine:
git clone https://github.com/bcgov/lcfs.git
cd lcfs
3. Running the Full Application (Docker Compose)
The simplest way to get all core services (frontend, backend, database, Redis, RabbitMQ, MinIO) running together is using the main Docker Compose file at the project root.
docker-compose up --build
- The
--build
flag ensures that Docker images are rebuilt if there are changes to Dockerfiles or related build contexts. - Once started:
- Frontend will be accessible at:
http://localhost:3000
- Backend API documentation (Swagger UI) will be accessible at:
http://localhost:8000/docs
(Note: original wiki said/3000/docs
, but FastAPI typically serves on its own port). - Backend API documentation (ReDoc) will also be available at:
http://localhost:8000/redoc
.
- Frontend will be accessible at:
4. Setting Up and Running Frontend Separately
If you need to work primarily on the frontend or run it independently:
- Navigate to the frontend directory:
cd frontend
- Install dependencies:
This will also install Husky git hooks if configured (checknpm install
.husky/
directory). - Run the frontend development server:
The frontend will typically be available atnpm run dev
http://localhost:3000
(as configured in Vite andpackage.json
).
5. Setting Up and Running Backend Separately
If you need to work primarily on the backend or run it independently:
- Navigate to the backend directory:
cd backend
- Install dependencies using Poetry:
Ensure Poetry is installed and configured in your shell.
poetry install
- Set up pre-commit hooks (recommended for code quality checks before committing):
Pre-commit hooks are configured inpoetry run pre-commit install
backend/.pre-commit-config.yaml
and typically run tools like Black, Flake8, MyPy, and Isort. - Run the backend development server:
This command executes thepoetry run python -m lcfs
__main__.py
script in thelcfs
package, which starts the Uvicorn server for the FastAPI application. The backend API will typically be available athttp://localhost:8000
.
6. Setting Up the ETL Environment
The ETL subsystem (Apache NiFi and related services) has its own Docker Compose setup for local development.
- Navigate to the ETL directory:
cd etl
- Run ETL services:
This starts NiFi, NiFi Registry, Zookeeper, and the TFRS source database.docker-compose up -d
- Access NiFi UI:
http://localhost:8091/nifi/
- Access NiFi Registry UI:
http://localhost:18080
- Refer to
etl/readme.md
or Data Migration (TFRS to LCFS) for instructions on loading NiFi templates and configuring database connections within NiFi.
7. IDE Setup
- VS Code: Recommended extensions for Python (Pylance, Python Test Explorer), JavaScript/React (ESLint, Prettier), Docker.
- Ensure your VS Code settings use the project's Python interpreter (managed by Poetry) and Node.js version.
- Other IDEs: Configure according to their specific instructions for Python/Poetry and Node.js/npm projects.
8. Environment Variables
- Backend: Core database and service connection details are often set via environment variables in
docker-compose.yml
for local development. For running the backend separately, you might need to set these in your shell or a.env
file (checkbackend/lcfs/settings.py
for how Pydantic settings loads them). - Frontend: Environment variables for the frontend (e.g., API base URL if not relative, Keycloak settings) are typically managed via
.env
files (e.g.,.env
,.env.development
) loaded by Vite. Checkfrontend/vite.config.js
and the application code. - Cypress: E2E tests require
frontend/cypress.env.json
for test user credentials and other parameters. Create this by copyingfrontend/cypress.env.example.json
and filling in the necessary values. Do not commitcypress.env.json
.
This setup guide should provide a solid foundation for local development. Refer to specific README files in subdirectories (backend/README.md
, frontend/README.md
, etl/readme.md
) for more detailed information on each component.