How garehmalika/medassit works
Project Type and Purpose
• This is a full-stack healthcare/telemedicine application.
• The Frontend is built in Next.js (React) and provides user interfaces for authentication, dashboards, patient management, consultations, prescriptions, certificates, billing, analytics, and settings.
• The Backend is a Flask monolith exposing REST/AI endpoints, orchestrating business logic, interacting with a relational database, generating PDFs, sending emails, handling payments, and offloading long-running tasks to Celery.
File Structure Analysis
• Top-level: two folders “frontend” and “Backend.”
• Frontend:
• src/app – Next.js pages/routes, relying on Next’s App Router (server+client components).
• src/components, src/services, src/hooks, src/context – UI components, API wrappers, custom hooks, global state.
• Tailwind & global CSS, Next config, ESLint, environment variables.
• Backend:
• app/run.py initializes Flask, extensions, middleware (auth, CORS, rate limit).
• app/routes – REST endpoints for AI, auth, patients, consultations, prescriptions, certificates, analytics, documents, users.
• app/services & app/ai – Business logic and GPT/Whisper integrations.
• app/database, app/migrations – PostgreSQL schema, Alembic migrations, seed scripts.
• app/email_service, payment_service, pdf_service – External integrations.
• Celery setup (celery_worker.py) for async tasks (email, PDF generation, billing).
• Deployment: Dockerfiles (backend/frontend), docker-compose; setup and coding standards guides.
• Tests covering auth, AI services, PDF generation, CRUD operations.
Key Architectural Patterns
• Layered architecture in the backend:
• Routes → Middleware → Services → Models → Database.
• Separate AI “service” layer interacting with OpenAI APIs.
• Asynchronous task queue (Celery + Redis/RabbitMQ).
• Frontend separation of concerns:
• Pages vs. shared UI components vs. API service layers.
• Context for global state (authentication, notifications).
a. Frontend (Next.js)
• UI Layer (React components, pages)
• Client-side state (AuthContext, NotificationContext)
• API Service Layer (authService, consultationService, etc.)
b. Backend (Flask)
• HTTP API Endpoints
• Middleware (Auth, CORS, Rate Limit)
• Business Logic Services (auth_service, consultation_service, etc.)
• AI Services (GPT, Whisper wrappers)
• PDF Generation Service
• Email Service
• Payment Service
• Celery Worker for background jobs
c. Database
• PostgreSQL (with Alembic migrations)
d. Message Broker
• Redis or RabbitMQ (for Celery)
e. External Services
• OpenAI (GPT, Whisper)
• SMTP provider (for email_service)
• Payment gateway (Stripe/PayPal via payment_service)
• Object storage (if used by storage_service)
Relationships and Data Flow
• Frontend ↔ Backend: HTTP(S) API calls (fetch/Axios).
• Backend → Database: SQLAlchemy ORM.
• Backend → Celery Broker: push tasks for async processing.
• Celery Worker → Database / External Services: update records, send emails, generate/store PDFs.
• Backend → External AI APIs: on-demand prompts and transcriptions.
• Backend → Payment Gateway: subscription billing and webhooks.
Final Recommendations
• Asynchronous flows separately from synchronous HTTP calls.