# adala-wanyande/afya-one architecture

> Architecture diagram of the GitHub repository adala-wanyande/afya-one, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adala-wanyande/afya-one
- Repository: https://github.com/adala-wanyande/afya-one

## Overview

##### Project Type and Purpose
- Afya One is a full-stack, single-page health & fitness tracking application built with React on the front end, and Firebase services (Authentication, Firestore, Cloud Functions) as its back end.
- Its main purpose is to let users sign up/in, record workouts, nutrition, and weight entries, and view a dashboard with interactive charts and contribution graphs.

##### File Structure
- Top-level: package.json, public/ (static HTML, manifest, robots.txt), src/ (React code), firebase-config.js, src/functions/auth.js (Cloud Functions).
- src/components/ and src/pages/ reflect a component-driven UI organized by feature area (auth, dashboard, nutrition, training, user, weight, workout).
- src/lib/utils.js is a shared utility layer.
- Tailwind config, CSS input/output files, and component JSON hint at theming and design system usage.

##### README for Additional Insights
- Confirms technology stack: React, React Router, Tailwind CSS, Chart.js, react-github-contribution-calendar, Firebase Auth & Firestore.

##### Main Components & Interactions
a. Presentation Layer (Client/Browser)
- index.html → index.js → App.js → React Router → pages & UI components
- UI library: Tailwind CSS + custom components (buttons, alerts, table, calendar, nav menu, popover)
b. Service Layer (API/Business Logic)
- firebase-config.js orchestrates Auth, Firestore, Storage
c. Data Layer
- Collections: users, workouts, nutrition, weightEntries
d. External Libraries/Services
- Chart.js for charts
- react-github-contribution-calendar for contribution graph
e. Hosting & Delivery
- Static hosting (Firebase Hosting / any CDN) serving public/index.html and bundled JS/CSS

