# Legal Document Masker API This is the backend API for the Legal Document Masking system. It provides endpoints for file upload, processing status tracking, and file download. ## Prerequisites - Python 3.8+ - Redis (for Celery) ## File Storage Files are stored in the following structure: ``` backend/ ├── storage/ │ ├── uploads/ # Original uploaded files │ └── processed/ # Masked/processed files ``` ## Setup ### Option 1: Local Development 1. Create a virtual environment: ```bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` 2. Install dependencies: ```bash pip install -r requirements.txt ``` 3. Set up environment variables: Create a `.env` file in the backend directory with the following variables: ```env SECRET_KEY=your-secret-key-here ``` The database (SQLite) will be automatically created when you first run the application. 4. Start Redis (required for Celery): ```bash redis-server ``` 5. Start Celery worker: ```bash celery -A app.services.file_service worker --loglevel=info ``` 6. Start the FastAPI server: ```bash uvicorn app.main:app --reload ``` ### Option 2: Docker Deployment 1. Build and start the services: ```bash docker-compose up --build ``` This will start: - FastAPI server on port 8000 - Celery worker for background processing - Redis for task queue ## API Documentation Once the server is running, you can access: - Swagger UI: `http://localhost:8000/docs` - ReDoc: `http://localhost:8000/redoc` ## API Endpoints - `POST /api/v1/files/upload` - Upload a new file - `GET /api/v1/files` - List all files - `GET /api/v1/files/{file_id}` - Get file details - `GET /api/v1/files/{file_id}/download` - Download processed file - `WS /api/v1/files/ws/status/{file_id}` - WebSocket for real-time status updates ## Development ### Running Tests ```bash pytest ``` ### Code Style The project uses Black for code formatting: ```bash black . ``` ### Docker Commands - Start services: `docker-compose up` - Start in background: `docker-compose up -d` - Stop services: `docker-compose down` - View logs: `docker-compose logs -f` - Rebuild: `docker-compose up --build`