# gabr1eeeel/iagym architecture

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

- Interactive diagram: https://gitdiagram.com/gabr1eeeel/iagym
- Repository: https://github.com/gabr1eeeel/iagym

## Overview

##### Project type and purpose
- This is a full-stack web application called **IAGym**, an intelligent gym management system.
- Purpose: provide CRUD operations for students (“alunos”), record check-ins, manage plans, and use a Random Forest model to predict churn risk.

##### File structure
- Top-level:
- `backend/`: Python API and worker code
- `frontend/`: React + TypeScript UI
- `docker-compose.yml`: orchestration of containers
- Backend substructure:
- `app/routes/`: REST endpoints (FastAPI)
- `app/models/`: SQLAlchemy entities (Aluno, Checkin, Plano)
- `app/services/`: business logic (e.g., churn_predictor)
- `app/workers/`: async processing via RabbitMQ
- `app/database.py`: DB connection
- `app/rabbitmq.py`: broker setup
- Frontend substructure:
- `src/pages/`: five page components (Home, Alunos, Checkin, Frequencia, Churn)
- `src/api.ts`: wrapper around REST calls
- `src/components/`: shared UI (Navbar)

##### README for additional insights
- Tech stack: FastAPI, SQLAlchemy, PostgreSQL, scikit-learn, RabbitMQ, React, Material-UI
- Architecture callout: REST API, ML model, message broker, Docker containers
- Async flows: check-ins produce events to RabbitMQ, workers consume and update churn analysis

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["External User (Browser)"]:::ui
        Frontend["Frontend UI (React)"]:::ui
    end

    %% Server Layer
    subgraph "Server Layer"
        subgraph "API Container"
            API["FastAPI Backend"]:::backend
        end
        subgraph "Data Stores"
            DB["PostgreSQL Database"]:::data
        end
        subgraph "Message Broker"
            RabbitMQ["RabbitMQ"]:::broker
        end
        subgraph "Worker Services"
            Worker["Event Processor"]:::broker
            ML["Churn Predictor"]:::broker
        end
    end

    %% Connections
    Browser -->|"HTTP:3000"| Frontend
    Frontend -->|"REST HTTP:8000"| API
    API -->|"SQL over TCP"| DB
    API -->|"AMQP publish to checkins"| RabbitMQ
    RabbitMQ -->|"consume checkins"| Worker
    Worker -->|"invoke after 10 events"| ML
    Worker -->|"write churn scores"| DB
    API -->|"in-process churn_predictor"| ML

    %% Click Events
    click Frontend "https://github.com/gabr1eeeel/iagym/tree/main/frontend/"
    click API "https://github.com/gabr1eeeel/iagym/blob/main/backend/app/main.py"
    click DB "https://github.com/gabr1eeeel/iagym/blob/main/backend/app/database.py"
    click RabbitMQ "https://github.com/gabr1eeeel/iagym/blob/main/backend/app/rabbitmq.py"
    click Worker "https://github.com/gabr1eeeel/iagym/blob/main/backend/app/workers/event_processor.py"
    click ML "https://github.com/gabr1eeeel/iagym/blob/main/backend/app/services/churn_predictor.py"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef broker fill:#DDA0DD,stroke:#000,stroke-width:1px
```
