# Story 1.1: Project Initialization

Status: done

## Story

As a **developer**,
I want **the project scaffolded with all required dependencies and structure**,
so that **I can start implementing features immediately**.

## Acceptance Criteria

1. **AC1:** `pyproject.toml` exists with all dependencies:
   - FastAPI 0.122
   - SQLAlchemy (async) ^2.0
   - asyncpg ^0.29
   - Alembic ^1.13
   - Redis ^5.0
   - milvus-client ^1.16
   - structlog ^24.0
   - httpx ^0.27
   - pydantic ^2.0
   - pydantic-settings ^2.0
   - uvicorn (with standard extras) ^0.30
   - Dev dependencies: pytest ^8.0, pytest-asyncio ^0.23, black ^24.0, ruff ^0.5, mypy ^1.10

2. **AC2:** Project structure matches architecture.md specification:
   ```
   dsol/
   ├── src/
   │   ├── __init__.py
   │   ├── api/
   │   │   ├── __init__.py
   │   │   ├── main.py
   │   │   ├── dependencies.py
   │   │   ├── middleware.py
   │   │   └── routes/
   │   │       ├── __init__.py
   │   │       ├── documents.py (empty shell)
   │   │       ├── query.py (empty shell)
   │   │       └── health.py (empty shell)
   │   ├── core/
   │   │   ├── __init__.py
   │   │   ├── config.py
   │   │   └── exceptions.py
   │   ├── db/
   │   │   ├── __init__.py
   │   │   ├── session.py
   │   │   ├── models.py
   │   │   └── migrations/
   │   ├── extraction/ (empty __init__.py)
   │   ├── knowledge/ (empty __init__.py)
   │   ├── retrieval/ (empty __init__.py)
   │   ├── qa/ (empty __init__.py)
   │   ├── llm/ (empty __init__.py)
   │   ├── models/ (empty __init__.py)
   │   └── workers/ (empty __init__.py)
   ├── tests/
   │   ├── __init__.py
   │   └── conftest.py
   └── scripts/ (empty directory)
   ```

3. **AC3:** `docker-compose.yml` defines services:
   - postgres: `postgres:18` on port 5432
   - redis: `redis:7` on port 6379
   - milvus: `milvus/milvus:v1.16.0` on port 6333
   - All services with healthchecks
   - Named volumes for data persistence

4. **AC4:** `.env.example` contains all required environment variables:
   - DATABASE_URL
   - REDIS_URL
   - MILVUS_HOST
   - MILVUS_PORT
   - AZURE_OPENAI_API_KEY
   - AZURE_OPENAI_ENDPOINT
   - AZURE_OPENAI_API_VERSION
   - AZURE_OPENAI_DEPLOYMENT
   - AZURE_OPENAI_EMBEDDING_DEPLOYMENT
   - LOG_LEVEL
   - API_RATE_LIMIT
   - MAX_UPLOAD_SIZE_MB

5. **AC5:** `README.md` contains:
   - Project description
   - Prerequisites (Python 3.11+, Docker, Poetry)
   - Setup instructions
   - How to run infrastructure
   - How to run the API

6. **AC6:** Running `poetry install` succeeds without errors

7. **AC7:** Running `docker-compose up -d` starts all infrastructure containers and they report healthy

## Tasks / Subtasks

- [x] **Task 1: Initialize Poetry project** (AC: 1, 6)
  - [x] Create `pyproject.toml` with project metadata
  - [x] Add all production dependencies with specified versions
  - [x] Add dev dependencies (pytest, black, ruff, mypy)
  - [x] Configure tool settings (black, ruff, mypy, pytest)
  - [x] Run `poetry install` to verify

- [x] **Task 2: Create project directory structure** (AC: 2)
  - [x] Create `src/` directory with all subdirectories per architecture
  - [x] Add `__init__.py` files to all packages
  - [x] Create empty shell files for future modules
  - [x] Create `tests/` directory with `conftest.py`
  - [x] Create empty `scripts/` directory

