How cos30018-2025-sem2-groupd1/medicaldiagnosissystem works
Project Type and Purpose
• This is a full-stack web application (“Medical AI Assistant”) with a FastAPI backend, a static/JavaScript frontend, AI-model integrations, and MongoDB persistence.
• Purpose: offer an AI-powered medical chatbot that keeps patient-centric memory, supports doctors/patients workflows, and persists data in MongoDB.
File‐Structure Analysis
• Top‐level: Docker/Docker-Compose files for containerization; requirements*.txt; setup guides.
• src/api/routes/: HTTP controllers (FastAPI endpoints) grouped by resource (chat, session, user/patient, system, static).
• src/core/: In‐memory caching and context-building (LRU short-term, session history).
• src/data/: Repository layer for MongoDB operations (connection, CRUD on sessions/messages/patients/users/medical KB).
• src/services/: Business logic for AI interactions (Gemini calls, NVIDIA summariser fallback, audio transcription).
• src/models/: Pydantic or ORM models for request/response schemas.
• src/utils/: Helpers (embeddings, logging, API-key rotator).
• src/main.py or start.py: FastAPI app entrypoint.
• static/: Frontend assets (HTML/CSS/JS).
• tests/: Unit/integration tests (e.g., Mongo tests).
README Insights
• High-level architecture: layered backend (memory, data, API).
• Key endpoints and flows described.
• Technology stack: Python 3.11, FastAPI, MongoDB, Docker, JS/CSS frontend, external AI APIs.
Main Components
a. Frontend (Browser)
• Static assets served by FastAPI (/static) or CDN.
• JavaScript app: UI modules (chat, sessions sidebar, patient/doctor modals).
b. Backend API (FastAPI App)
• HTTP Routes → Controllers (src/api/routes).
• Business core:
– Memory Manager (LRU cache + session history builder).
– Services: Gemini API, NVIDIA summariser, audio transcription.
• Data Layer: Repository modules interacting with MongoDB.
• Config & Utils: Settings loader, key rotator, logger.
c. Database
• MongoDB (persist sessions, messages, patient/doctor records, long-term memory).
d. External Services
• Gemini AI API
• NVIDIA summariser service
e. Infrastructure
• Docker container for backend + container for MongoDB (via Docker Compose)
Relationships and Data Flow
1. Browser → HTTP (JSON) → FastAPI routes
2. Route handler calls → Core/Memory to build context
3. Core invokes → Services (Gemini or fallback NVIDIA summariser)
4. Service returns → generated response
5. Handler persists → messages & memory summaries via Data/Repository → MongoDB
6. Response → back to Browser
7. Static file requests → served by FastAPI static route
Architectural Patterns & Principles
• Layered Architecture: Routes → Core/Services → Data → DB
• Repository Pattern for data access
• Cache + Persistence: short-term LRU + long-term Mongo
• Key Rotator for load-balancing external API keys
• Containerization for environment consistency