Skip to content

Technical — API Tarantula

The main RAGA backend service, built on NestJS. It serves as the core API layer — managing workspaces, knowledge (documents, audio, database, API), chat, system prompts, user access, and orchestrating calls to external engines (chatbot, OCR, summarize, speech).

Repository

KeyValue
Git Remotehttps://git.tlab.co.id/tarantula/tarantula-v2/service/api-tarantula.git
Active Branchdev
Other Branchesmain, staging, refactor/code-integrations
bash
git clone https://git.tlab.co.id/tarantula/tarantula-v2/service/api-tarantula.git
cd api-tarantula
git checkout dev

Tech Stack

LayerTechnology
FrameworkNestJS 10 (TypeScript)
DatabasePostgreSQL 16 via TypeORM 0.3
Cache / QueueRedis 7 (ioredis + Bull)
Object StorageMinIO
Search / IndexElasticsearch 8.17
Secret ManagementInfisical SDK v4
Loggingnest-winston (Winston 3.17)
TestingJest 29 + Supertest
RuntimeNode.js (Docker)

Environment Variables

.env File (Infisical Bootstrap)

The .env file only holds bootstrap variables for authenticating to Infisical. All application secrets are fetched from Infisical at startup.

bash
INFISICAL_ENV=dev
INFISICAL_PATH=/
INFISICAL_SITE_URL=http://infisical-backend:8080
INFISICAL_CLIENT_ID=<client-id>
INFISICAL_CLIENT_SECRET=<client-secret>
INFISICAL_PROJECT_ID=<project-id>
VariableDescription
INFISICAL_ENVTarget environment in Infisical (dev / staging / prod)
INFISICAL_PATHSecret path in Infisical (default /)
INFISICAL_SITE_URLInfisical server URL (self-hosted or https://app.infisical.com)
INFISICAL_CLIENT_IDClient ID for Universal Auth
INFISICAL_CLIENT_SECRETClient Secret for Universal Auth
INFISICAL_PROJECT_IDInfisical project ID holding this service's secrets

Secrets via Infisical

All variables below are managed in Infisical and injected into process.env at runtime by InfisicalService.

Database (PostgreSQL)

VariableDescription
DB_HOSTPostgreSQL host
DB_PORTPostgreSQL port (default 5432)
DB_USERPostgreSQL username
DB_PASSWORDPostgreSQL password
DB_NAMEDatabase name

Redis

VariableDefaultDescription
REDIS_HOSTlocalhostRedis host
REDIS_PORT6379Redis port
REDIS_PASSWORDRedis password (optional)

MinIO (Object Storage)

VariableDefaultDescription
MINIO_ENDPOINTlocalhostMinIO endpoint
MINIO_PORTMinIO port (optional)
MINIO_SSLfalseUse SSL (true/false)
MINIO_ACCESS_KEYMinIO access key
MINIO_SECRET_KEYMinIO secret key
MINIO_BUCKETtarantulaDefault bucket name
MINIO_DOMAINhttps://s3.ziwardingai.xyzPublic domain used to build URLs for uploaded files (documents, chat images, etc.)

Elasticsearch

VariableDefaultDescription
ELASTICSEARCH_HOSThttp://localhost:9200Elasticsearch node URL
ELASTICSEARCH_USERNAMEElasticsearch username
ELASTICSEARCH_PASSWORDElasticsearch password
MAXIMUM_CHAT_PER_ROOM2Maximum indexed messages per room
INDEX_USER_ACTIVITY_LOGuser-activity-logElasticsearch index name activity-log writes user activity to

Chatbot Engine (opa-data / VLLM)

VariableDefaultDescription
CHATBOT_URLhttp://192.168.0.25:8034Chatbot engine base URL
MAX_CHAR_GENERATE_REPORT100000Character limit for report generation

RDBMS Engine (database-connect)

VariableDefaultDescription
DATABASE_CONNECT_URLhttp://192.168.0.25:8105Base URL of the database-connect service for external RDBMS connections & Text-to-SQL
DATABASE_CONNECT_TIMEOUT86400000Timeout (ms) for requests to database-connect

OCR / PDF Engine

VariableDefaultDescription
PDF_URLhttp://192.168.0.25:8090/api/v1Tarantula PDF/OCR service URL
ENGINE_SOURCE_LOCALtrueUse local file source for OCR

Summarize Engine

VariableDefaultDescription
SUMMARIZE_URLhttp://10.1.102.14:8014Summarize service URL
SUMMARIZE_TIMEOUT86400000Timeout (ms) for the summarize process
SUMMARIZE_ENABLE_NERtrueEnable Named Entity Recognition
SUMMARIZE_CHUNK_SIZE1000Text chunk size for summarization
SUMMARIZE_TARGET_CONTEXT128000Target LLM context window

Speaches (Speech-to-Text)

VariableDefaultDescription
SPEACHES_URLhttps://speaches.ziwardingai.xyz/v1Transcription service URL
SPEACHES_MODELturboWhisper model used
SPEACHES_DIARIZEtrueEnable speaker diarization
SPEACHES_SUPPRESS_NUMERALSfalseSuppress numerals in output

WhatsApp Integration

VariableDefaultDescription
WHATSAPP_URLhttp://192.168.0.27:18004WhatsApp Go service URL
WHATSAPP_TIMEOUT86400000WhatsApp connection timeout (ms)

License Validation

VariableDefaultDescription
LICENSE_API_URLhttp://10.1.102.15:8003License validation service URL
LICENSE_API_EMAILadmin@mail.comBasic Auth email for the license service
LICENSE_API_PASSWORD123456Basic Auth password for the license service

Folder Structure

api-tarantula/
├── src/
│   ├── app.module.ts               # Root module, bootstraps all modules
│   ├── main.ts                     # NestJS entry point
│   │
│   ├── common/                     # Shared utilities, config, integrations
│   │   ├── config/                 # Config class per external service
│   │   │   ├── chatbot.config.ts
│   │   │   ├── elasticsearch.config.ts
│   │   │   ├── minio.config.ts
│   │   │   ├── pdf-tarantula.config.ts
│   │   │   ├── rdbms.config.ts
│   │   │   ├── redis.config.ts
│   │   │   ├── speaches.config.ts
│   │   │   ├── summarize.config.ts
│   │   │   ├── typeorm.config.ts
│   │   │   └── whatsapp-go.config.ts
│   │   ├── decorator/               # Custom decorators
│   │   ├── dto/                     # Shared DTOs (PaginationDto, ParamDto)
│   │   ├── exception/                # Custom exceptions
│   │   ├── filter/                   # Global exception filter
│   │   ├── helper/                   # PDF helper, safe JSON parse
│   │   ├── integrations/             # HTTP client per external service
│   │   │   ├── chatbot/
│   │   │   ├── elasticsearch/
│   │   │   ├── minio/
│   │   │   ├── pdf-tarantula/
│   │   │   ├── rdbms/
│   │   │   ├── redis/
│   │   │   ├── speaches/
│   │   │   ├── summarize/
│   │   │   └── whatsapp-go/
│   │   ├── interceptor/              # Response interceptor (standard format)
│   │   ├── logger/                   # Telegram transport for Winston
│   │   ├── middleware/                # API key middleware, dynamic CSP
│   │   └── services/
│   │       └── document/              # Document chunk service
│   │
│   ├── db/
│   │   ├── migrations/               # TypeORM migrations (70+ files)
│   │   └── seeds/                     # Data seeder
│   │
│   ├── infisical/                    # Infisical secret loader & service
│   │
│   ├── activity-log/                 # User activity logging
│   ├── apis/                         # External API management within a workspace
│   ├── api-users/                    # ACL: user access to an API
│   ├── audio-document-chunks/        # Audio transcription chunks
│   ├── audio-document-summaries/     # Audio document summaries
│   ├── audio-document-users/         # ACL: user access to an audio document
│   ├── audio-documents/              # Audio transcription result documents
│   ├── audio-users/                  # ACL: user access to audio
│   ├── audios/                       # Audio file management
│   ├── canvas/                       # Endpoint for testing knowledge & LLM combinations
│   ├── chat-histories/               # Chat history per room
│   ├── dashboard/                    # Dashboard summary data
│   ├── database-users/               # ACL: user access to a database
│   ├── databases/                    # External database (RDBMS) connections
│   ├── document-folder/              # Document folder management
│   ├── document-folder-users/        # ACL: user access to a folder
│   ├── document-ocr/                 # Per-document OCR results
│   ├── document-summaries/           # Document summaries
│   ├── document-users/               # ACL: user access to a document
│   ├── documents/                    # Document management (upload, metadata)
│   ├── endpoints/                    # Endpoints of an external API
│   ├── health/                       # Health check endpoint
│   ├── log/                          # HTTP request logging middleware
│   ├── mail/                         # Email service (Bull queue + templates)
│   ├── model-management/             # LLM model management per workspace
│   ├── open-api/                     # Public API surface (app_key)
│   ├── openai-compat/                # OpenAI-compatible chat completion endpoint
│   ├── room-chats/                   # Room chat management
│   ├── settings/                     # Global application settings
│   ├── shared/                       # Shared service (JWT, auth helper)
│   ├── system-prompt/                # Workspace system prompt management
│   ├── system-prompt-users/          # ACL: user access to a system prompt
│   ├── topic-document-users/         # ACL: user access to a topic document
│   ├── topic-documents/              # Topic ↔ document relation
│   ├── topic-users/                  # ACL: user access to a topic
│   ├── topics/                       # Knowledge topic management
│   ├── utils/                        # Misc utility endpoints
│   ├── whatsapp/                     # WhatsApp integration
│   ├── workspace-iframes/            # Workspace iframe embed configuration
│   ├── workspace-integrations/       # External integrations per workspace
│   ├── workspace-roles/              # Role management within a workspace
│   ├── workspace-users/              # Workspace user membership
│   └── workspaces/                   # Workspace management (core entity)

├── test/                             # E2E tests
├── scripts/                          # Infisical CLI helper script
├── docker-compose.dev.yml            # Docker for local development
├── docker-compose.yml                # Docker for production/staging
├── Dockerfile.dev                    # Development image
├── Dockerfile                        # Production image
├── Dockerfile.stag                   # Staging image
├── nest-cli.json
├── tsconfig.json
└── package.json

Module Architecture

Core domains are grouped into NestJS modules following a controller → service → entity pattern:

  • Workspace Coreworkspaces, workspace-users, workspace-roles, workspace-integrations, workspace-iframes
  • Knowledge: Documentsdocuments, document-ocr, document-folder, document-summaries, topics, topic-documents
  • Knowledge: Audioaudios, audio-documents, audio-document-chunks, audio-document-summaries
  • Knowledge: Database & APIdatabases, apis, endpoints
  • Chat & Intelligenceroom-chats, chat-histories, system-prompt, model-management, canvas, openai-compat
  • Auth & Accessshared (JWT), open-api, activity-log
  • Supportmail, health, settings, dashboard, whatsapp, infisical

Every knowledge source also has a matching *-users module (document-users, audio-users, topic-users, database-users, api-users, etc.) for per-resource access control — see Architecture Overview.

Key Modules

ModuleResponsibility
workspacesRAGA's core entity; configures LLM, chain mode, streaming, personalization, and relations to all knowledge sources
documentsUpload, metadata, OCR status, progress tracking for PDF/file documents
document-ocrStores OCR results per chunk; relates to the PDF Tarantula service
audiosAudio file upload; triggers transcription to the Speaches service
audio-documentsPer-segment transcription results; is_publish_transcribe status
topicsGroups documents into a knowledge topic within a workspace
databasesExternal RDBMS (PostgreSQL/MySQL) connections for Text-to-SQL
apisExternal API definitions callable by the chatbot (Text-to-API)
system-promptWorkspace system prompt templates; supports report and persistent prompt types
model-managementLLM model configuration available per workspace (QWEN, GLM, etc.)
chat-historiesStores conversation history per room; used as context by the engine
openai-compatOpenAI-compatible endpoints (POST /open-api/chat/completions, GET /open-api/models) for third-party integration — not under /v1/..., but sharing the open-api namespace
infisicalInfisical secret loader; initializes process.env before other modules run
activity-logInterceptor + decorator that logs every user action to an Elasticsearch index (INDEX_USER_ACTIVITY_LOG), not a database table

Infrastructure (Development)

Run via docker-compose.dev.yml:

bash
docker compose -f docker-compose.dev.yml up -d
ContainerImagePortDescription
api-jabarinDockerfile.dev (NestJS)3000Application with hot-reload
db-api-jabarinpostgres:16-alpine5432PostgreSQL
cached-api-jabarinredis:7.4.5-alpine3.216379Redis for cache & Bull queue
minio-jabarinquay.io/minio/minio9000 (API), 9001 (Console)Object storage for file uploads
es-jabarinelasticsearch-wolfi:8.17.09200, 9300Single-node Elasticsearch for indexing

All containers share the network-jabarin network.

External Integrations

ServiceEnv VarDescription
Chatbot Engine (opa-data)CHATBOT_URLRAGA chatbot engine; called for LLM inference
PDF Tarantula (OCR)PDF_URLDocument OCR service; accepts PDF files and returns text per chunk
Speaches (STT)SPEACHES_URLWhisper-based speech-to-text; used for audio transcription
Summarize EngineSUMMARIZE_URLSummarize + NER service for documents and audio
WhatsApp GoWHATSAPP_URLWhatsApp bridge for chatbot integration via WA
InfisicalINFISICAL_SITE_URLSecret management; all sensitive env vars are pulled from here

Development Commands

bash
# Install dependencies
npm install

# Run development (hot-reload)
npm run start:dev

# Build production
npm run build

# Run migrations
npm run migration:run

# Create a new migration
npm run migration:create --name=MigrationName

# Rollback migration
npm run migration:revert

# Run tests
npm run test

# Run tests + coverage
npm run test:cov

# Sync new secrets to Infisical
npm run sync:infisical