Feature: Content Analysis
Relevant source files
The following files were used as context for generating this wiki page:The Content Analysis feature is a core component of the Strategic Legal Analyzer AI mobile app. It enables users to submit legal documents for AI-powered evaluation. The system is designed to process content from various sources, including file uploads, camera captures of physical documents, and pasted text. After processing, it presents a structured analysis to the user, highlighting key clauses, identified risks, and strategic recommendations.
This feature is accessed from the Home screen or directly via the "Analyze Document" tab. The front-end is built using React Native with Expo, and the backend analysis is powered by an external Large Language Model (LLM) accessed via a dedicated server module. The goal is to provide users with professional legal insights directly on their mobile devices.
Sources: app/(tabs)/analyze.tsx, app/(tabs)/index.tsx:60-68, todo.md:19-24, design.md:32-45
Architecture Overview
The analysis feature follows a client-server architecture. The client-side, represented by the AnalyzeScreen, is responsible for gathering user input. The server-side contains the logic to communicate with an external LLM service, which performs the actual analysis.
The following diagram illustrates the high-level data flow from user interaction on the app to receiving analysis results.
This sequence shows the intended flow. Currently, the AnalyzeScreen uses a mock analysis function with a timeout to simulate the backend call. The actual backend logic is defined in server/_core/llm.ts.
Sources: app/(tabs)/analyze.tsx:64-84, server/_core/llm.ts:211-253
User Interface (AnalyzeScreen)
The user interface for the analysis feature is implemented in the AnalyzeScreen component. It manages the user's journey from selecting an input source to viewing the final analysis.
Sources: app/(tabs)/analyze.tsx
UI States
The screen operates in two main states:
- Input State: The default state where the user is prompted to provide a document.
- Results State: Displayed after the analysis is complete, showing the findings.
The component uses React state to manage the selected file, analysis status, and results.
// app/(tabs)/analyze.tsx:16-23
const [selectedFile, setSelectedFile] = useState</*...*/>(null);
const [documentName, setDocumentName] = useState("");
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [analysisResults, setAnalysisResults] = useState<AnalysisResult | null>(null);
Content Input Methods
The screen provides three methods for a user to input a document for analysis.
| Method | Component | Implementation Details |
|---|---|---|
| File Upload | TouchableOpacity | Calls handlePickDocument, which uses the pickDocument utility. This utility is expected to leverage the expo-document-picker library. |
| Camera Capture | TouchableOpacity | Calls handleOpenCamera, which navigates the user to the /camera-modal route to capture a photo. |
| Paste Text | TextInput | A multiline text input field where users can directly paste the content of a document. |
Sources: app/(tabs)/analyze.tsx:42-51, app/(tabs)/analyze.tsx:126-135, app/(tabs)/analyze.tsx:149-160, package.json:44
UI Flow
The following flowchart details the user's path within the AnalyzeScreen.
Sources: app/(tabs)/analyze.tsx:86-258
Backend Analysis Engine
The core of the analysis is handled by a backend module that communicates with a Large Language Model. The server/_core/llm.ts file defines the interface for this communication.
invokeLLM Function
The primary function is invokeLLM, which constructs and sends a request to the LLM API endpoint.
// server/_core/llm.ts:211
export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
// ...
}
The function performs several key steps:
- Asserts that an API key (
forgeApiKey) is available. - Normalizes the
messagesarray to the format expected by the API. - Sets the model to
gemini-2.5-flash. - Optionally includes tools and normalizes
tool_choice. - Constructs the final payload, including a
max_tokenslimit. - Sends a
POSTrequest to the API endpoint (https://forge.manus.im/v1/chat/completions). - Handles errors or returns the parsed JSON response.
Sources: server/_core/llm.ts:211-253
Data Structures
The interaction with the LLM is defined by a set of specific data types.
InvokeParams
This type defines the request payload sent to the invokeLLM function.
| Parameter | Type | Description |
|---|---|---|
messages | Message[] | An array of message objects forming the conversation history. |
tools | Tool[] | (Optional) A list of functions the model may call. |
toolChoice | ToolChoice | (Optional) Controls which function is called by the model. |
maxTokens | number | (Optional) Maximum number of tokens to generate. |
outputSchema | OutputSchema | (Optional) Defines a JSON schema for the model's output. |
responseFormat | ResponseFormat | (Optional) Specifies the output format, e.g., json_object. |
Sources: server/_core/llm.ts:46-57
Message
A Message object represents a single turn in the conversation. It can contain different types of content.
This structure allows the system to send text, images (from the camera), or files (from the document picker) to the LLM for analysis.
Sources: server/_core/llm.ts:5-30
Analysis Results
After a successful analysis, the feature presents the findings in a structured format defined by the AnalysisResult interface.
// app/(tabs)/analyze.tsx:9-13
interface AnalysisResult {
clauses: Array<{ title: string; risk: string; description: string }>;
risks: string[];
recommendations: string[];
}
The results are divided into three sections:
| Section | Description | Example (from mock data) |
|---|---|---|
| Key Clauses | A list of important clauses found in the document, each with a title, a risk level (Low, Medium, High), and a description. | title: "Payment Terms", risk: "Low", description: "Payment due within 30 days" |
| Identified Risks | A list of potential risks or unfavorable terms discovered in the document. | "Unfavorable dispute resolution clause" |
| Recommendations | A list of actionable suggestions to improve the document or mitigate risks. | "Add specific performance milestones" |
These results are rendered in the UI using distinct visual cues, such as colored tags for risk levels and icons for risks and recommendations.
Sources: app/(tabs)/analyze.tsx:9-13, app/(tabs)/analyze.tsx:70-82, lib/translations.ts:50-61