Add FastAPI backend HMVC module structure#356
Merged
NoorChasib merged 18 commits intomainfrom Aug 21, 2025
Merged
Conversation
Introduces the foundational package structure for the FastMCP backend using the HMVC pattern. Adds __init__.py files for app, middleware, modules, shared, and various agent submodules, including agent registry logic and shared RAG state utilities. Prepares the codebase for modular development and agent auto-discovery.
Added comprehensive unit tests for MCP agents in test_mcp_agents.py, covering agent registry, tool functionality, and server health. Updated test_main.py to improve import path handling. Removed empty __init__.py from unittest_backend.
Introduces an OrchestratorAgent using FastMCP that can analyze tasks, determine required capabilities, coordinate specialized agents, and generate execution plans. Includes tools for orchestrating tasks, listing agent capabilities, and querying agent status. Internal helper functions support task analysis and execution planning.
Introduces three new agent modules: community_detection.py for community-based search, explicit_search.py for safe Cypher query execution against Neo4j, and semantic_search.py for cosine similarity search using RAG and state management. These modules provide distinct search capabilities for the agent system.
Introduces new agent and analytics modules, including controllers, models, services, and views for both. The agent module supports agentic chat, orchestration of multi-agent tasks, and agent status/capabilities endpoints. The analytics module provides endpoints for saving and updating analytics data.
Introduces the analytics module including Pydantic models for analytics data, an asynchronous service for reading, writing, saving, and updating analytics JSON data, and view helpers for formatting API responses. This provides the foundation for analytics data management in the backend.
Introduces a new authentication module for FastAPI, including controller setup with routes, service logic for login, token refresh, and health check, Pydantic models for request/response schemas, and view helpers for formatting responses.
Introduces a new chat module for FastAPI, including controller, service, model, and view layers. The module supports chat processing and retrieval of available RAG states, with clear separation of concerns and Pydantic models for request/response validation.
Introduces a new feedback module for the FastAPI backend, including controller, service, models, and views. Provides endpoints for submitting questions, processing feedback, handling RAG feedback, and fetching feedback data.
Introduces new modules under app/shared/models for Azure AI, AWS Bedrock, Neo4j, and retrieval-augmented generation (RAG). These modules provide classes and functions for interacting with respective AI services, vector search, and RAG workflows, supporting advanced conversational and retrieval capabilities.
Introduces custom exception classes for module-specific errors, several RAG state model implementations (including UpdatedChunks, AtomicIndexing, and ImagesAndChunks), a Trulens integration module for feedback and database operations, and a utility class for standardized API responses. These additions provide foundational components for error handling, retrieval-augmented generation state management, feedback processing, and consistent API responses.
Introduced a ModuleRegistry class to centralize registration and management of HMVC modules. Updated main.py to use the registry for including routers, improving modularity and maintainability. Also switched MCP app initialization to use agent_registry from the new module structure.
Deleted all source files under web/backend-fastapi/app, including controllers, models, services, and agent modules. This removes the FastAPI backend implementation, RAG models, analytics, feedback, and agent integration code from the project.
Introduced a new section in the presentation detailing the transition from a monolithic MVC to a modular HMVC architecture for the FastAPI backend. The new slides cover the motivation, architectural differences, module breakdown, benefits for agent systems, and the advantages realized in development, testing, scalability, and deployment.
Deleted empty or placeholder __init__.py files from middleware, analysis, and specialized agent modules to clean up the codebase. Also updated the community_detection tool decorator to include explicit name and description parameters for better clarity and documentation.
dbarkowsky
reviewed
Jul 30, 2025
| from ..models.agent_model import AgentRequest, AgentResponse | ||
|
|
||
|
|
||
| class OrchestratorService: |
Collaborator
There was a problem hiding this comment.
It looks like this shares a lot of logic with the agent_service.py
I wonder if we could make a parent class that covers both of these.
| from ..models.auth_model import TokenRequest | ||
|
|
||
|
|
||
| class AuthController: |
Collaborator
There was a problem hiding this comment.
Are these for future outside use of this API?
Otherwise traffic from the browser doesn't perform the login through this API at the moment.
The 'HMVC Backend Transformation' item was removed from the 'What we will cover' section in the presentation index. This streamlines the agenda to focus on other topics.
Collaborator
|
Tested routes available via Swagger docs. A few items to edit at your own judgement:
Let me know when you're done any edits you want to make and I can approve. |
dbarkowsky
approved these changes
Aug 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Summary
ZUBA-423
This PR transforms the backend architecture to use HMVC pattern while integrating FastMCP for agent-based interactions.
Key Changes
1. HMVC Module Structure
agent/,analytics/,auth/,chat/,feedback/)controllers/,models/,services/, andviews/2. FastMCP Agent Integration
Agent Registry System
app/modules/agent/agents/__init__.py: Central registry for MCP agents with auto-discoverySpecialized MCP Agents
agents/search/semantic_search.py- Vector similarity searchagents/search/explicit_search.py- Cypher query executionagents/search/community_detection.py- Graph analysisagents/orchestrator/orchestrator_agent.py- Multi-agent coordinationService Layer Integration
3. Technical Implementation
MCP Client Pattern
Authentication Flow
Tool Discovery & Execution
semanticsearch_semantic_search)4. API Endpoints
New Routes
POST /agent/- Basic agent chat with automatic tool selectionPOST /agent/orchestrate/- Complex multi-agent task coordinationGET /agent/capabilities/- List available agents and capabilitiesGET /agent/status/{agent_name}- Individual agent statusFiles Modified/Added
Core Architecture
app/modules/module_registry.py- Module discovery systemapp/modules/agent/- Complete agent module with HMVC structureFastMCP Integration
app/modules/agent/agents/__init__.py- Agent registryapp/modules/agent/agents/search/- Search agent implementationsapp/modules/agent/agents/orchestrator/- Multi-agent orchestrationapp/modules/agent/services/agent_service.py- MCP client integrationapp/modules/agent/services/orchestrator_service.py- Orchestration logic🔰 Checklist