# Legal Documents Service

Comprehensive document management service for law firms and courts.

## Features

- **Document Management**: Full CRUD operations with versioning
- **Template System**: Template-based document generation
- **Legal Matters**: Matter management and document linking
- **Document Assembly**: Multi-clause document assembly
- **Collaboration**: Comments, annotations, and review workflows
- **Workflows**: Approval, signing, and filing workflows
- **Court Filings**: E-filing and deadline tracking
- **Audit Trail**: Comprehensive audit logging
- **Search**: Full-text search and discovery
- **Security**: Watermarking, encryption, access control
- **Retention**: Retention policies and disposal workflows
- **Clause Library**: Reusable clause management

## API Endpoints

### Documents
- `POST /documents` - Create document
- `GET /documents/:id` - Get document
- `GET /documents` - List documents
- `PATCH /documents/:id` - Update document
- `POST /documents/:id/checkout` - Checkout document
- `POST /documents/:id/checkin` - Checkin document

### Versions
- `GET /documents/:id/versions` - List versions
- `GET /documents/:id/versions/:version` - Get version
- `GET /documents/:id/versions/latest` - Get latest version
- `GET /documents/:id/versions/history` - Get version history
- `GET /documents/:id/versions/:v1/compare/:v2` - Compare versions
- `POST /documents/:id/versions/:version/restore` - Restore version

### Templates
- `POST /templates` - Create template
- `GET /templates/:id` - Get template
- `GET /templates` - List templates
- `PATCH /templates/:id` - Update template
- `POST /templates/:id/version` - Create template version
- `POST /templates/:id/render` - Render template
- `GET /templates/:id/variables` - Extract variables

### Matters
- `POST /matters` - Create matter
- `GET /matters/:id` - Get matter
- `GET /matters` - List matters
- `PATCH /matters/:id` - Update matter
- `POST /matters/:id/participants` - Add participant
- `GET /matters/:id/participants` - Get participants
- `POST /matters/:matter_id/documents/:document_id` - Link document
- `GET /matters/:id/documents` - Get matter documents

### Assembly
- `POST /assembly/generate` - Generate from template
- `POST /assembly/preview` - Preview template rendering
- `POST /assembly/from-clauses` - Assemble from clauses

### Collaboration
- `POST /documents/:id/comments` - Create comment
- `GET /documents/:id/comments` - Get comments
- `PATCH /comments/:id` - Update comment
- `POST /comments/:id/resolve` - Resolve comment

### Workflows
- `POST /workflows` - Create workflow
- `GET /workflows/:id` - Get workflow
- `GET /documents/:id/workflows` - Get document workflows
- `PATCH /workflows/:id/status` - Update workflow status

### Filings
- `POST /filings` - Create filing
- `GET /filings/:id` - Get filing
- `GET /filings` - List filings
- `GET /matters/:id/filing-deadlines` - Get deadlines

### Audit
- `GET /documents/:id/audit` - Get audit logs
- `GET /audit/search` - Search audit logs
- `GET /audit/statistics` - Get statistics

### Search
- `POST /search` - Search documents
- `GET /search/suggestions` - Get search suggestions

### Retention
- `POST /retention/policies` - Create policy
- `GET /retention/policies` - List policies
- `POST /documents/:id/retention` - Apply policy
- `GET /documents/:id/retention` - Get retention record
- `GET /retention/expired` - Get expired records
- `POST /documents/:id/dispose` - Dispose document
- `GET /retention/statistics` - Get statistics

### Clauses
- `POST /clauses` - Create clause
- `GET /clauses/:id` - Get clause
- `GET /clauses` - List clauses
- `POST /clauses/:id/render` - Render clause

## Development

```bash
# Install dependencies
pnpm install

# Run development server
pnpm dev

# Build
pnpm build

# Start production server
pnpm start

# Run tests
pnpm test
```

## Environment Variables

- `PORT` - Server port (default: 4005)
- `DATABASE_URL` - PostgreSQL connection string
- `NODE_ENV` - Environment (development/production)
- `SWAGGER_SERVER_URL` - Swagger server URL

## API Documentation

Swagger documentation available at `/docs` when running.

