documentation

This commit is contained in:
2026-10-20 10:52:26 +03:30
parent 9ee9081b11
commit 3ad66aa4dc
3 changed files with 124 additions and 18 deletions
+29 -15
View File
@@ -1,6 +1,6 @@
# Inquiry Gateway
Production-grade **NestJS + MongoDB** unified inquiry gateway for external service providers.
Production-grade **NestJS + PostgreSQL** unified inquiry gateway for external service providers.
## 📚 Documentation
@@ -18,7 +18,7 @@ Client → POST /inquiries/person (unified)
→ ProviderFactory → Hamta | Moallem | TejaratNou
→ LegacyApiProvider (shared base for identical APIs)
→ BaseProvider (retry, timeout, logging, error normalization)
→ MongoDB inquiry_logs
→ PostgreSQL inquiry logs
```
### Provider vs Authentication Service
@@ -50,9 +50,9 @@ src/
├── users/ # Unified users (ADMIN / USER / SUPER_ADMIN)
├── audit/ # Security audit logs
├── rate-limit/ # Global + per-user throttling
├── logging/ # MongoDB inquiry audit logs
├── health/ # Liveness and MongoDB readiness probes
├── idempotency/ # Mongo-backed idempotency keys for inquiry retries
├── logging/ # PostgreSQL inquiry audit logs
├── health/ # Liveness, readiness, and admin inquiry diagnostics
├── idempotency/ # Database-backed idempotency keys for inquiry retries
├── providers/ # BaseProvider, LegacyApiProvider, factory, orchestrator
└── inquiry/ # Unified controllers & services
```
@@ -60,8 +60,8 @@ src/
## Quick start
```bash
cp .env.example .env
# Edit .env with your provider credentials (see Environment Configuration Guide)
cp .env.example .local.env
# Edit .local.env with your provider credentials (see Environment Configuration Guide)
npm install
npm run cli:create-super-admin # interactive — creates SUPER_ADMIN
npm run start:dev
@@ -70,8 +70,9 @@ npm run start:dev
- API: `http://localhost:8085`
- Operations dashboard: `http://localhost:8085/dashboard/` (SUPER_ADMIN only)
- Swagger: `http://localhost:8085/api/docs`
- Liveness: `GET /health/live` (process-level probe; no MongoDB dependency)
- Readiness: `GET /health/ready` (MongoDB, heap, and disk checks; returns `503` when a dependency is unavailable)
- Liveness: `GET /health/live` (process-level probe; no database dependency)
- Readiness: `GET /health/ready` (PostgreSQL, heap, and disk checks; returns `503` when a dependency is unavailable)
- Admin inquiry diagnostics: `POST /health/inquiries/check` for one live provider check; `POST /health/inquiries/check/batch` starts 1–50 sequential checks and `GET /health/inquiries/check/batch/:jobId` returns progress and results. These endpoints require an ADMIN or SUPER_ADMIN JWT. Batch jobs run in memory, only one can run at a time, and completed reports expire after one hour.
The dashboard is served by the same process and uses the existing JWT login flow. It does not expose a second credential store: only a user whose profile role is `SUPER_ADMIN` can enter it, and the inquiry-log/metrics endpoints enforce that role server-side as well. It provides readiness details, recent audit logs, metrics, manual inquiry execution, and formatted JSON/XML output. Metrics separate valid provider no-match results from operational failures: success rate is calculated over evaluated requests (successes plus operational failures), while no-match results remain visible as their own count. Dashboard panels can be collapsed independently, with their open/closed state remembered in the browser. Typed inquiry routes render field-based forms with examples matching their Swagger DTO definitions; legal-person remains an advanced JSON payload because its controller accepts a provider-specific object.
@@ -178,7 +179,7 @@ See [API Documentation](docs/API_DOCUMENTATION.md) for detailed request/response
## Token management
- **Token refresh**: Every 20 minutes automatically
- **Distributed refresh lock**: MongoDB lease lock prevents concurrent replicas from refreshing the same token
- **Distributed refresh lock**: PostgreSQL lease lock prevents concurrent replicas from refreshing the same token
- **Token expiration**: Daily at 23:59:59 Tehran time
- **Retry logic**: Automatic retry on transient network failures and HTTP 404/408/499/5xx responses (legacy gateways can return 404 transiently); exhausted attempts retain the provider HTTP/SOAP code for diagnosis
- **Error handling**: Graceful fallback to alternative providers
@@ -197,7 +198,7 @@ See [API Documentation](docs/API_DOCUMENTATION.md) for detailed request/response
2. Create request/response DTOs with `class-validator` in `src/inquiry/dto/`
3. Add `POST /inquiries/<type>` in `InquiryController`
4. Implement service method using `ProviderOrchestratorService`
5. Configure routing and credentials in `.env`
5. Configure routing and credentials in `.local.env`
## Security
@@ -206,7 +207,7 @@ See [API Documentation](docs/API_DOCUMENTATION.md) for detailed request/response
- **Inquiry access**: `allowedInquiries` + `InquiryAccessGuard` (e.g. `PERSON_INQUIRY`)
- **Rate limiting**: global throttler + per-user `requestLimitPerMinute` / `requestLimitPerDay`
- **Audit**: `audit_logs` for login, user lifecycle events
- **Request logging**: All inquiries logged to MongoDB with masked sensitive data
- **Request logging**: All inquiries logged to PostgreSQL with masked sensitive data
## Error handling
@@ -223,7 +224,7 @@ The system provides comprehensive error handling:
## Monitoring & observability
- **OpenTelemetry**: Distributed tracing support
- **Inquiry logs**: MongoDB collection with full request/response audit trail
- **Inquiry logs**: PostgreSQL tables with full request/response audit trail
- **Audit logs**: Security events and user actions
- **Performance metrics**: Request duration, provider response times
- **Error tracking**: Normalized error codes and messages
@@ -252,7 +253,20 @@ npm run format
## Environment variables
Key environment variables (see `.env.example` for complete list):
All local settings live in `.local.env`, grouped into shared application settings,
routing, AMITIS authentication, and one section per client. Copy `.env.example`
to `.local.env` for a new checkout and fill in the credentials.
The app, telemetry, admin CLI, and migration CLI load `.local.env` automatically
from the project root. Shell/container variables take priority, followed by
`.local.env`, then `.env` as a legacy fallback. The split `env/*.env` files and
the differently named `.env.local` are inactive. Restart after editing settings.
Docker Compose continues to inject settings from the single `.production.env`
file; it no longer mounts the split `env/` directory. Keep real environment files
out of Git and Docker images.
Key environment variables:
```env
# Application
@@ -261,7 +275,7 @@ PORT=8085
API_PREFIX=api
# Database
MONGODB_URI=mongodb://localhost:27017/inquiry-gateway
DATABASE_URL=postgresql://esg:esg@localhost:5432/inquiry_gateway
# JWT
JWT_SECRET=your-secret-key