Skip to content

Shared Package ​

Why ​

Agent and Server were duplicating db.py (MongoDB connections + collection references) and schema.py (document builders like call_history_schema, conversation_history_schema). Changing a collection name or adding a field meant updating two places easy to forget, guaranteed bugs.

Now there's one source of truth: shared/.

What's in it ​

shared/
├── __init__.py
├── pyproject.toml
├── db.py          # All MongoDB collections
└── schema.py      # All document schema builders (DBSchema)

What's NOT in it ​

  • Analysis uses async motor driver (not pymongo), has its own domain-specific schemas. No duplication.
  • client_backend Node.js/Mongoose, different language entirely. Reads Python-written collections with strict: false.

How to use ​

Import from shared instead of local src.db / src.schema:

python
# Before
from src.db import call_history_collection
from src.schema import DBSchema

# After
from shared.db import call_history_collection
from shared.schema import DBSchema

Local development ​

Install the shared package in editable mode from Agent or Server directory:

bash
pip install -e ../shared

Or add to requirements.txt:

-e ../shared

Docker ​

Build context is now the repo root (not individual service folders). The Dockerfiles handle it:

dockerfile
# Copies shared into the image
COPY shared/ /app/shared/
RUN pip install --no-cache-dir /app/shared

# Then copies the service
COPY Agent/ .

docker-compose.dev.yml uses context: . with dockerfile: Agent/Dockerfile (or Server/Dockerfile).

Production docker-compose.yml uses pre-built images shared code is already baked in at build time. No runtime dependency between containers.

Scaling ​

Shared code is copied into each Docker image at build time. At runtime, Agent and Server are fully independent containers. Scaling one doesn't affect the other.

When you change shared/ ​

Rebuild both images:

bash
docker compose -f docker-compose.dev.yml build agent server

Last updated: