CLAUDE.md
Guides Claude Code on a financial document analysis platform with FastAPI backend, Next.js frontend, and Claude API integration.
What this file does
Guides Claude Code on a financial document analysis platform with FastAPI backend, Next.js frontend, and Claude API integration.
When to use it
- Setting up a new project with FastAPI and Next.js
- Configuring Claude Code for a financial document analysis app
- Standardizing development commands and project structure for a team
- Documenting API endpoints and testing strategies for a full-stack app
Assumes this stack
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
CFIN (Financial Document Analysis System) is an AI-powered platform for analyzing financial documents. It combines PDF processing, conversational AI, and dynamic data visualization using Claude API as its core engine.
Tech Stack
Backend
- Framework: FastAPI (Python 3.8+)
- Database: SQLAlchemy with PostgreSQL/SQLite
- AI Integration: Anthropic Claude API (primary), LangChain/LangGraph (secondary)
- Storage: Local filesystem or AWS S3
- Key Dependencies: anthropic, langchain, fastapi, sqlalchemy, pydantic
- Backend Start Terminal Command: cd /Users/alexcardell/AlexCoding_Local/cfin/backend && PYTHONPATH=$PYTHONPATH:/Users/alexcardell/AlexCoding_Local/cfin/backend python -m uvicorn app.main:app --reload --port 8000
Frontend
- Framework: Next.js 14 with App Router
- Language: TypeScript
- UI Components: Tailwind CSS, shadcn/ui
- Charts: Recharts
- State Management: React hooks and context
Development Setup
Backend Setup
cd cfin/backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
# Set environment variables
export ANTHROPIC_API_KEY="your-api-key"
export BACKEND_URL="http://localhost:8000"
export CORS_ORIGINS="http://localhost:3000"
# Initialize database
python create_db.py
# Run development server
python run.py # or uvicorn app.main:app --reload --port 8000
Frontend Setup
cd cfin/nextjs-fdas
npm install
npm run dev # Runs on http://localhost:3000
Key Development Commands
Backend Commands
# Run backend server
python run.py
python debug_server.py # Debug mode with verbose logging
./restart_server.sh # Restart server (kills existing process)
# Run tests
cd backend/tests
./run_tests.sh # Run all tests
pytest test_specific.py # Run specific test file
pytest -k "test_name" # Run specific test by name
pytest -v # Verbose output
# Database operations
python create_db.py # Initialize/reset database
python migrate_claude_fields.py # Run migrations
# API testing scripts
./test_api.sh # Test all endpoints
./test_document_api_only.sh # Test document endpoints
./test_document_endpoints.sh # Document endpoint tests
Frontend Commands
# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run test # Run Jest tests
npm test -- --watch # Run tests in watch mode
Project Structure
cfin/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI app entry point
│ │ └── routes/ # API endpoints
│ │ ├── document.py # Document management
│ │ ├── conversation.py # Chat interface
│ │ └── analysis.py # Analysis operations
│ ├── services/
│ │ ├── analysis_service.py # Analysis orchestration
│ │ ├── conversation_service.py
│ │ └── analysis_strategies/ # Analysis implementations
│ ├── pdf_processing/
│ │ ├── claude_file_client.py # Claude Files API integration
│ │ └── financial_agent.py # Financial analysis logic
│ ├── models/ # Pydantic models & DB schemas
│ ├── repositories/ # Data access layer
│ └── utils/ # Utilities and helpers
├── nextjs-fdas/
│ └── src/
│ ├── app/ # Next.js app router pages
│ │ ├── dashboard/ # Document library
│ │ └── workspace/ # Main analysis interface
│ ├── components/ # React components
│ │ ├── chat/ # Chat interface components
│ │ ├── charts/ # Visualization components
│ │ └── document/ # Document handling
│ └── lib/api/ # API client functions
└── uploads/ # Document storage (local mode)
API Endpoints
Document Management
POST /api/documents/upload- Upload PDF with Claude processingGET /api/documents/{id}- Get document detailsGET /api/documents/- List all documentsDELETE /api/documents/{id}- Delete documentGET /api/documents/{id}/citations- Get citations for highlighting
Conversation/Chat
POST /api/conversation/message- Send message with contextPOST /api/conversation/create- Create new conversationGET /api/conversation/{id}- Get conversation historyGET /api/conversation/history- List all conversations
Analysis
POST /api/analysis/run- Execute analysis on documentsGET /api/analysis/{id}- Get analysis resultsGET /api/analysis/types- List available analysis types
Claude API Configuration
The system uses different Claude models based on the operation:
- Document Processing: Claude 3 Haiku (fast, cost-effective)
- Analysis & Chat: Claude 3 Sonnet (balanced performance)
- Complex Analysis: Claude 3 Opus (highest capability)
Key settings in backend/settings.py:
DEFAULT_MODEL: "claude-3-5-sonnet-20241022"MAX_TOKENS: 4096TEMPERATURE: 0 (deterministic outputs)
Key Features
PDF Processing
- Native PDF support via Claude API (no OCR required)
- Automatic extraction of text, tables, and financial data
- Citation mapping for precise document references
Analysis Types
- Comprehensive Analysis - Full financial analysis with visualizations
- Financial Template - Structured analysis using predefined templates
- Basic Financial - Quick financial overview
- Sentiment Analysis - Tone and sentiment assessment
Tool System
The backend implements a tool-based system for Claude interactions:
- Tool definitions in
models/tools.py - Tool processing logic in
utils/tool_processing.py - Supports: charts, tables, metrics, financial calculations
- Critical: Chart tools require
xAxisKeyin config and transform data to{x, y}format - Multi-series charts automatically detected and processed differently than single-series
Testing Strategy
Backend Testing
# Unit tests
pytest backend/tests/unit/
# Integration tests
pytest backend/tests/integration/
# Performance tests
pytest backend/tests/performance/
# Run with coverage
pytest --cov=app --cov=services --cov=repositories
Frontend Testing
# Component tests
npm test
# Specific component
npm test -- ChartRenderer
# E2E tests (if configured)
npm run test:e2e
Development Tips
- Claude API Rate Limits: The system implements automatic retry logic and rate limit handling
- Document Caching: Uploaded documents are cached using Claude Files API for 7 days
- Error Handling: All API endpoints return standardized error responses
- Logging: Use
secure_loggingutility to avoid exposing sensitive data - Database Migrations: Always test migrations on a copy before applying to production
- Schema Alignment: All Pydantic models use
ConfigDict(alias_generator=to_camel, populate_by_name=True)for consistent camelCase API responses - Visualization Data: Use
List[Dict[str, Any]]for visualization fields (monetary_values,percentages) - not dictionaries - Tool Processing: Charts require
xAxisKeyin config; data is automatically transformed to{x, y}format for frontend consumption
Common Issues & Solutions
- CORS Errors: Ensure
CORS_ORIGINSenv var matches your frontend URL - Claude API Errors: Check API key and rate limits
- Database Connection: Verify
DATABASE_URLis set correctly - File Upload Issues: Check
MAX_FILE_SIZEsetting (default: 50MB) - Pydantic Validation Errors: Check that
model_dump(by_alias=True)is used for API responses to ensure camelCase output - Chart Data Errors: Missing
xAxisKeyin chart config will cause validation failures; all chart data needs x/y structure - Dict vs List Type Errors: Visualization helpers return lists, not dicts - update models accordingly
Deployment Considerations
- Set proper environment variables for all services
- Enable HTTPS for all endpoints
- Configure proper CORS origins for production domains
<Gemini_CLI_Usage_For_Long_Context_Analysis>
Using Gemini CLI for Large Codebase Analysis
When analyzing large codebases or multiple files that might exceed context limits, use the Gemini CLI with its massive
context window. Use gemini -p to leverage Google Gemini's large context capacity.
File and Directory Inclusion Syntax
Use the @ syntax to include files and directories in your Gemini prompts. The paths should be relative to WHERE you run the
gemini command:
Examples:
Single file analysis: gemini -p "@src/main.py Explain this file's purpose and structure"
Multiple files: gemini -p "@package.json @src/index.js Analyze the dependencies used in the code"
Entire directory: gemini -p "@src/ Summarize the architecture of this codebase"
Multiple directories: gemini -p "@src/ @tests/ Analyze test coverage for the source code"
Current directory and subdirectories: gemini -p "@./ Give me an overview of this entire project"
Or use --all_files flag:
gemini --all_files -p "Analyze the project structure and dependencies"
Implementation Verification Examples
Check if a feature is implemented: gemini -p "@src/ @lib/ Has dark mode been implemented in this codebase? Show me the relevant files and functions"
Verify authentication implementation: gemini -p "@src/ @middleware/ Is JWT authentication implemented? List all auth-related endpoints and middleware"
Check for specific patterns: gemini -p "@src/ Are there any React hooks that handle WebSocket connections? List them with file paths"
Verify error handling: gemini -p "@src/ @api/ Is proper error handling implemented for all API endpoints? Show examples of try-catch blocks"
Check for rate limiting: gemini -p "@backend/ @middleware/ Is rate limiting implemented for the API? Show the implementation details"
Verify caching strategy: gemini -p "@src/ @lib/ @services/ Is Redis caching implemented? List all cache-related functions and their usage"
Check for specific security measures: gemini -p "@src/ @api/ Are SQL injection protections implemented? Show how user inputs are sanitized"
Verify test coverage for features: gemini -p "@src/payment/ @tests/ Is the payment processing module fully tested? List all test cases"
When to Use Gemini CLI
Use gemini -p when:
- Analyzing entire codebases or large directories
- Comparing multiple large files
- Need to understand project-wide patterns or architecture
- Current context window is insufficient for the task
- Working with files totaling more than 100KB
- Verifying if specific features, patterns, or security measures are implemented
- Checking for the presence of certain coding patterns across the entire codebase
Important Notes
- Paths in @ syntax are relative to your current working directory when invoking gemini
- The CLI will include file contents directly in the context
- No need for --yolo flag for read-only analysis
- Gemini's context window can handle entire codebases that would overflow Claude's context
- When checking implementations, be specific about what you're looking for to get accurate results </Gemini_CLI_Usage_For_Long_Context_Analysis>
What's inside
10 sections covering project overview, tech stack, setup, commands, structure, API endpoints, Claude config, features, testing, and troubleshooting
Change this for your project
- Replace
/Users/alexcardell/AlexCoding_Local/cfin/backendwith your own backend path - Replace
abc0008/cfin_newwith your repository name - Replace
cfin/andnextjs-fdas/directory names with your project's actual directory names
Where it goes
Save as CLAUDE.md in your repository root. Claude Code reads it automatically at the start of every session.
Worth borrowing
- Separate backend and frontend setup instructions with distinct command sections
- Include a Gemini CLI usage section for large codebase analysis when context limits are a concern
- List common issues and their solutions alongside development tips for quick troubleshooting
Related Documents
Code indexing for AI agents: summarization strategies and evaluation systems
Synthesises 2024-2025 research on code indexing for AI agents, covering summarisation strategies, hybrid retrieval architectures, and evaluation benchmarks.
write-script
Guides an AI through writing a YouTube video script with strict structural, language, and quiz rules for a survival channel.
Claude AI Git Workflow Integration
Recommends using the git-ai-commit CLI tool for AI-generated commit messages instead of manual ones.
Missing Business Agents Research — FLUXION 2026
Identifies 12 missing business operations agents for an indie software company and ranks them by impact and effort with €0 implementation plans.