---
globs: back/**
alwaysApply: false
---

# Python Firebase Functions - Broker Architecture

This project follows the broker architecture pattern for Firebase Functions.

## Folder Structure

### `src/` - Source Code

#### Core Components

- **brokers/** - Message/event handling layer

  - **callable/** - Client-callable functions (Firebase callable functions)
  - **https/** - HTTP endpoints (REST APIs)
  - **triggered/** - Event-triggered functions (Firestore/Storage triggers)

- **documents/** - DocumentBase classes

  - Each document class represents a Firestore collection
  - All Firestore operations MUST go through these classes
  - Never access Firestore directly

- **models/** - Type definitions

  - **firestore_types.py** - Pydantic models for Firestore documents
  - **function_types.py** - Request/response types for functions
  - **util_types.py** - Utility types and enums

- **services/** - Business logic

  - Orchestrate operations across multiple documents
  - Complex workflows and business rules

- **factories/** - Object creation

  - Create documents from various sources (CSV, JSON, templates)
  - Batch operations

- **shared/** - Shared components

  - **Db.py** - Database singleton with ProjectDb class
  - **DocumentBase.py** - Base document class

- **util/** - Utility functions

  - Authentication helpers
  - CORS handling
  - Logging

- **exceptions/** - Custom exceptions
  - Project-specific error classes

### `tests/` - Test Suite

- **integration/** - End-to-end tests
- **unit/** - Component tests
- **util/** - Test utilities
