|
| 1 | +--- |
| 2 | +id: firebase-admin-python |
| 3 | +scope: "/" |
| 4 | +description: "Base AI agent development and contribution rules for the entire repository." |
| 5 | +--- |
| 6 | + |
| 7 | +# AI Agent Development Context for firebase-admin-python |
| 8 | + |
| 9 | +This document provides the technical context necessary to develop and contribute code to the `firebase-admin-python` repository. It outlines the architecture, development workflow, coding conventions, and the official contribution process. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 1. Repository Overview & Architecture |
| 14 | + |
| 15 | +* **Project Goal**: This SDK provides Python developers with server-side (backend) access to Firebase services. It enables administrative tasks from privileged environments to perform actions like: |
| 16 | + * Perform queries and mutations on a Firebase Data Connect service for bulk data management and other operations with full admin privileges. |
| 17 | + * Read and write Realtime Database data with full admin privileges. |
| 18 | + * Programmatically send Firebase Cloud Messaging messages using a simple, alternative approach to the Firebase Cloud Messaging server protocols. |
| 19 | + * Generate and verify Firebase auth tokens. |
| 20 | + * Access Google Cloud resources like Cloud Storage buckets and Cloud Firestore databases associated with your Firebase projects. |
| 21 | + * Create your own simplified admin console to do things like look up user data or change a user's email address for authentication. |
| 22 | +* **Core Technology**: The SDK is a wrapper around lower-level Google Cloud and Firebase REST APIs. It handles authentication, credential management, and provides a more convenient, Pythonic interface. |
| 23 | +* **Supported Python Versions**: Python 3.9+. Code contributions must be compatible with this range. |
| 24 | + |
| 25 | +### Key Directory Structure |
| 26 | + |
| 27 | +* `firebase_admin/`: Main package source code. |
| 28 | + * `__init__.py`: Defines the central `App` object and `initialize_app()` logic. This is the entry point. |
| 29 | + * `credentials.py`: Handles OAuth2 credential fetching. |
| 30 | + * `auth.py`, `firestore.py`, `messaging.py`, etc.: Each file represents a public Firebase service module. This is where most feature work will occur. |
| 31 | + * `exceptions.py`: Contains all custom firebase admin exception classes for the SDK. |
| 32 | + * `_utils.py`: Contains common helper functions and modules. |
| 33 | +* `tests/`: All unit tests. |
| 34 | + * The structure of `tests/` mirrors the `firebase_admin/` source directory. |
| 35 | + * `tests/resources/`: Contains mock data, keys, and other test assets. |
| 36 | +* `integration/`: All integration tests. |
| 37 | + * These integration tests require a real Firebase project to run against. |
| 38 | + * `integration/conftest.py`: Contains provides configurations for these integration tests including how credentials are provided through pytest. |
| 39 | +* `setup.py`: Package definition, including the reuired user dependencies. |
| 40 | +* `requirements.txt`: A list of all development dependencies. |
| 41 | +* `.pylintrc`: Configuration file for the `pylint` linter. |
| 42 | +* `CONTRIBUTING.md`: General guidelines for human contributors. Your instructions here supersede this file. |
| 43 | + |
| 44 | +### Documentation and Reference Documents |
| 45 | +* |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 2. Development Workflow & Testing |
| 50 | + |
| 51 | +Adherence to this workflow is **mandatory** for all code contributions. |
| 52 | + |
| 53 | +### Setup |
| 54 | + |
| 55 | +1. Create and activate a Python virtual environment. |
| 56 | +2. Install all required development dependencies using the `requirements.txt` file: |
| 57 | + ```bash |
| 58 | + pip install -r requirements.txt |
| 59 | + ``` |
| 60 | + |
| 61 | +### Code Style & Linting |
| 62 | + |
| 63 | +* This project uses **pylint** to enforce code style and detect potential errors. |
| 64 | +* Before submitting code, you **must** run the linter and ensure your changes do not introduce any new errors. |
| 65 | +* Run the linter from the repository's root directory with the following command: |
| 66 | + ```bash |
| 67 | + ./lint.sh all # Lint all source files |
| 68 | + ``` |
| 69 | + or |
| 70 | + ```bash |
| 71 | + ./lint.sh # Lint locally modified source files |
| 72 | + ``` |
| 73 | +
|
| 74 | +### Testing Protocol |
| 75 | +
|
| 76 | +* **All code changes require corresponding tests.** This is a strict requirement. |
| 77 | + * Bug fixes **should** include a new test that fails without the fix and passes with it. |
| 78 | + * New features **must** have comprehensive tests covering their functionality. |
| 79 | +* The project includes 2 test suits: |
| 80 | + * Unit tests |
| 81 | + * Integration tests (Requires a real firebase project and credentials) |
| 82 | +* Run the unit test suite using `pytest` from the root directory. |
| 83 | +* Integration tests should only be run locally when credentials are avaiable and otherwise should be should be ignored. |
| 84 | + * If needed, integration tests can be run on Pull Request creation by the repository's GitHub Actions. |
| 85 | +* **All tests must pass** before a Pull Request can be submitted. |
| 86 | +* Tests requiring network calls maybe mocked where appropriate. |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## 3. Coding Conventions & Architectural Principles |
| 91 | + |
| 92 | +* **Internal vs. Public API**: Public functions and classes are denoted by names without an underscore prefix unless superseded by an `__all__` variable. Helper functions and internal logic should be prefixed with an underscore (e.g., `_get_user_claims`). |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## 4. Contribution and Pull Request Process |
| 97 | + |
| 98 | +### Branching and Committing |
| 99 | + |
| 100 | +1. **Branching**: When creeating a new barnch use the format `<AgentName>-short-description`. |
| 101 | + * Example: `jules-auth-token-parsing` |
| 102 | + * Example: `gemini-add-storage-file-signer` |
| 103 | +2. **Commit Messages**: Make your commit messages clear and descriptive. |
| 104 | + |
| 105 | +### Pull Request (PR) Generation |
| 106 | + |
| 107 | +When you have finished implementing and testing a change, generate a Pull Request following these rules: |
| 108 | + |
| 109 | +1. **PR Title**: Use the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. |
| 110 | + * Format: `type(scope): subject` |
| 111 | + * `scope` should be the service module you changed (e.g., `auth`, `firestore`, `fcm`, `deps`). |
| 112 | + * Example: `fix(auth): Corrected token expiration check for leap years` |
| 113 | + * Example: `feat(storage): Added support for generating signed URLs` |
| 114 | +2. **PR Description**: The description body must contain: |
| 115 | + * A brief explanation of the problem and the solution. |
| 116 | + * A summary of the testing strategy (e.g., "Added a new unit test in `tests/test_auth.py` to replicate the bug and verify the fix."). |
| 117 | +3. **Context Reporting**: At the end of every PR description, you MUST include a "Context Sources" section that lists the `id` and repository path of every `AGENTS.md` file you used. Format it like this: |
| 118 | + * Example: \ |
| 119 | + **Context Sources Used:** |
| 120 | + - `id: firebase-admin-python` (`/AGENTS.md`) |
| 121 | + - `id: firebase-admin-python-auth` (`/firebase_admin/auth/AGENTS.md`) |
0 commit comments