-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPROJECT_STRUCTURE.txt
More file actions
250 lines (216 loc) · 8.53 KB
/
PROJECT_STRUCTURE.txt
File metadata and controls
250 lines (216 loc) · 8.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
Clinical-ChatBot/
│
├── README.md # Main documentation
├── ARCHITECTURE.md # System architecture details
├── QUICK_START.md # Quick start guide
├── DEVELOPMENT.md # Development guide
├── .gitignore # Git ignore rules
├── docker-compose.yml # Docker orchestration
│
├── backend/ # Python Backend
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI application entry
│ │ ├── config.py # Configuration management
│ │ │
│ │ ├── api/ # API routes
│ │ │ ├── __init__.py
│ │ │ └── routes/
│ │ │ ├── __init__.py
│ │ │ ├── chat.py # Chat endpoints
│ │ │ ├── documents.py # Document management
│ │ │ └── health.py # Health checks
│ │ │
│ │ ├── models/ # Data models
│ │ │ ├── __init__.py
│ │ │ └── schemas.py # Pydantic schemas
│ │ │
│ │ └── services/ # Business logic
│ │ ├── __init__.py
│ │ ├── pinecone_service.py # Vector DB operations
│ │ ├── document_processor.py # Document processing
│ │ └── rag_engine.py # RAG implementation
│ │
│ ├── tests/ # Test suite
│ │ ├── __init__.py
│ │ ├── conftest.py # Test fixtures
│ │ ├── test_rag_engine.py # RAG engine tests
│ │ ├── test_document_processor.py # Document processor tests
│ │ └── test_api_chat.py # API endpoint tests
│ │
│ ├── requirements.txt # Python dependencies
│ ├── pytest.ini # Pytest configuration
│ ├── Dockerfile # Docker image
│ ├── .env.example # Environment template
│ └── .env # Environment variables (git ignored)
│
└── frontend/ # Next.js Frontend
├── src/
│ ├── components/ # React components
│ │ ├── ChatContainer.tsx # Main chat interface
│ │ ├── ChatMessage.tsx # Message component
│ │ ├── ChatInput.tsx # Input component
│ │ └── DocumentUpload.tsx # Upload component
│ │
│ ├── pages/ # Next.js pages
│ │ ├── _app.tsx # App wrapper
│ │ ├── _document.tsx # Document structure
│ │ └── index.tsx # Home page
│ │
│ ├── services/ # Services
│ │ └── api.ts # API client
│ │
│ ├── store/ # State management
│ │ └── chatStore.ts # Zustand store
│ │
│ ├── theme/ # UI theme
│ │ └── theme.ts # MUI theme config
│ │
│ └── types/ # TypeScript types
│ └── index.ts # Type definitions
│
├── public/ # Static assets
│
├── package.json # Node dependencies
├── tsconfig.json # TypeScript config
├── next.config.js # Next.js config
├── Dockerfile # Docker image
├── .env.local.example # Environment template
└── .env.local # Environment variables (git ignored)
KEY FILES BY FUNCTION:
======================
API ENDPOINTS:
- backend/app/api/routes/chat.py → POST /api/chat/message (send message)
→ GET /api/chat/history/:id (get history)
→ DELETE /api/chat/conversation/:id
- backend/app/api/routes/documents.py → POST /api/documents/upload (upload PDF)
→ GET /api/documents/stats
- backend/app/api/routes/health.py → GET /api/health (health check)
CORE SERVICES:
- backend/app/services/rag_engine.py → RAG implementation & LLM generation
- backend/app/services/document_processor.py → PDF processing & chunking
- backend/app/services/pinecone_service.py → Vector database operations
CONFIGURATION:
- backend/app/config.py → Backend configuration
- backend/.env → Backend environment variables
- frontend/src/theme/theme.ts → UI theme and styling
- frontend/.env.local → Frontend environment variables
STATE MANAGEMENT:
- frontend/src/store/chatStore.ts → Global state (Zustand)
API CLIENT:
- frontend/src/services/api.ts → HTTP client (Axios)
UI COMPONENTS:
- frontend/src/components/ChatContainer.tsx → Main chat interface
- frontend/src/components/ChatMessage.tsx → Individual messages
- frontend/src/components/ChatInput.tsx → Message input
- frontend/src/components/DocumentUpload.tsx → Document upload
DATA MODELS:
- backend/app/models/schemas.py → Pydantic models (validation)
- frontend/src/types/index.ts → TypeScript interfaces
TESTING:
- backend/tests/ → Python tests (pytest)
- backend/tests/conftest.py → Test fixtures
- frontend/src/components/__tests__/ → React component tests
DEPLOYMENT:
- backend/Dockerfile → Backend container
- frontend/Dockerfile → Frontend container
- docker-compose.yml → Multi-container orchestration
DEVELOPMENT WORKFLOW:
====================
1. Start Backend:
cd backend
source venv/bin/activate
python -m app.main
→ Runs on http://localhost:8000
2. Start Frontend:
cd frontend
npm run dev
→ Runs on http://localhost:3000
3. Run Tests:
Backend: cd backend && pytest
Frontend: cd frontend && npm test
4. View API Docs:
http://localhost:8000/api/docs
TECHNOLOGY STACK:
================
Backend:
- FastAPI → Web framework
- LangChain → LLM orchestration
- Pinecone → Vector database
- OpenAI → GPT-4 LLM
- Pydantic → Data validation
- Pytest → Testing
Frontend:
- Next.js → React framework
- TypeScript → Type safety
- Material-UI → UI components
- Zustand → State management
- Axios → HTTP client
- React Markdown → Markdown rendering
EXTERNAL SERVICES:
==================
1. OpenAI API
- Purpose: GPT-4 language model
- Used in: RAG engine for response generation
- Config: OPENAI_API_KEY in .env
2. Pinecone
- Purpose: Vector database for document embeddings
- Used in: Document storage and similarity search
- Config: PINECONE_API_KEY, PINECONE_ENVIRONMENT in .env
DATA FLOW:
==========
Chat Message Flow:
User Input (ChatInput.tsx)
↓
State Update (chatStore.ts)
↓
API Request (api.ts → POST /api/chat/message)
↓
Backend Processing (chat.py → rag_engine.py)
↓
Vector Search (pinecone_service.py)
↓
LLM Generation (OpenAI GPT-4)
↓
Response (back to frontend)
↓
UI Update (ChatContainer.tsx)
Document Upload Flow:
File Selection (DocumentUpload.tsx)
↓
Upload Request (api.ts → POST /api/documents/upload)
↓
Backend Processing (documents.py → document_processor.py)
↓
PDF Parsing (PyPDF)
↓
Text Chunking (RecursiveCharacterTextSplitter)
↓
Embedding Generation (OpenAI)
↓
Vector Storage (Pinecone)
↓
Response (success + stats)
PRODUCTION CHECKLIST:
====================
Backend:
[ ] Set APP_ENV=production
[ ] Change SECRET_KEY
[ ] Configure CORS for production domain
[ ] Set up logging
[ ] Use Gunicorn/Uvicorn workers
[ ] Set up monitoring
[ ] Configure rate limiting
Frontend:
[ ] Run npm run build
[ ] Set NEXT_PUBLIC_API_URL to production
[ ] Enable HTTPS
[ ] Configure CDN
[ ] Set up error tracking
[ ] Optimize bundle size
Infrastructure:
[ ] Set up SSL certificates
[ ] Configure reverse proxy
[ ] Set up backups
[ ] Configure monitoring
[ ] Set up CI/CD pipeline