# emmaashi/compile architecture

> Architecture diagram of the GitHub repository emmaashi/compile, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emmaashi/compile
- Repository: https://github.com/emmaashi/compile

## Overview

Based on our analysis of the file tree and the README file, Compile is a full-stack web application focused on supporting families managing in-home hospice care. Its main purpose is to offer symptom tracking, data visualizations, comprehensive user profiles, and emotional support through a modern web interface combined with predictive analytics. The architecture distinctly separates frontend and backend, while also incorporating specialized machine learning (ML) modules.

##### Main System Components
- Frontend: Built with Next.js, React, and TypeScript. It includes several views and pages (Home, Predictions, Profile, Sign-Up, Visualizations), along with UI components and an API layer for interacting with the backend.
- Backend: A Flask-based server handling requests such as user authentication, session management, and serving HTML templates. It is organized following an MVC-like pattern with directories for authentication (auth.py), models (models.py), views (views.py), and templates.
- Machine Learning Module: Within the backend, there is a dedicated ML subdirectory. This module manages prediction routes, ML services, and contains model files (pickle files for severity and symptoms) along with Python code to load and run the predictive models.
- Database: Although the file tree includes a local SQLite database (backend/instance/database.db), the README indicates use of Supabase/PostgreSQL for production. This is the data persistence layer where user profiles, symptom logs, and other healthcare data reside.
- Deployment/Containerization: There are two Dockerfiles (one for the backend and one for the frontend), indicating that containerization is used to facilitate deployment.
- External Services: In a production scenario, services such as Supabase for the database and possibly third-party support libraries (SQLAlchemy, Scikit-learn, React-Chartjs) would be external dependencies.

##### Out Key Interactions and Data Flows
- Clients (users) interact with the Frontend application via web browsers.
- The Frontend communicates with the Backend via API requests (REST or similar) — e.g., for logging symptoms, authentication, or fetching predictions.
- The Backend processes these requests, interacts with the Database to store/retrieve data, and interfaces with the ML module for generating predictive analytics.
- The ML module might be accessed through dedicated routes (such as the “/prediction” endpoint) that trigger services to run the models and return results.
- There are clear boundaries between the presentation layer (Next.js/React UI) and the business logic/services (Flask controllers and ML services).

##### Architectural Patterns and Design Principles
- Separation of concerns: The division between frontend (presentation), backend (API and business logic), and the ML module.
- MVC-like structure in Flask: With separate modules for models, views, and templates.
- Containerization for consistent deployments.
- Integration patterns: The Frontend connects to the Backend via API endpoints; the Backend divides responsibilities among pure web operations and ML/scientific computation; and both layers are containerized for ease of deployment.

##### Additional Notes for Precision
– Be as detailed as possible, ensuring that every module—especially the ML services within the backend—is distinctly represented.
– Even if some directories and files (for example, cached Next.js build files) are not core architectural components, ensure that the main logical divisions are clearly separated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Web Browser)"]:::client

    subgraph "Frontend Layer"
        FE_Pages["Pages & Views (frontend/src/app)"]:::frontend
        FE_UI["UI Components (frontend/src/components/ui)"]:::frontend
        FE["Frontend (Next.js, React, TypeScript)"]:::frontend
        FE_Pages --> FE
        FE_UI --> FE
    end

    FDocker["Docker: Frontend Container"]:::docker

    subgraph "Backend Layer"
        BE["Flask API (backend/flask_app/ - auth.py, models.py, views.py, templates)"]:::backend
        BEML["ML Module (backend/ml/ - prediction.py, ml_service.py, ml_models.py)"]:::ml
        BE --> BEML
    end

    BDocker["Docker: Backend Container"]:::docker
    DB["Database (SQLite Dev/Supabase Prod)"]:::database

    Client -->|"uses"| FE
    FDocker -->|"hosts"| FE
    FE -->|"APIcalls"| BE
    BDocker -->|"hosts"| BE
    BE -->|"dataaccess"| DB

    click FE "https://github.com/emmaashi/compile/tree/main/frontend/"
    click FE_Pages "https://github.com/emmaashi/compile/tree/main/frontend/src/app"
    click FE_UI "https://github.com/emmaashi/compile/tree/main/frontend/src/components/ui"
    click BE "https://github.com/emmaashi/compile/tree/main/backend/flask_app/"
    click BEML "https://github.com/emmaashi/compile/tree/main/backend/ml/"
    click DB "https://github.com/emmaashi/compile/blob/main/backend/instance/database.db"
    click FDocker "https://github.com/emmaashi/compile/blob/main/frontend/Dockerfile.frontend"
    click BDocker "https://github.com/emmaashi/compile/blob/main/backend/Dockerfile.backend"

    classDef client fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;
    classDef frontend fill:#f9d6bc,stroke:#d96b2f,stroke-width:2px;
    classDef backend fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef ml fill:#bbdefb,stroke:#1976d2,stroke-width:2px;
    classDef database fill:#ffe0b2,stroke:#fb8c00,stroke-width:2px;
    classDef docker fill:#c5cae9,stroke:#303f9f,stroke-width:2px;
```
