# fdilmr/running_companion architecture

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

- Interactive diagram: https://gitdiagram.com/fdilmr/running_companion
- Repository: https://github.com/fdilmr/running_companion

## Overview

##### Project Overview and Identification
- This is a full-stack application that serves as a personalized running companion. Its core functionality includes integrating with Strava to import running data, authenticating users, and providing predictive race analytics.
- The README and file tree indicate that the system combines a Python backend (using FastAPI or a similar framework), a JavaScript-based frontend (React), and additional modules (in the “second_part” directory) for data analytics, model training, and visualization.

##### High-Level Components
a. Frontend:
- The “frontend” directory shows the implementation of the user interface built with React.
- Key elements include public assets, React components, and services (API, auth, and Strava integrations) that provide connectivity to the backend.

b. Backend:
- The “backend” directory includes the FastAPI application (evidenced by files like app/main.py and utility modules).
- This portion handles:
- User Authentication (routes/auth.py),
- Strava data integration and other specialized endpoints (lambda_strava, lambda_user, and others),
- Data access and model management (models directory) and database interactions (see dynamodb.py in the database folder).
- It also has an extensive tests setup, build scripts, and configuration files (e.g., Procfile and requirements.txt).

c. Data Processing and Analytics:
- The “second_part” directory contains scripts and Jupyter notebooks for:
- Fetching and processing athlete data,
- Transforming and analyzing running activities,
- Race predictions and model training (race_prediction.py, train_model.py, etc.).
- This module integrates with external data sources (e.g., JSON files, SQL methods) and utilizes notebooks for iterative model development and visualization.

d. Additional Services and Cloud Integration:
- The README and configuration files (docker-compose.yml, dockerfile, buildspec.yml) imply deployment on AWS.
- Components to include:
- AWS EC2 or container service for backend deployment,
- AWS Lambda or SageMaker for model serving,
- AWS S3 for storing raw data and possibly hosting the frontend static assets,
- AWS services such as API Gateway and Cognito for authentication and routing if applicable.

##### Relationships and Interactions
- Connection between the backend and external services:
- The backend interacts with a NoSQL/SQL database (possibly PostgreSQL) and DynamoDB (as seen in dynamodb.py).
- Interactions with AWS Lambda for model predictions.

##### Architectural Patterns and Design Principles
- Separation of concerns by clearly segmenting the frontend, backend, and analytics modules.
- Use a microservices or modular architecture pattern where the backend services (authentication, Strava data processing, prediction) are represented as independent route modules.
- Optionally, show integration points for CI/CD pipelines (e.g., GitHub workflows, Docker configurations) and deployment automation onto AWS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A1("React Client (UI)"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1("FastAPI Server"):::backend
        B2("Auth Module"):::backend
        B3("Strava Integration"):::backend
        B4("Database Connector"):::backend
    end

    %% Analytics Layer
    subgraph "Analytics Layer"
        C1("Data Processing Module"):::analytics
    end

    %% AWS Cloud Components
    subgraph "AWS Cloud"
        D1("AWS EC2/Container Services"):::aws
        D2("AWS Lambda"):::aws
        D3("AWS S3"):::aws
        D4("API Gateway/Cognito"):::aws
    end

    %% Deployment Artifacts / CI-CD
    subgraph "Deployment Artifacts"
        E1("buildspec.yml"):::aws
        E2("docker-compose.yml"):::aws
        E3("dockerfile"):::aws
        E4("Procfile"):::aws
    end

    %% External Services
    X1("Strava API External"):::external

    %% Relationships and Data Flow
    A1 -->|"REST_API"| B1
    B1 -->|"AuthCalls"| B2
    B1 -->|"StravaData"| B3
    B1 -->|"DB_Calls"| B4
    B3 -->|"Fetch_Data"| X1
    B1 -->|"Deploys_to"| D1
    B1 -->|"Invokes"| D2
    B1 -->|"Stores_to"| D3
    B2 -->|"Uses"| D4
    C1 -->|"Provides_Insights"| B1
    A1 -->|"Displays_Insights"| C1
    E1 -->|"Deploys_with"| D1
    E2 -->|"Deploys_with"| D1
    E3 -->|"Deploys_with"| D1
    E4 -->|"Deploys_with"| D1

    %% Click Events
    click A1 "https://github.com/fdilmr/running_companion/tree/main/frontend/"
    click B1 "https://github.com/fdilmr/running_companion/tree/main/backend/app/"
    click C1 "https://github.com/fdilmr/running_companion/tree/main/second_part/"
    click E1 "https://github.com/fdilmr/running_companion/blob/main/buildspec.yml"
    click E2 "https://github.com/fdilmr/running_companion/blob/main/docker-compose.yml"
    click E3 "https://github.com/fdilmr/running_companion/tree/main/dockerfile"
    click E4 "https://github.com/fdilmr/running_companion/tree/main/backend/Procfile"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef analytics fill:#cfc,stroke:#333,stroke-width:2px;
    classDef aws fill:#fc9,stroke:#333,stroke-width:2px;
    classDef external fill:#faa,stroke:#333,stroke-width:2px;
```
