2.1 KiB
2.1 KiB
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
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
Create a
.envfile in the backend directory with the following variables:
SECRET_KEY=your-secret-key-here
The database (SQLite) will be automatically created when you first run the application.
- Start Redis (required for Celery):
redis-server
- Start Celery worker:
celery -A app.services.file_service worker --loglevel=info
- Start the FastAPI server:
uvicorn app.main:app --reload
Option 2: Docker Deployment
- Build and start the services:
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 fileGET /api/v1/files- List all filesGET /api/v1/files/{file_id}- Get file detailsGET /api/v1/files/{file_id}/download- Download processed fileWS /api/v1/files/ws/status/{file_id}- WebSocket for real-time status updates
Development
Running Tests
pytest
Code Style
The project uses Black for code formatting:
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