##### Architectural Patterns & Design Principles
- Component-driven UI: each feature under src/pages + reusable components in src/components/ui
- Separation of concerns: presentation (React), services (Firebase SDK), data storage (Firestore)
- Service abstraction: all Firebase calls centrally configured in firebase-config.js and wrapped by utility functions in src/lib/utils.js
- Responsive design with Tailwind CSS utility classes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser[/"Browser"/]:::gray
    Browser --> ReactSPA["React SPA"]:::frontend

    subgraph "React SPA"
        IndexHTML["index.html"]:::frontend
        IndexJS["index.js"]:::frontend
        AppJS["App.js"]:::frontend
        IndexHTML --> IndexJS
        IndexJS --> AppJS
        AppJS --> Router["React Router"]:::frontend

        subgraph "Pages"
            SignIn["SignIn"]:::frontend
            SignUp["SignUp"]:::frontend
            ForgotPW["ForgotPassword"]:::frontend
            Dashboard["Dashboard"]:::frontend
            UserInsights["UserInsightsPanel"]:::frontend
            CreateNut["CreateNutrition"]:::frontend
            ViewNut["ViewNutrition"]:::frontend
            CreateTrain["CreateTrainingSplit"]:::frontend
            UpdateTrain["UpdateTrainingSplit"]:::frontend
            ViewTrain["ViewTrainingSplits"]:::frontend
            CreateUser["CreateUserInfo"]:::frontend
            UpdateUser["UpdateUserInfo"]:::frontend
            ViewUser["ViewUserInfo"]:::frontend
            CreateWeight["CreateWeight"]:::frontend
            UpdateWeight["UpdateWeight"]:::frontend
            ViewWeights["ViewWeights"]:::frontend
            CreateWorkout["CreateWorkout"]:::frontend
            UpdateWorkout["UpdateWorkout"]:::frontend
            ViewWorkouts["ViewWorkouts"]:::frontend
        end

        AppJS --> Pages

        subgraph "UI Components"
            AlertUI["alert.jsx"]:::frontend
            ErrorAlert["ErrorAlert"]:::frontend
            ButtonUI["button.jsx"]:::frontend
            LoadingBtn["LoadingButton"]:::frontend
            CalendarUI["calendar.jsx"]:::frontend
            NavMenu["navigation-menu.jsx"]:::frontend
            NavBar["NavBar"]:::frontend
            PopoverUI["popover.jsx"]:::frontend
            TableUI["table.jsx"]:::frontend
            DatePicker["DatePicker.js"]:::frontend
        end

        Pages --> UIComponents
    end

    %% Service Layer
    subgraph "Service Layer"
        FirebaseSDK["Firebase SDK"]:::backend
        Utils["utils.js"]:::backend
        AuthFunc["Cloud Functions"]:::backend
    end

    ReactSPA --> FirebaseSDK
    FirebaseSDK --> Utils
    AuthFunc --> FirebaseSDK

    %% Data Layer
    subgraph "Data Layer"
        Firestore[(Firestore DB)]:::db
        FirestoreCollectionUsers["users Collection"]:::db
        FirestoreCollectionWorkouts["workouts Collection"]:::db
        FirestoreCollectionNutrition["nutrition Collection"]:::db
        FirestoreCollectionWeight["weightEntries Collection"]:::db
        Firestore --> FirestoreCollectionUsers
        Firestore --> FirestoreCollectionWorkouts
        Firestore --> FirestoreCollectionNutrition
        Firestore --> FirestoreCollectionWeight
    end

    FirebaseSDK --> Firestore

    %% External Libraries
    ChartJS[(Chart.js)]:::external
    ContribCal[(GitHub Contribution Calendar)]:::external
    Dashboard --> ChartJS
    CalendarUI --> ContribCal

    %% Hosting & Delivery
    CDN[/"Hosting/CDN"/]:::gray
    CDN --> Browser

    %% Click Events
    click IndexHTML "https://github.com/adala-wanyande/afya-one/blob/master/public/index.html"
    click IndexJS "https://github.com/adala-wanyande/afya-one/blob/master/src/index.js"
    click AppJS "https://github.com/adala-wanyande/afya-one/blob/master/src/App.js"
    click SignIn "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/auth/SignIn.js"
    click SignUp "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/auth/SignUp.js"
    click ForgotPW "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/auth/ForgotPassword.js"
    click Dashboard "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/dashboard/Dashboard.js"
    click UserInsights "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/dashboard/UserInsightsPanel.js"
    click CreateNut "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/nutrition/CreateNutrition.js"
    click ViewNut "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/nutrition/ViewNutrition.js"
    click CreateTrain "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/training/CreateTrainingSplit.js"
    click UpdateTrain "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/training/UpdateTrainingSplit.js"
    click ViewTrain "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/training/ViewTrainingSplits.js"
    click CreateUser "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/user/CreateUserInfo.js"
    click UpdateUser "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/user/UpdateUserInfo.js"
    click ViewUser "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/user/ViewUserInfo.js"
    click CreateWeight "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/weight/CreateWeight.js"
    click UpdateWeight "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/weight/UpdateWeight.js"
    click ViewWeights "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/weight/ViewWeights.js"
    click CreateWorkout "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/workout/CreateWorkout.js"
    click UpdateWorkout "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/workout/UpdateWorkout.js"
    click ViewWorkouts "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/workout/ViewWorkouts.js"
    click AlertUI "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/alert.jsx"
    click ErrorAlert "https://github.com/adala-wanyande/afya-one/blob/master/src/components/alerts/ErrorAlert.js"
    click ButtonUI "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/button.jsx"
    click LoadingBtn "https://github.com/adala-wanyande/afya-one/blob/master/src/components/buttons/LoadingButton.js"
    click CalendarUI "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/calendar.jsx"
    click NavMenu "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/navigation-menu.jsx"
    click NavBar "https://github.com/adala-wanyande/afya-one/blob/master/src/components/navigation/NavBar.js"
    click PopoverUI "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/popover.jsx"
    click TableUI "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/table.jsx"
    click DatePicker "https://github.com/adala-wanyande/afya-one/blob/master/src/components/forms/DatePicker.js"
    click Utils "https://github.com/adala-wanyande/afya-one/blob/master/src/lib/utils.js"
    click FirebaseSDK "https://github.com/adala-wanyande/afya-one/blob/master/firebase-config.js"
    click AuthFunc "https://github.com/adala-wanyande/afya-one/blob/master/src/functions/auth.js"
    click ChartJS "https://github.com/adala-wanyande/afya-one/blob/master/src/pages/dashboard/Dashboard.js"
    click ContribCal "https://github.com/adala-wanyande/afya-one/blob/master/src/components/ui/calendar.jsx"
    click CDN "https://github.com/adala-wanyande/afya-one/blob/master/public/index.html"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#D5F5E5,stroke:#28a745,color:#28a745
    classDef db fill:#FDF2E9,stroke:#d35400,color:#d35400
    classDef external fill:#FEF9E7,stroke:#f1c40f,color:#d4aa00
    classDef gray fill:#ECECEC,stroke:#7f8c8d,color:#7f8c8d
```
