Subsystems and Responsibilities - bcgov/lcfs GitHub Wiki
Subsystems and Responsibilities
This document outlines the major subsystems of the LCFS application, their primary responsibilities, and key technologies. It draws information from the system's docker-compose.yml files, backend (pyproject.toml), frontend (package.json), and ETL (etl/) configurations.
1. Backend (backend service)
- Description: The central application server responsible for business logic, API provision, and coordination between other services.
- Primary Technologies: Python, FastAPI, SQLAlchemy, Pydantic.
- Build: Custom Docker image built from
backend/Dockerfile(dev target) andbackend/Dockerfile.openshift(OpenShift target). - Responsibilities:
- Exposing RESTful APIs (FastAPI auto-generates OpenAPI spec) for the frontend and potentially other clients.
- Implementing core business rules and workflows of the LCFS.
- Interacting with the
db(PostgreSQL) for data persistence using SQLAlchemy ORM. - Utilizing
redisfor caching (viafastapi-cache2) and potentially session management. - Communicating with
rabbitmqfor asynchronous task processing (usingaio-pika). - Interacting with
minioobject storage for file uploads/downloads (usingboto3). - Validating incoming data using Pydantic.
- Handling API security with JWTs (issued by Keycloak, validated with
pyjwt).
- Key Configuration (from root
docker-compose.ymlenvironment variables &pyproject.tomlanalysis):- Connects to PostgreSQL (
LCFS_DB_HOST: db,LCFS_DB_PORT: 5432). - Connects to Redis (
LCFS_REDIS_HOST: redis,LCFS_REDIS_PORT: 6379). - Application Port:
8000(local dev). - Debugger Port:
5678(local dev).
- Connects to PostgreSQL (
- Directory Structure Snippet (from
02. Code Guidelines Conventions):backend └── lcfs ├── db # module contains db configurations │ ├── migrations # Alembic migrations │ ├── models # SQLAlchemy ORM models │ └── seeders # Alembic seeders ├── services # Package for different external services (e.g., rabbit, redis) ├── tests # Pytest tests ├── utils # Utility functions └── web # Package contains web server (FastAPI) ├── api # API route handlers │ └── router.py # Main FastAPI router ├── core # Core application logic ├── exception # Custom exception handlers ├── application.py # FastAPI application setup └── lifetime.py # Startup/shutdown event handlers ├── __main__.py # Startup script (runs uvicorn) ├── settings.py # Main configuration settings └── ... (other config files like alembic.ini, pyproject.toml)
2. Frontend (frontend service)
- Description: The user interface for the LCFS application, built as a Single Page Application (SPA).
- Primary Technologies: React, Vite, Material-UI, Zustand, React Query.
- Build: Custom Docker image built from
frontend/Dockerfile.dev(dev target) andfrontend/Dockerfile.openshift(OpenShift target), using Vite. - Responsibilities:
- Providing a dynamic and responsive web-based interface.
- Making API calls to the
backendservice (usingaxios) to fetch, submit, and manage data. - Client-side routing (
react-router-dom). - Managing client-side application state (
zustandfor global state,@tanstack/react-queryfor server state). - Rendering UI components (Material-UI, AG Grid for tables).
- Handling user authentication/authorization via Keycloak (
@react-keycloak/web). - Internationalization (
i18next). - Displaying maps (
react-leaflet). - Rich text editing (
react-quill).
- Key Configuration (from root
docker-compose.yml&package.jsonanalysis):- Development server port:
3000. - Build tool: Vite.
- Component library: Material-UI.
- Development server port:
- Directory Structure Snippet (from
02. Code Guidelines Conventions):frontend ├── public # Static assets ├── src │ ├── assets │ ├── components # Reusable UI components │ ├── constants │ ├── hooks # Custom React hooks │ ├── layouts │ ├── services # API service integrations (e.g., useApiService) │ ├── stores # Zustand stores │ ├── themes │ ├── utils │ ├── pages/views # Page-level components │ ├── App.jsx │ └── main.jsx ├── .storybook # Storybook configuration ├── cypress # Cypress E2E tests └── ... (config files like vite.config.js, package.json)
3. Database (db service - LCFS Main)
- Description: The primary relational database for LCFS application data.
- Technology: PostgreSQL (
postgres:14.2image). - Responsibilities: Storing transactional and relational data, ensuring data integrity.
- Configuration (from root
docker-compose.yml):- Database Name:
lcfs, User:lcfs. - Port:
5432. - Data Volume:
postgres_data.
- Database Name:
- Schema Management: Alembic (see Database Schema Overview).
4. Cache (redis service)
- Description: In-memory data store for caching.
- Technology: Redis (
bitnami/redis:7.4.2image). - Responsibilities: Storing frequently accessed data to reduce database load and improve API response times.
- Integration: Used by the
backendviafastapi-cache2. - Configuration (from root
docker-compose.yml): Port6379, Data Volumeredis_data.
5. Message Queue (rabbitmq service)
- Description: Message broker for asynchronous communication.
- Technology: RabbitMQ (
rabbitmq:3-managementimage). - Responsibilities: Managing queues for asynchronous tasks (e.g., report generation, notifications).
- Integration: Used by the
backendviaaio-pika. - Configuration (from root
docker-compose.yml): AMQP Port5672, Management UI15672.
6. Object Storage (minio service)
- Description: S3-compatible object storage.
- Technology: MinIO (
minio/minio:latestimage). - Responsibilities: Storing user-uploaded files, generated reports, etc.
- Integration: Used by the
backendviaboto3. - Configuration (from root
docker-compose.yml): API Port9000, Console9001, Bucketlcfs.
7. ETL Subsystem (Extract, Transform, Load - in etl/ directory)
- Description: Responsible for data integration, primarily migrating/synchronizing data from an external TFRS database to the LCFS database.
- Core Technology: Apache NiFi (
apache/nifi:1.27.0image).- Manages data flow pipelines defined in templates (
etl/templates/). - Uses PostgreSQL JDBC driver for database connections.
- Depends on Zookeeper for configuration management.
- Manages data flow pipelines defined in templates (
- Flow Version Control: Apache NiFi Registry (
apache/nifi-registry:1.27.0image). - Source Database (ETL context):
tfrs(PostgreSQL14.2image, runs on port5435locally). - Responsibilities:
- Extracting data from the TFRS database.
- Transforming data according to LCFS requirements.
- Loading data into the LCFS application database.
- Error logging for failed records (
etl/nifi_output/).
- Orchestration/Utilities: Local ETL environment defined in
etl/docker-compose.yml. Shell scripts (data-transfer.sh,data-migration.sh) assist with data movement and NiFi process management.
8. Identity and Access Management (IAM)
- Technology: Keycloak.
- Responsibilities: Handles user authentication, identity brokering, token issuance (JWTs), and access management.
- Integration: Frontend integrates via OIDC (
keycloak-js). Backend validates JWTs issued by Keycloak.
Potentially Used Services (Commented out in root docker-compose.yml)
clamav: Antivirus engine, likely for scanning file uploads if enabled.
This document provides an overview. For deeper dives into specific technologies or code structure, refer to the linked detailed pages or the codebase itself.