This document provides strict instructions, coding standards, and architectural context for any AI/LLM assisting with this project.
This is an ETL (Extract, Transform, Load) data pipeline project that extracts data (likely from MongoDB, based on scripts/python/mongo_to_postgres.py), transforms it using PySpark, validates it via Great Expectations (gx/), and loads it into a PostgreSQL relational database. It includes observability via Docker/Grafana and extensive SQL-based analytics.
src/: Core Python ETL pipeline logic (pipeline/), database connections (database/), and validation triggers (validation/).scripts/: Operational Bash and Python scripts (e.g.,scripts/shell/monitor_logs.sh,scripts/python/run_gx.py).sql/: Analytical queries, schema explorations, and PL/pgSQL functions.tests/: Data quality tests using Python (data_quality/) and SQL/PLpgSQL (generic/loops/).gx/: Great Expectations configurations, suites, and uncommitted data docs.docker/: Grafana and Prometheus observability stack.ps1/: PowerShell automation (e.g.,local_runner.ps1).utils/: Shared Python utilities (logging, metrics, engines).docs/&reports/: Documentation and generated Markdown reports.
- Think Step-by-Step: Plan your logic before generating code.
- Short & Concise Comments: Write meaningful, brief comments. Explain the why, not the what. Do not over-comment obvious code.
- No Placeholders: Do not use
// ... existing code ...unless explicitly asked to truncate. Provide fully working blocks. - Modularity: Keep functions small and single-purpose.
- Standard: Follow PEP 8 strict guidelines.
- Type Hinting: Always use strict type hints (e.g.,
def transform_data(df: DataFrame) -> DataFrame:). - Docstrings: Use short Google-style docstrings for classes and complex functions.
- Imports: Organize imports cleanly. Standard library first, third-party (PySpark, Great Expectations) second, local (
src.*,utils.*) third. - Error Handling: Use specific exceptions. Leverage the custom logger in
utils/logger.py.
- Safety First: Every Bash script must start with
set -euo pipefail. - Variables: Quote all variables (e.g.,
"${FILE_PATH}"). Prefer lowercase for local variables and UPPERCASE for environment variables. - Modularity: Use functions for repetitive logic.
- Logging: Echo informative output with timestamps if the script runs continuously (like
monitor_logs.sh).
- Safety: Enforce
Set-StrictMode -Version Latestand$ErrorActionPreference = "Stop". - Naming: Use standard
Verb-Nounconventions for custom functions (e.g.,Invoke-Pipeline). - Parameters: Use
[CmdletBinding()]and strong typing for script parametersParam([string]$Environment). - Paths: Use
Join-Pathinstead of string concatenation for file paths to maintain cross-platform compatibility.
- Indentation: MUST use actual tabs, not spaces.
- Phony Targets: Always declare
.PHONY: target_namefor non-file targets. - Self-Documenting: Add a
helptarget that usesgreporawkto parse comments and describe what each command does. - Environment: Load the
.envfile automatically at the top of the Makefile if environment variables are required.
This project strictly uses uv by Astral for Python dependency management.
- No pip/conda: Do not suggest
pip installorconda install. - Running Scripts: Always prefix Python executions with
uv run(e.g.,uv run main.pyoruv run scripts/python/run_gx.py). - Adding Dependencies:
- Standard:
uv add <package> - Dev Dependencies:
uv add --dev <package>(Use this for linters, formatters, or testing frameworks likepytest).
- Standard:
- Syncing: Suggest
uv syncto install dependencies fromuv.lockandpyproject.toml.
- Workflows: The
.github/workflowsfolder contains CI rules (codeql.yml,linting.yml). Ensure any new code complies with strict linting standards before suggesting a commit. - Pull Requests: Code changes must not break existing Great Expectations suites (
gx/) or PySpark DataFrame schemas. - Linting Compliance: Assume the pipeline enforces
rufforflake8andmypyvialinting.yml. Code provided must pass these silently.
- PySpark (
src/pipeline/): Avoid UDFs where standard Spark SQL functions (pyspark.sql.functions) can be used. Rely onsrc/pipeline/spark_session.pyfor context generation. - SQL (
sql/&tests/generic/loops/): Use standard PostgreSQL syntax. Avoid reserved keywords as column names. Use explicitJOINsyntax rather than implicitWHEREclauses. - Great Expectations (
gx/): When updating validations, interact strictly through thesrc/validation/wrappers orscripts/python/run_gx.py.
When suggesting Git commands or generating commits, strictly adhere to the following rules:
- Staging: Prefer specific file staging (
git add <file>) over blind blanket additions (git add .) to maintain atomic commits. - Conventional Commits: Commit messages MUST follow the Conventional Commits format to standardize project history:
feat:for new pipeline features, scripts, or analytical queries (e.g.,feat: add cohort analysis SQL script).fix:for bug fixes in ETL logic or configs (e.g.,fix: resolve PySpark memory leak in transform step).docs:for updating markdown reports or data catalogs (e.g.,docs: update run book for incremental loading).chore:for routine tasks, dependency updates, or Docker changes (e.g.,chore: add pytest to uv dev dependencies).refactor:for code restructuring that doesn't alter behavior (e.g.,refactor: modularize mongo_source.py extraction logic).test:for adding or fixing data quality tests (e.g.,test: add PL/pgSQL loops test for products).
- Commit Style: Use the imperative mood in the subject line (e.g., "add", not "added" or "adds"). Keep the subject line concise (under 50 characters).