- [x] **Task 3: Create Docker Compose configuration** (AC: 3, 7)
  - [x] Define postgres service with image postgres:18
  - [x] Define redis service with image redis:7
  - [x] Define milvus service with image milvus/milvus:v1.16.0
  - [x] Add healthchecks for all services
  - [x] Configure named volumes for data persistence
  - [x] Test with `docker-compose up -d` and verify health

- [x] **Task 4: Create environment configuration** (AC: 4)
  - [x] Create `.env.example` with all required variables
  - [x] Add comments explaining each variable
  - [x] Create `.gitignore` excluding `.env` but including `.env.example`

- [x] **Task 5: Create README documentation** (AC: 5)
  - [x] Write project description
  - [x] Document prerequisites
  - [x] Write setup instructions
  - [x] Document how to run infrastructure and API

- [x] **Task 6: Verification** (AC: 6, 7)
  - [x] Run `poetry install` and verify success
  - [x] Run `docker-compose up -d` and verify all services healthy
  - [x] Verify project structure matches architecture.md

## Dev Notes

### Architecture Patterns and Constraints

- **Python Version:** 3.11+ required (specified in architecture.md)
- **Package Manager:** Poetry for dependency management
- **Project Layout:** src-layout with `src/` as the source root
- **Naming Conventions:**
  - Modules: snake_case (e.g., `table_detector.py`)
  - Classes: PascalCase (e.g., `TableDetector`)
  - Constants: UPPER_SNAKE (e.g., `MAX_RETRIES`)

### Project Structure Notes

All directories should be created even if empty to establish the expected structure for subsequent stories. Empty directories need an `__init__.py` file to be recognized as Python packages.

**Key paths from architecture.md:**
- API layer: `src/api/`
- Core config/exceptions: `src/core/`
- Database layer: `src/db/`
- Business logic (future): `src/extraction/`, `src/knowledge/`, `src/retrieval/`, `src/qa/`, `src/llm/`
- Data models (Pydantic): `src/models/`
- Background workers: `src/workers/`

### References

- [Source: docs/architecture.md#Project-Structure] - Complete directory layout
- [Source: docs/architecture.md#Technology-Stack-Details] - Version requirements
- [Source: docs/architecture.md#Development-Environment] - Setup commands
- [Source: docs/sprint-artifacts/tech-spec-epic-1.md#Dependencies-and-Integrations] - Dependency versions

## Dev Agent Record

### Context Reference

N/A - No context file generated for this story

### Agent Model Used

Claude Opus 4.5 (claude-opus-4-5-20251101)

### Debug Log References

- Fixed PostgreSQL 18 volume mount path (changed from `/var/lib/postgresql/data` to `/var/lib/postgresql` due to PG18 directory structure change)
- Removed deprecated `version: "3.8"` from docker-compose.yml

### Completion Notes List

- Created complete project scaffolding with all 25 Python files
- All dependencies installed successfully via Poetry (73 packages)
- Docker services (PostgreSQL 18, Redis 7, Milvus 1.16) all running and healthy
- Added openai and openpyxl dependencies for future epics
- Added celery dependency for background task processing

### File List

| Status | File Path |
|--------|-----------|
| NEW | pyproject.toml |
| NEW | docker-compose.yml |
| NEW | .env.example |
| NEW | .gitignore |
| NEW | README.md |
| NEW | src/__init__.py |
| NEW | src/api/__init__.py |
| NEW | src/api/main.py |
| NEW | src/api/dependencies.py |
| NEW | src/api/middleware.py |
| NEW | src/api/routes/__init__.py |
| NEW | src/api/routes/documents.py |
| NEW | src/api/routes/query.py |
| NEW | src/api/routes/health.py |
| NEW | src/core/__init__.py |
| NEW | src/core/config.py |
| NEW | src/core/exceptions.py |
| NEW | src/db/__init__.py |
| NEW | src/db/session.py |
| NEW | src/db/models.py |
| NEW | src/db/migrations/__init__.py |
| NEW | src/extraction/__init__.py |
| NEW | src/knowledge/__init__.py |
| NEW | src/retrieval/__init__.py |
| NEW | src/qa/__init__.py |
| NEW | src/llm/__init__.py |
| NEW | src/models/__init__.py |
| NEW | src/workers/__init__.py |
| NEW | tests/__init__.py |
| NEW | tests/conftest.py |
