# Services Directory

**Last Updated**: 2025-01-27  
**Purpose**: Backend microservices overview

## Overview

This directory contains all backend microservices for The Order platform. Each service is a self-contained, independently deployable unit following microservices architecture principles.

## Available Services

### Identity Service (`identity/`)
- **Purpose**: Digital identity, verifiable credentials, Entra VerifiedID
- **Port**: 4002
- **Features**: eIDAS/DID, credential issuance, identity verification
- **Documentation**: [Identity Service README](identity/README.md)

### Intake Service (`intake/`)
- **Purpose**: Document ingestion, OCR, classification
- **Port**: 4001
- **Features**: Document upload, OCR processing, classification, routing
- **Documentation**: [Intake Service README](intake/README.md)

### Finance Service (`finance/`)
- **Purpose**: Payments, ledgers, invoicing
- **Port**: 4003
- **Features**: Payment processing, ledger management, invoicing
- **Documentation**: [Finance Service README](finance/README.md)

### Dataroom Service (`dataroom/`)
- **Purpose**: Virtual data rooms, deal management
- **Port**: 4004
- **Features**: Secure VDR, deal rooms, document access control
- **Documentation**: [Dataroom Service README](dataroom/README.md)

### Legal Documents Service (`legal-documents/`)
- **Purpose**: Comprehensive document management
- **Port**: 4005
- **Features**: Templates, versioning, matter management, court filing, collaboration
- **Documentation**: [Legal Documents Service README](legal-documents/README.md)

### e-Residency Service (`eresidency/`)
- **Purpose**: Digital residency services
- **Port**: 4006
- **Features**: e-Residency management
- **Documentation**: [e-Residency Service README](eresidency/README.md)

## Service Architecture

All services follow a consistent architecture:

```
service/
├── src/
│   ├── index.ts              # Entry point
│   ├── routes/               # API routes
│   ├── services/             # Business logic
│   └── types/                # TypeScript types
├── tests/                    # Test files
├── k8s/                      # Kubernetes manifests
├── Dockerfile                # Container definition
├── package.json              # Dependencies
└── README.md                 # Service documentation
```

## Common Patterns

### Health Checks
All services expose `/health` endpoint:
```bash
curl http://localhost:4002/health
```

### API Documentation
All services provide Swagger/OpenAPI docs:
```bash
# Access at /docs endpoint
http://localhost:4002/docs
```

### Metrics
All services expose Prometheus metrics:
```bash
# Access at /metrics endpoint
http://localhost:4002/metrics
```

## Development

### Running Services Locally

```bash
# Start all services
pnpm dev

# Start specific service
pnpm --filter @the-order/identity-service dev
```

### Building Services

```bash
# Build all services
pnpm build

# Build specific service
pnpm --filter @the-order/identity-service build
```

### Testing Services

```bash
# Test all services
pnpm test

# Test specific service
pnpm --filter @the-order/identity-service test
```

## Deployment

### Kubernetes

Each service has Kubernetes manifests in `services/{service}/k8s/`:
```bash
kubectl apply -f services/identity/k8s/deployment.yaml
```

### Docker

Each service has a Dockerfile:
```bash
docker build -t theorder/identity-service:latest -f services/identity/Dockerfile .
```

## Service Communication

Services communicate via:
- **HTTP/REST**: Synchronous communication
- **Message Queue**: Asynchronous communication (planned)
- **Shared Database**: Common data access
- **Event Bus**: Event-driven architecture (planned)

## Related Documentation

- [Architecture Documentation](../docs/architecture/)
- [Deployment Guides](../docs/deployment/)
- [Infrastructure Documentation](../infra/)

---

**Last Updated**: 2025-01-27

