A complete, production-ready FastAPI backend for generating client onboarding system estimates with:
✅ FastAPI Application - RESTful API with automatic documentation
✅ OpenAI Integration - GPT-4 powered feature extraction and response generation
✅ PDF/DOCX Processing - Document extraction from all reference files
✅ Estimation Engine - Time and cost calculation with complexity multipliers
✅ Knowledge Base - Structured data from extracted documents
✅ Railway Configuration - Ready for one-click deployment
✅ Error Handling - Comprehensive logging and error management
✅ API Documentation - Swagger UI and ReDoc included
Estimate_Bot/
├── app/
│ ├── api/endpoints.py # API routes
│ ├── core/config.py # Configuration
│ ├── models/schemas.py # Pydantic models
│ ├── services/
│ │ ├── estimation_engine.py # Calculation logic
│ │ ├── knowledge_base.py # Document management
│ │ └── openai_service.py # AI integration
│ ├── utils/document_extractor.py # PDF/DOCX extraction
│ └── main.py # FastAPI app
├── requirements.txt # Dependencies
├── Dockerfile # Docker configuration for Railway
├── .dockerignore # Docker ignore file
├── railway.json # Railway config (uses Dockerfile)
├── runtime.txt # Python version
├── .env # Environment variables (gitignored)
├── venv/ # Virtual environment (gitignored)
├── test_api.py # Test script
└── DEPLOYMENT.md # Deployment guide
pip install -r requirements.txtThe .env file is already created. Just edit it and add your OpenAI API key:
# Edit .env file
OPENAI_API_KEY=your_openai_api_key_hereNote: .env and venv/ are already in .gitignore and won't be committed to Git.
# Start server
uvicorn app.main:app --reload
# In another terminal, run tests
python3 test_api.pyOption A: Via Railway Dashboard (Recommended)
- Push your code to GitHub
- Go to https://railway.app
- Click "New Project" → "Deploy from GitHub repo"
- Connect your GitHub account and select the repository
- Railway will automatically detect the Dockerfile
- Set environment variable:
OPENAI_API_KEYin Railway dashboard - Deploy!
Option B: Via Railway CLI
npm i -g @railway/cli
railway login
railway init
railway link # Link to GitHub repo
railway upNote: Railway uses Dockerfile for building and deployment (Procfile removed).
Railway will provide a URL like: https://your-app.railway.app
Test it:
curl https://your-app.railway.app/api/v1/healthOnce deployed, your endpoints will be:
POST https://your-app.railway.app/api/v1/estimate- Generate estimatePOST https://your-app.railway.app/api/v1/chat- Chat interfaceGET https://your-app.railway.app/api/v1/features- List featuresGET https://your-app.railway.app/api/v1/health- Health checkGET https://your-app.railway.app/docs- API documentation
curl -X POST https://your-app.railway.app/api/v1/estimate \
-H "Content-Type: application/json" \
-d '{
"requirements": "I need a client onboarding system with user authentication and dashboard"
}'Railway Dashboard → Variables:
OPENAI_API_KEY(REQUIRED) - Your OpenAI API key
Optional:
DEFAULT_HOURLY_RATE- Default: 100.0BUFFER_PERCENTAGE- Default: 0.20OPENAI_MODEL- Default: gpt-4-turbo-preview
Your frontend team can integrate using:
// Example fetch call
const response = await fetch('https://your-app.railway.app/api/v1/estimate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
requirements: 'User authentication and dashboard',
hourly_rate: 100.0,
include_breakdown: true
})
});
const estimate = await response.json();
console.log(estimate);{
"total_time_hours": 240.0,
"total_cost": 24000.0,
"breakdown": [
{
"feature": "User Authentication",
"description": "Login and registration",
"time_hours": 52.0,
"cost": 5200.0,
"complexity": "medium"
}
],
"assumptions": [
"Estimates are based on standard implementation practices",
"A 20% buffer has been included for unforeseen complexities"
],
"timeline": "Approximately 6 weeks",
"summary": "AI-generated professional summary...",
"next_steps": [
"Review this estimate and provide feedback",
"Schedule a detailed requirements discussion"
]
}-
"OpenAI API key not configured"
- Set
OPENAI_API_KEYin Railway environment variables
- Set
-
"Module not found"
- Ensure all dependencies are in
requirements.txt - Railway will auto-install on deploy
- Ensure all dependencies are in
-
Port errors
- Railway sets
$PORTautomatically - Don't hardcode ports
- Railway sets
-
PDF extraction fails
- Ensure PDF files are in project root
- Check file permissions
- API Docs: Available at
/docswhen deployed - Deployment Guide: See
DEPLOYMENT.md - Project Workflow: See
PROJECT_WORKFLOW.md
- ✅ AI-powered feature extraction from natural language
- ✅ Professional ChatGPT-like response generation
- ✅ Detailed time and cost breakdowns
- ✅ Complexity-based calculations
- ✅ 20% buffer for unforeseen issues
- ✅ Timeline estimation
- ✅ Assumptions and disclaimers
- ✅ Next steps recommendations
The API is fully built and ready for deployment. Just:
- Set
OPENAI_API_KEYin Railway - Deploy!
- Share the API URL with your frontend team
Happy Deploying! 🚀