Meet Patel commited on
Commit
52bbf83
·
1 Parent(s): bd84a4f

Remove ARCHITECTURE.md from version control and update .gitignore to exclude it

Browse files
Files changed (2) hide show
  1. .gitignore +1 -2
  2. ARCHITECTURE.md +332 -0
.gitignore CHANGED
@@ -10,5 +10,4 @@ wheels/
10
  # Virtual environments
11
  .venv
12
 
13
- # Documentation
14
- ARCHITECTURE.md
 
10
  # Virtual environments
11
  .venv
12
 
13
+
 
ARCHITECTURE.md ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TutorX-MCP Architecture Documentation
2
+
3
+ ## Table of Contents
4
+ 1. [System Overview](#system-overview)
5
+ 2. [Architecture Components](#architecture-components)
6
+ 3. [Data Flow](#data-flow)
7
+ 4. [Technical Stack](#technical-stack)
8
+ 5. [Security & Performance](#security--performance)
9
+ 6. [Deployment Architecture](#deployment-architecture)
10
+
11
+ ## System Overview
12
+
13
+ TutorX-MCP is an advanced educational AI tutoring platform that leverages the Model Context Protocol (MCP) for tool integration and provides a comprehensive suite of educational features through both MCP clients and a web interface.
14
+
15
+ ```mermaid
16
+ graph TD
17
+ A[Student] --> B[Web Interface]
18
+ A --> C[MCP Client]
19
+ B --> D[TutorX-MCP Server]
20
+ C --> D
21
+ D --> E[Core Features]
22
+ D --> F[Advanced Features]
23
+ D --> G[Multi-Modal Features]
24
+ D --> H[Assessment Features]
25
+ ```
26
+
27
+ ## Architecture Components
28
+
29
+ ### 1. Core Components
30
+
31
+ ```mermaid
32
+ graph LR
33
+ A[MCP Server] --> B[Core Features]
34
+ A --> C[Advanced Features]
35
+ A --> D[Multi-Modal Features]
36
+ A --> E[Assessment Features]
37
+
38
+ B --> B1[Adaptive Learning]
39
+ B --> B2[Concept Graph]
40
+ B --> B3[Learning Paths]
41
+
42
+ C --> C1[Neurological Monitor]
43
+ C --> C2[Knowledge Fusion]
44
+ C --> C3[Lesson Authoring]
45
+
46
+ D --> D1[Text Processing]
47
+ D --> D2[Voice Processing]
48
+ D --> D3[Handwriting Processing]
49
+
50
+ E --> E1[Quiz Generation]
51
+ E --> E2[Assessment Creation]
52
+ E --> E3[Analytics]
53
+ ```
54
+
55
+ ### 2. Client-Server Architecture
56
+
57
+ ```mermaid
58
+ sequenceDiagram
59
+ participant C as Client
60
+ participant S as MCP Server
61
+ participant T as Tools
62
+ participant R as Resources
63
+
64
+ C->>S: HTTP Request
65
+ S->>T: Tool Execution
66
+ T->>S: Response
67
+ S->>C: HTTP Response
68
+
69
+ C->>S: Resource Request
70
+ S->>R: Resource Fetch
71
+ R->>S: Resource Data
72
+ S->>C: Resource Response
73
+ ```
74
+
75
+ ## MCP Server Architecture (v0.1.0 - v0.2.0)
76
+
77
+ - The MCP server is structured to use a single shared `mcp` instance, defined in a dedicated module (`mcp_instance.py`)
78
+ - All tool modules import this shared instance to register their tools, ensuring all tools are available to the running server and MCP clients
79
+ - The server exposes the SSE transport at `/sse` for protocol-compliant client connections (e.g., MCP Inspector, Claude Desktop, etc.)
80
+ - Circular import issues are avoided by isolating the MCP instance from the main server and tool modules
81
+ - The server is fully compatible with MCP Inspector and other clients for tool discovery and invocation
82
+
83
+ **Updates in v0.2.0:**
84
+ - Added database integration for persistent storage of resources and user data
85
+ - Implemented role-based access control for secure API access
86
+ - Added Memory Bank for stateful interactions and learning progress tracking
87
+ - Enhanced model fallback mechanisms for improved reliability
88
+ - Implemented caching strategies for frequently accessed resources
89
+
90
+ ```mermaid
91
+ graph TD
92
+ APIGateway[API Gateway Layer] --> AuthLayer[Authentication Layer]
93
+ APIGateway --> SSEEndpoint[SSE Transport]
94
+
95
+ AuthLayer --> ToolRegistry[Tool Registry]
96
+ SSEEndpoint --> ToolRegistry
97
+
98
+ ToolRegistry --> CoreTools[Core Tools]
99
+ ToolRegistry --> AdvancedTools[Advanced Tools]
100
+ ToolRegistry --> MemoryTools[Memory Tools]
101
+
102
+ CoreTools --> ResourceAccess[Resource Access]
103
+ AdvancedTools --> ResourceAccess
104
+ MemoryTools --> ResourceAccess
105
+
106
+ ResourceAccess --> CacheLayer[Cache Layer]
107
+ CacheLayer --> Database[(Database)]
108
+ CacheLayer --> ExternalAPIs[External APIs]
109
+ ```
110
+
111
+ ### Key Responsibilities
112
+ - **API Gateway:** Exposes HTTP endpoints for all core features (concepts, lessons, quizzes, learning paths, assessments, OCR, originality checking, etc.).
113
+ - **Tool Registration:** Uses MCP decorators to register modular tools from `mcp-server/tools/`. Each tool is an async function, making the system highly extensible.
114
+ - **Resource Management:** Manages the concept graph and curriculum standards as in-memory resources, enabling adaptive learning and standards alignment.
115
+ - **Model Integration:** Integrates Google Gemini Flash models for advanced text and quiz generation, with automatic fallback for reliability.
116
+ - **Multi-Modal Input:** Supports text, voice, and handwriting (via OCR) for student interaction.
117
+ - **Assessment & Analytics:** Provides endpoints for skill assessment, originality checking, and analytics.
118
+
119
+ ### Extensibility
120
+ - **Adding Tools:** New educational tools can be added by creating an async function in `mcp-server/tools/` and registering it with the MCP instance. The server auto-discovers and exposes these tools via API endpoints.
121
+ - **Resource Expansion:** The concept graph and curriculum standards can be extended to support new subjects, countries, or educational standards.
122
+
123
+ ### Example: Tool Registration
124
+ ```python
125
+ @mcp.tool()
126
+ async def generate_quiz_tool(concept: str, difficulty: str = "medium") -> Dict[str, Any]:
127
+ # ... implementation ...
128
+ ```
129
+
130
+ ## Memory Bank Implementation (v0.2.0)
131
+
132
+ The **Memory Bank** provides persistent or session-based memory for the TutorX-MCP platform. This feature:
133
+ - Stores and retrieves user/session context, learning progress, and conversation history
134
+ - Enables personalized, context-aware tutoring by allowing tools and endpoints to access relevant past interactions
135
+ - Supports both in-memory (for development) and persistent (database-backed) storage options
136
+ - Exposes memory operations (read, write, update, clear) as MCP tools for integration with the tutoring workflow
137
+ - Is designed for easy extension to support advanced analytics, recommendations, and adaptive learning features
138
+
139
+ **Architecture Integration:**
140
+ - The Memory Bank is implemented as a set of MCP tools in `memory_bank/memory_tools.py`
141
+ - It interacts with the concept graph, learning path, and assessment tools to provide a seamless, stateful tutoring experience
142
+ - Incorporates security and privacy protections with role-based access control
143
+
144
+ ```mermaid
145
+ graph TD
146
+ Client[Client Apps] -->|Request| MCP[MCP Server]
147
+ MCP -->|Read/Write| MemoryBank[Memory Bank]
148
+ MemoryBank -->|Store| SessionMemory[Session Memory]
149
+ MemoryBank -->|Store| UserMemory[User Memory]
150
+ MemoryBank -->|Store| ConceptMemory[Concept Memory]
151
+ SessionMemory -->|Persist| DB[(Database)]
152
+ UserMemory -->|Persist| DB
153
+ ConceptMemory -->|Persist| DB
154
+ ```
155
+
156
+ The Memory Bank exposes these key operations as MCP tools:
157
+ - `read_memory(memory_type, key)`: Retrieve stored memory
158
+ - `write_memory(memory_type, key, value)`: Store new memory
159
+ - `update_memory(memory_type, key, update)`: Modify existing memory
160
+ - `clear_memory(memory_type, key)`: Remove stored memory
161
+
162
+ ## Data Flow
163
+
164
+ ### 1. Student Interaction & Tool Invocation Flow
165
+
166
+ ```mermaid
167
+ graph TD
168
+ A[Student Input] --> B{Input Type}
169
+ B -->|Text| C[API: /api/text-interaction]
170
+ B -->|Voice| D[API: /api/voice-interaction]
171
+ B -->|Handwriting| E[API: /api/pdf-ocr or /api/image-to-text]
172
+ C & D & E --> F[MCP Tool Execution]
173
+ F --> G[Response Generation]
174
+ G --> H[Student Feedback]
175
+ H --> I[Learning Path Update]
176
+ I --> J[Concept Graph Update]
177
+ ```
178
+
179
+ ### 2. Tool Execution Flow
180
+
181
+ ```mermaid
182
+ sequenceDiagram
183
+ participant Client
184
+ participant MCP_Server as MCP Server
185
+ participant Tool
186
+ Client->>MCP_Server: API Request (e.g., /api/generate-quiz)
187
+ MCP_Server->>Tool: Invoke Registered Tool
188
+ Tool-->>MCP_Server: Tool Response
189
+ MCP_Server-->>Client: API Response
190
+ ```
191
+
192
+ ## Technical Stack
193
+
194
+ ### 1. Technology Stack
195
+
196
+ ```mermaid
197
+ graph TD
198
+ A[TutorX-MCP] --> B[Backend]
199
+ A --> C[Frontend]
200
+ A --> D[Infrastructure]
201
+ B --> B1[Python 3.12]
202
+ B --> B2[FastAPI]
203
+ B --> B3[FastMCP]
204
+ B --> B4[Google Gemini Flash]
205
+ B --> B5[Gradio]
206
+ C --> C1[Web Interface]
207
+ C --> C2[MCP Client]
208
+ D --> D1[HTTP Server]
209
+ D --> D2[Resource Management]
210
+ ```
211
+
212
+ ### 2. Dependencies
213
+
214
+ ```mermaid
215
+ graph LR
216
+ A[TutorX-MCP] --> B[mcp[cli] >= 1.9.3]
217
+ A --> C[gradio >= 4.19.0]
218
+ A --> D[numpy >= 1.24.0]
219
+ A --> E[pillow >= 10.0.0]
220
+ A --> F[fastapi]
221
+ A --> G[google-generativeai]
222
+ A --> H[pytesseract]
223
+ ```
224
+
225
+ ## Security & Performance
226
+
227
+ ### 1. Security Architecture
228
+
229
+ ```mermaid
230
+ graph TD
231
+ A[Client Request] --> B[Authentication]
232
+ B --> C[Authorization]
233
+ C --> D[Request Validation]
234
+ D --> E[Tool Execution]
235
+ E --> F[Response Sanitization]
236
+ F --> G[Client Response]
237
+ ```
238
+
239
+ ### 2. Performance Optimization
240
+
241
+ ```mermaid
242
+ graph LR
243
+ A[Request] --> B{Cache Check}
244
+ B -->|Hit| C[Cache Response]
245
+ B -->|Miss| D[Process Request]
246
+ D --> E[Update Cache]
247
+ E --> F[Response]
248
+ C --> F
249
+ ```
250
+
251
+ ## Deployment Architecture
252
+
253
+ ### 1. Deployment Model
254
+
255
+ ```mermaid
256
+ graph TD
257
+ A[Load Balancer] --> B[Server Instance 1]
258
+ A --> C[Server Instance 2]
259
+ A --> D[Server Instance N]
260
+
261
+ B --> E[Database]
262
+ C --> E
263
+ D --> E
264
+
265
+ B --> F[Cache]
266
+ C --> F
267
+ D --> F
268
+ ```
269
+
270
+ ### 2. Scaling Strategy
271
+
272
+ ```mermaid
273
+ graph LR
274
+ A[Monitoring] --> B{Load Check}
275
+ B -->|High| C[Scale Up]
276
+ B -->|Low| D[Scale Down]
277
+ C --> E[New Instance]
278
+ D --> F[Remove Instance]
279
+ ```
280
+
281
+ ## Key Features Implementation
282
+
283
+ ### 1. MCP Server & Modular Tool System
284
+ - **Modular Tools:** All educational features (concepts, quizzes, lessons, learning paths, OCR, originality checking) are implemented as modular async tools in `mcp-server/tools/` and registered with the MCP server.
285
+ - **API Endpoints:** Each tool is exposed via a FastAPI endpoint, making the system easy to extend and integrate.
286
+ - **Model Integration:** Quiz and lesson generation leverage Google Gemini Flash models for advanced content creation.
287
+ - **Resource Management:** The server manages a concept graph and curriculum standards for adaptive learning and standards alignment.
288
+
289
+ ### 2. Adaptive Learning Engine
290
+ - **Concept Graph:** Tracks student progress and concept relationships.
291
+ - **Personalized Learning Paths:** Generated based on prerequisites and student level.
292
+ - **Skill Assessment:** Tools for assessing student understanding and providing targeted feedback.
293
+
294
+ ### 3. Multi-Modal Interaction
295
+ - **Text, Voice, Handwriting:** Supported via dedicated endpoints and tools (text interaction, OCR, etc.).
296
+ - **Real-Time Feedback:** Immediate responses and suggestions based on student input.
297
+
298
+ ### 4. Assessment Suite
299
+ - **Automated Quiz Generation:** Using Gemini models and prompt templates.
300
+ - **Plagiarism Detection:** Originality checking tool compares submissions to reference sources.
301
+ - **Performance Analytics:** Endpoints for tracking and analyzing student progress.
302
+
303
+ ### 5. Extensibility & Integration
304
+ - **Add New Tools:** Simply create a new async function in `mcp-server/tools/` and register with `@mcp.tool()`.
305
+ - **Expand Resources:** Update concept graph or curriculum standards for new subjects or regions.
306
+ - **API-First:** All features are accessible via HTTP API for easy integration with web clients or third-party systems.
307
+
308
+ ## Future Considerations
309
+
310
+ 1. **Scalability**
311
+ - Implement horizontal scaling
312
+ - Add caching layers
313
+ - Optimize database queries
314
+
315
+ 2. **Feature Expansion**
316
+ - Add more interaction modes
317
+ - Enhance analytics capabilities
318
+ - Implement advanced AI features
319
+
320
+ 3. **Integration**
321
+ - Support for more educational standards
322
+ - Integration with LMS systems
323
+ - API expansion for third-party tools
324
+
325
+ 4. **Performance**
326
+ - Implement request batching
327
+ - Add response compression
328
+ - Optimize resource loading
329
+
330
+ ## Conclusion
331
+
332
+ TutorX-MCP provides a robust, scalable, and feature-rich educational platform that leverages modern technologies and architectural patterns to deliver an exceptional learning experience. The system's modular design allows for easy expansion and maintenance while ensuring high performance and security.