How sifatul-islam-onik/fableflash-preli works
1. What this repository is
QueueStorm Investigator is a stateless FastAPI service for analyzing digital-finance support tickets. Its main job is to turn a complaint plus recent transaction history into a structured investigation result and a safe customer reply.
2. Top-level runtime boundary
The runtime entrypoint is app/main.py, which wires the API routers into a FastAPI app. There are two public endpoints: GET /health for liveness and POST /analyze-ticket for the ticket-analysis workflow.
3. Request/response contract
Input and output are modeled with Pydantic schemas under app/models. This is the main boundary between external clients and internal logic: requests are strictly validated before any analysis runs, and the response is normalized into a structured API payload.
4. Core deterministic engine
Most business reasoning lives in app/core. This layer is intentionally rule-based and deterministic:
- transaction_matcher.py identifies the most relevant transaction from user history.
- evidence_analyzer.py judges whether the complaint is supported by the transaction data.
- case_classifier.py maps the ticket to a case type and support department.
- severity_scorer.py assigns severity.
- escalation.py decides whether human review is required.
This is the main domain logic and the most important subsystem for an architecture diagram.
5. Primary data flow for analysis
The /analyze-ticket flow is: validate request → match transaction context → analyze evidence consistency → classify case and route department → score severity → decide escalation → generate customer-facing text. The core decision fields are produced before any LLM call, so the model is used for language generation rather than business judgment.
6. LLM layer and external dependency
The app/llm package isolates all model-facing behavior. groq_client.py is the only external AI dependency and talks to Groq using API keys from environment variables. prompts.py prepares the prompt context, parser.py extracts structured output from the model response, and fallback.py provides a deterministic template-based response when the model is unavailable or rate-limited.
7. Failover behavior
The LLM client is designed to degrade gracefully: it can iterate through multiple GROQ_API_KEY_* keys and falls back to local template generation if calls fail. That means the service does not depend on the LLM for correctness, only for better natural-language output.
8. Safety boundary
app/safety/guardrails.py is a post-processing safety layer applied to generated replies. It scans for unsafe content such as credential requests, unauthorized refund promises, or off-channel contact instructions, and it also normalizes text formatting into single-line outputs. This is the final gate before a response is returned to clients.
9. Configuration and deployment
app/config.py centralizes runtime configuration from environment variables. The repo includes Docker support (Dockerfile, docker-compose.yml) and environment templates (.env.example), so the application is intended to run as a containerized API service without any database or persistent storage.
10. Operational and verification surface
Tests under tests/ cover health checks, analyze behavior, safety rules, and sample-case regressions. CI is handled by GitHub Actions in .github/workflows/ci.yml, which runs the test suite and builds the Docker image. The sample cases and output files in the repo are evaluation artifacts, not runtime dependencies.
11. Important architectural takeaway
The overall architecture is a layered pipeline: API boundary → deterministic finance-ops reasoning → optional LLM text generation → safety sanitization → response. The important separation is that domain decisions stay local and rule-based, while the LLM is treated as a constrained text service behind a failover and guardrail boundary.
Main entry points: analyze.py Analyze API · main.py App entry · guardrails.py Guardrails · groq_client.py Groq client
Components 20
Application
FastAPI runtime and request-processing layers
- App entry · Builds the service and mounts routers
app/main.py - Health API · Liveness endpoint
app/routers/health.py - Analyze API · Ticket analysis endpoint
app/routers/analyze.py - Request schema · Validates ticket input
app/models/request.py - Response schema · Normalizes investigation output
app/models/response.py - Config · Loads runtime settings from environment
app/config.py - Guardrails · Removes unsafe content and normalizes output
app/safety/guardrails.py
Domain Logic
Deterministic ticket investigation and decisioning
- Txn matcher · Finds the most relevant transaction
app/core/transaction_matcher.py - Evidence check · Compares complaint with transaction data
app/core/evidence_analyzer.py - Case class · Assigns case type and department
app/core/case_classifier.py - Severity · Rates urgency and impact
app/core/severity_scorer.py - Escalation · Flags human review needs
app/core/escalation.py
LLM Layer
External model integration and fallback generation
- Prompt prep · Builds model context from decisions
app/llm/prompts.py - Groq client · Calls Groq with rotating API keys
app/llm/groq_client.py - LLM parser · Extracts structured model output
app/llm/parser.py - Fallback reply · Produces deterministic text when LLM fails
app/llm/fallback.py
Operations
Containerization, CI, and verification assets
- Test suite · Verifies health, analysis, safety, and sample cases
tests - CI workflow · Runs tests and builds the image
.github/workflows/ci.yml - Docker build · Defines the service image
Dockerfile - Compose setup · Local container orchestration
docker-compose.yml
Connections 23
- App entry → Health API: mounts · Registers the health route
- App entry → Analyze API: mounts · Registers the analysis route
- App entry → Config: loads · Reads runtime settings
- Health API → Response schema: returns · Uses normal API response shape
- Analyze API → Request schema: validates · Checks incoming ticket payload
- Analyze API → Txn matcher: starts · Begins ticket reasoning
- Txn matcher → Evidence check: feeds · Passes matched transaction context
- Evidence check → Case class: routes · Provides supported case context
- Case class → Severity: refines · Adds case priority signal
- Severity → Escalation: decides · Determines need for review
- Escalation → Prompt prep: summarizes · Prepares structured decision context
- Prompt prep → Groq client: invokes · Sends generation request
- Groq client → LLM parser: returns · Model output is parsed into structure
- Groq client → Fallback reply: fails over · Uses deterministic reply on error or rate limit
- Fallback reply → Guardrails: sanitizes · Fallback text still passes safety checks
- LLM parser → Guardrails: sanitizes · Final reply is checked before return
- Guardrails → Response schema: formats · Produces API-ready response payload
- Analyze API → Response schema: returns · Responds with structured investigation result
- Test suite → App entry: covers · Exercises application behavior
- Test suite → Guardrails: covers · Checks safety filtering
- CI workflow → Test suite: runs · CI executes the test suite
- CI workflow → Docker build: builds · CI validates container image
- Compose setup → Docker build: uses · Local compose is based on the service image