How abhi-7-github/shiprule works
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: pipeline.py RAG orchestrator · main.py FastAPI application · documents.py Document endpoints · query.py Query endpoint
Components 29
Web client
- ShipRule interface
client/src/app - Query interface
client/src/components/chat/QueryInterface.tsx - Document manager
client/src/components/documents/DocumentManager.tsx - API service client
client/src/services/api.ts
API and identity
- FastAPI application
server/main.py - Query endpoint
server/app/api/routes/query.py - Document endpoints
server/app/api/routes/documents.py - Authentication routes
server/app/api/routes/auth.py - Admin routes
server/app/api/routes/admin.py - JWT and role checks
server/app/api/dependencies.py
Document indexing
- Document ingestion
server/app/documents/ingestion.py - Document loading
server/app/documents/loader.py - Text cleaning
server/app/documents/cleaner.py - Text chunking
server/app/documents/chunker.py - Embedding generation
server/app/rag/embeddings.py
Grounded answers
- RAG orchestrator
server/app/rag/pipeline.py - Hybrid retrieval
server/app/rag/retrieval.py - Vector indexing
server/app/rag/indexing.py - Cross-encoder reranking
server/app/rag/reranker.py - Retrieval safeguards
server/app/guardrails/retrieval.py - Scope safeguards
server/app/guardrails/scope.py - Security safeguards
server/app/guardrails/security.py - Answer and citation checks
server/app/validation - Groq completion
server/app/llm/groq.py - Prompt templates
server/app/prompts/prompt_templates.py
Persistence and operations
- MongoDB user and activity data
server/app/db/mongodb.py - Service configuration
server/app/core/config.py
Other components
- Platform user
- Administrator
Connections 38
- Platform user → ShipRule interface: uses
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
README.md - FastAPI application → Query endpoint: registers
server/main.py - FastAPI application → Document endpoints: registers
server/main.py - FastAPI application → Authentication routes: registers
server/main.py - FastAPI application → Admin routes: registers
server/main.py - Query endpoint → RAG orchestrator: calls
server/app/api/routes/query.py - Query endpoint → JWT and role checks: decodes token
server/app/api/routes/query.py - Query endpoint → MongoDB user and activity data: records activity
server/app/api/routes/query.py - Document endpoints → Document loading: loads files
server/app/api/routes/documents.py - Document endpoints → Text cleaning: cleans text
server/app/api/routes/documents.py - Document endpoints → Embedding generation: embeds documents
server/app/api/routes/documents.py - Document endpoints → Document ingestion: prepares corpus
- Document ingestion → Document loading: loads documents
server/app/documents/ingestion.py - Document ingestion → Text cleaning: cleans text
server/app/documents/ingestion.py - Document ingestion → Text chunking: creates chunks
server/app/documents/ingestion.py - RAG orchestrator → Hybrid retrieval: retrieves candidates
server/app/rag/pipeline.py - RAG orchestrator → Cross-encoder reranking: reranks candidates
server/app/rag/pipeline.py - RAG orchestrator → Retrieval safeguards: checks retrieval
server/app/rag/pipeline.py - RAG orchestrator → Scope safeguards: checks scope
server/app/rag/pipeline.py - RAG orchestrator → Security safeguards: checks security
server/app/rag/pipeline.py - RAG orchestrator → Answer and citation checks: validates answer
server/app/rag/pipeline.py - RAG orchestrator → Groq completion: requests completion
server/app/rag/pipeline.py - RAG orchestrator → Prompt templates: uses templates
server/app/rag/pipeline.py - Hybrid retrieval → Embedding generation: embeds query
server/app/rag/retrieval.py - Hybrid retrieval → Vector indexing: loads indexed collection
server/app/rag/retrieval.py - Cross-encoder reranking → Hybrid retrieval: uses retrieval
server/app/rag/reranker.py - Cross-encoder reranking → Vector indexing: uses index
server/app/rag/reranker.py - Authentication routes → MongoDB user and activity data: manages users
server/app/api/routes/auth.py - Admin routes → MongoDB user and activity data: reads administration data
server/app/api/routes/admin.py - Admin routes → JWT and role checks: requires admin
server/app/api/routes/admin.py - Administrator → ShipRule interface: manages platform
- Authentication routes → JWT and role checks: issues tokens
server/app/api/routes/auth.py - FastAPI application → Service configuration: configures service
server/main.py