# abhi-7-github/shiprule architecture

> Architecture diagram of the GitHub repository abhi-7-github/shiprule, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhi-7-github/shiprule
- Repository: https://github.com/abhi-7-github/shiprule

## Overview

ShipRule is a customs-duty and shipping-document lookup platform. Users ask compliance questions and receive grounded answers with citations; administrators and users also manage accounts, while users upload documents for indexing. The backend separates API routing, document preparation, RAG retrieval and answer generation, and persistence. The README documents the upload capabilities and frontend/API boundary; several frontend and backend modules are listed but not excerpted, so their internal wiring is not inferred.

Main entry points: [`server/app/rag/pipeline.py`](https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/pipeline.py) (RAG orchestrator), [`server/main.py`](https://github.com/abhi-7-github/shiprule/blob/main/server/main.py) (FastAPI application), [`server/app/api/routes/documents.py`](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/documents.py) (Document endpoints), [`server/app/api/routes/query.py`](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/query.py) (Query endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_web["ShipRule interface"]
  node_query_ui["Query interface<br/>[QueryInterface.tsx]"]
  node_doc_ui["Document manager"]
  node_api_client["API service client<br/>[api.ts]"]
end

subgraph group_api["API and identity"]
  node_server["FastAPI application<br/>[main.py]"]
  node_query_route["Query endpoint<br/>[query.py]"]
  node_document_route["Document endpoints<br/>[documents.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_admin_routes["Admin routes<br/>[admin.py]"]
  node_auth_deps["JWT and role checks<br/>[dependencies.py]"]
end

subgraph group_documents["Document indexing"]
  node_ingestion["Document ingestion<br/>[ingestion.py]"]
  node_loader["Document loading<br/>[loader.py]"]
  node_cleaner["Text cleaning<br/>[cleaner.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_embeddings["Embedding generation<br/>[embeddings.py]"]
end

subgraph group_rag["Grounded answers"]
  node_pipeline["RAG orchestrator<br/>[pipeline.py]"]
  node_retrieval["Hybrid retrieval<br/>[retrieval.py]"]
  node_indexing["Vector indexing<br/>[indexing.py]"]
  node_reranker["Cross-encoder reranking<br/>[reranker.py]"]
  node_guardrails["Retrieval safeguards<br/>[retrieval.py]"]
  node_scope_guard["Scope safeguards<br/>[scope.py]"]
  node_security_guard["Security safeguards<br/>[security.py]"]
  node_validation["Answer and citation checks"]
  node_llm["Groq completion<br/>[groq.py]"]
  node_prompts["Prompt templates"]
end

subgraph group_state["Persistence and operations"]
  node_mongo[("MongoDB user and activity data<br/>[mongodb.py]")]
  node_config["Service configuration<br/>[config.py]"]
end

node_user(("Platform user"))
node_admin(("Administrator"))

node_user -->|"uses"| node_web
node_web -.-> node_query_ui
node_web -.-> node_doc_ui
node_query_ui -.->|"submits queries"| node_api_client
node_doc_ui -.->|"manages documents"| node_api_client
node_api_client -->|"calls API"| node_server
node_server -->|"registers"| node_query_route
node_server -->|"registers"| node_document_route
node_server -->|"registers"| node_auth_routes
node_server -->|"registers"| node_admin_routes
node_query_route -->|"calls"| node_pipeline
node_query_route -->|"decodes token"| node_auth_deps
node_query_route -->|"records activity"| node_mongo
node_document_route -->|"loads files"| node_loader
node_document_route -->|"cleans text"| node_cleaner
node_document_route -->|"embeds documents"| node_embeddings
node_document_route -.->|"prepares corpus"| node_ingestion
node_ingestion -->|"loads documents"| node_loader
node_ingestion -->|"cleans text"| node_cleaner
node_ingestion -->|"creates chunks"| node_chunker
node_pipeline -->|"retrieves candidates"| node_retrieval
node_pipeline -->|"reranks candidates"| node_reranker
node_pipeline -->|"checks retrieval"| node_guardrails
node_pipeline -->|"checks scope"| node_scope_guard
node_pipeline -->|"checks security"| node_security_guard
node_pipeline -->|"validates answer"| node_validation
node_pipeline -->|"requests completion"| node_llm
node_pipeline -->|"uses templates"| node_prompts
node_retrieval -->|"embeds query"| node_embeddings
node_retrieval -->|"loads indexed collection"| node_indexing
node_reranker -->|"uses retrieval"| node_retrieval
node_reranker -->|"uses index"| node_indexing
node_auth_routes -->|"manages users"| node_mongo
node_admin_routes -->|"reads administration data"| node_mongo
node_admin_routes -->|"requires admin"| node_auth_deps
node_admin -.->|"manages platform"| node_web
node_auth_routes -.->|"issues tokens"| node_auth_deps
node_server -->|"configures service"| node_config

click node_web "https://github.com/abhi-7-github/shiprule/tree/main/client/src/app"
click node_query_ui "https://github.com/abhi-7-github/shiprule/blob/main/client/src/components/chat/QueryInterface.tsx"
click node_doc_ui "https://github.com/abhi-7-github/shiprule/blob/main/client/src/components/documents/DocumentManager.tsx"
click node_api_client "https://github.com/abhi-7-github/shiprule/blob/main/client/src/services/api.ts"
click node_server "https://github.com/abhi-7-github/shiprule/blob/main/server/main.py"
click node_query_route "https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/query.py"
click node_document_route "https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/documents.py"
click node_auth_routes "https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/auth.py"
click node_admin_routes "https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/admin.py"
click node_auth_deps "https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/dependencies.py"
click node_ingestion "https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/ingestion.py"
click node_loader "https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/loader.py"
click node_cleaner "https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/cleaner.py"
click node_chunker "https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/chunker.py"
click node_embeddings "https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/embeddings.py"
click node_pipeline "https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/pipeline.py"
click node_retrieval "https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/retrieval.py"
click node_indexing "https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/indexing.py"
click node_reranker "https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/reranker.py"
click node_guardrails "https://github.com/abhi-7-github/shiprule/blob/main/server/app/guardrails/retrieval.py"
click node_scope_guard "https://github.com/abhi-7-github/shiprule/blob/main/server/app/guardrails/scope.py"
click node_security_guard "https://github.com/abhi-7-github/shiprule/blob/main/server/app/guardrails/security.py"
click node_validation "https://github.com/abhi-7-github/shiprule/tree/main/server/app/validation"
click node_llm "https://github.com/abhi-7-github/shiprule/blob/main/server/app/llm/groq.py"
click node_prompts "https://github.com/abhi-7-github/shiprule/blob/main/server/app/prompts/prompt_templates.py"
click node_mongo "https://github.com/abhi-7-github/shiprule/blob/main/server/app/db/mongodb.py"
click node_config "https://github.com/abhi-7-github/shiprule/blob/main/server/app/core/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_query_ui,node_doc_ui,node_api_client,node_user toneBlue
class node_server,node_query_route,node_document_route,node_auth_routes,node_admin_routes,node_auth_deps toneAmber
class node_ingestion,node_loader,node_cleaner,node_chunker,node_embeddings toneMint
class node_pipeline,node_retrieval,node_indexing,node_reranker,node_guardrails,node_scope_guard,node_security_guard,node_validation,node_llm,node_prompts toneRose
class node_mongo,node_config,node_admin toneIndigo
```

## Components

### Web client

- [ShipRule interface](https://github.com/abhi-7-github/shiprule/tree/main/client/src/app): `client/src/app`
- [Query interface](https://github.com/abhi-7-github/shiprule/blob/main/client/src/components/chat/QueryInterface.tsx): `client/src/components/chat/QueryInterface.tsx`
- [Document manager](https://github.com/abhi-7-github/shiprule/blob/main/client/src/components/documents/DocumentManager.tsx): `client/src/components/documents/DocumentManager.tsx`
- [API service client](https://github.com/abhi-7-github/shiprule/blob/main/client/src/services/api.ts): `client/src/services/api.ts`

### API and identity

- [FastAPI application](https://github.com/abhi-7-github/shiprule/blob/main/server/main.py): `server/main.py`
- [Query endpoint](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/query.py): `server/app/api/routes/query.py`
- [Document endpoints](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/documents.py): `server/app/api/routes/documents.py`
- [Authentication routes](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/auth.py): `server/app/api/routes/auth.py`
- [Admin routes](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/routes/admin.py): `server/app/api/routes/admin.py`
- [JWT and role checks](https://github.com/abhi-7-github/shiprule/blob/main/server/app/api/dependencies.py): `server/app/api/dependencies.py`

### Document indexing

- [Document ingestion](https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/ingestion.py): `server/app/documents/ingestion.py`
- [Document loading](https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/loader.py): `server/app/documents/loader.py`
- [Text cleaning](https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/cleaner.py): `server/app/documents/cleaner.py`
- [Text chunking](https://github.com/abhi-7-github/shiprule/blob/main/server/app/documents/chunker.py): `server/app/documents/chunker.py`
- [Embedding generation](https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/embeddings.py): `server/app/rag/embeddings.py`

### Grounded answers

- [RAG orchestrator](https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/pipeline.py): `server/app/rag/pipeline.py`
- [Hybrid retrieval](https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/retrieval.py): `server/app/rag/retrieval.py`
- [Vector indexing](https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/indexing.py): `server/app/rag/indexing.py`
- [Cross-encoder reranking](https://github.com/abhi-7-github/shiprule/blob/main/server/app/rag/reranker.py): `server/app/rag/reranker.py`
- [Retrieval safeguards](https://github.com/abhi-7-github/shiprule/blob/main/server/app/guardrails/retrieval.py): `server/app/guardrails/retrieval.py`
- [Scope safeguards](https://github.com/abhi-7-github/shiprule/blob/main/server/app/guardrails/scope.py): `server/app/guardrails/scope.py`
- [Security safeguards](https://github.com/abhi-7-github/shiprule/blob/main/server/app/guardrails/security.py): `server/app/guardrails/security.py`
- [Answer and citation checks](https://github.com/abhi-7-github/shiprule/tree/main/server/app/validation): `server/app/validation`
- [Groq completion](https://github.com/abhi-7-github/shiprule/blob/main/server/app/llm/groq.py): `server/app/llm/groq.py`
- [Prompt templates](https://github.com/abhi-7-github/shiprule/blob/main/server/app/prompts/prompt_templates.py): `server/app/prompts/prompt_templates.py`

### Persistence and operations

- [MongoDB user and activity data](https://github.com/abhi-7-github/shiprule/blob/main/server/app/db/mongodb.py): `server/app/db/mongodb.py`
- [Service configuration](https://github.com/abhi-7-github/shiprule/blob/main/server/app/core/config.py): `server/app/core/config.py`

### Other components

- **Platform user**
- **Administrator**

## Connections

- Platform user → ShipRule interface: uses (evidence: `README.md`)
- ShipRule interface → Query interface
- ShipRule interface → Document manager
- Query interface → API service client: submits queries
- Document manager → API service client: manages documents
- API service client → FastAPI application: calls API (evidence: `README.md`)
- FastAPI application → Query endpoint: registers (evidence: `server/main.py`)
- FastAPI application → Document endpoints: registers (evidence: `server/main.py`)
- FastAPI application → Authentication routes: registers (evidence: `server/main.py`)
- FastAPI application → Admin routes: registers (evidence: `server/main.py`)
- Query endpoint → RAG orchestrator: calls (evidence: `server/app/api/routes/query.py`)
- Query endpoint → JWT and role checks: decodes token (evidence: `server/app/api/routes/query.py`)
- Query endpoint → MongoDB user and activity data: records activity (evidence: `server/app/api/routes/query.py`)
- Document endpoints → Document loading: loads files (evidence: `server/app/api/routes/documents.py`)
- Document endpoints → Text cleaning: cleans text (evidence: `server/app/api/routes/documents.py`)
- Document endpoints → Embedding generation: embeds documents (evidence: `server/app/api/routes/documents.py`)
- Document endpoints → Document ingestion: prepares corpus
- Document ingestion → Document loading: loads documents (evidence: `server/app/documents/ingestion.py`)
- Document ingestion → Text cleaning: cleans text (evidence: `server/app/documents/ingestion.py`)
- Document ingestion → Text chunking: creates chunks (evidence: `server/app/documents/ingestion.py`)
- RAG orchestrator → Hybrid retrieval: retrieves candidates (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Cross-encoder reranking: reranks candidates (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Retrieval safeguards: checks retrieval (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Scope safeguards: checks scope (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Security safeguards: checks security (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Answer and citation checks: validates answer (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Groq completion: requests completion (evidence: `server/app/rag/pipeline.py`)
- RAG orchestrator → Prompt templates: uses templates (evidence: `server/app/rag/pipeline.py`)
- Hybrid retrieval → Embedding generation: embeds query (evidence: `server/app/rag/retrieval.py`)
- Hybrid retrieval → Vector indexing: loads indexed collection (evidence: `server/app/rag/retrieval.py`)
- Cross-encoder reranking → Hybrid retrieval: uses retrieval (evidence: `server/app/rag/reranker.py`)
- Cross-encoder reranking → Vector indexing: uses index (evidence: `server/app/rag/reranker.py`)
- Authentication routes → MongoDB user and activity data: manages users (evidence: `server/app/api/routes/auth.py`)
- Admin routes → MongoDB user and activity data: reads administration data (evidence: `server/app/api/routes/admin.py`)
- Admin routes → JWT and role checks: requires admin (evidence: `server/app/api/routes/admin.py`)
- Administrator → ShipRule interface: manages platform
- Authentication routes → JWT and role checks: issues tokens (evidence: `server/app/api/routes/auth.py`)
- FastAPI application → Service configuration: configures service (evidence: `server/main.py`)
