# petersem/gym architecture

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

- Interactive diagram: https://gitdiagram.com/petersem/gym
- Repository: https://github.com/petersem/gym

## Overview

Gym is a role-based fitness scheduling and booking application. Members and trainers use a mobile-first React app that calls the versioned JSON API: users authenticate, then browse sessions or bookings and perform role-allowed actions, including XML downloads. Guests can read/search blogs and register; members and trainers can manage blog posts and profiles. The backend also retains server-rendered page routes. Evidence for frontend-to-API behavior comes from the README and sampled frontend references; several API subsystems are represented by their existing directories because their implementation was not excerpted.

Main entry points: [`backend/src/controllers/api/APIController.mjs`](https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIController.mjs) (API routing), [`frontend/src/api.mjs`](https://github.com/petersem/gym/blob/main/frontend/src/api.mjs) (API client), [`backend/src/models/DatabaseModel.mjs`](https://github.com/petersem/gym/blob/main/backend/src/models/DatabaseModel.mjs) (MySQL pool), [`backend/src/models/UsersModel.mjs`](https://github.com/petersem/gym/blob/main/backend/src/models/UsersModel.mjs) (User records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React app"]
  node_react["React routes<br/>[main.jsx]"]
  node_authui["Authentication UI"]
  node_apiclient["API client<br/>[api.mjs]"]
  node_timetable["Timetable<br/>[TimetableView.jsx]"]
  node_bookingui["Booking management"]
  node_blogui["Blog views"]
  node_profileui["Profile view<br/>[ProfileView.jsx]"]
end

subgraph group_api["JSON API"]
  node_apiroot["API routing<br/>[APIController.mjs]"]
  node_apiauth["API authentication"]
  node_apiusers["User endpoints"]
  node_apisessions["Session endpoints"]
  node_apibookings["Booking endpoints"]
  node_apiblogs["Blog endpoints"]
  node_apilocations["Location endpoints"]
end

subgraph group_domain["Gym domain"]
  node_users["User records<br/>[UsersModel.mjs]"]
  node_sessions["Session records<br/>[SessionsModel.mjs]"]
  node_bookings["Booking records<br/>[BookingsModel.mjs]"]
  node_activities["Activity records"]
  node_locations["Location records<br/>[LocationModel.mjs]"]
  node_mysql[("MySQL pool<br/>[DatabaseModel.mjs]")]
  node_blogmodel["Blog records<br/>[BlogModel.mjs]"]
end

subgraph group_web["Server-rendered app"]
  node_browserroutes["Page controllers"]
  node_browserauth["Browser authentication"]
end

node_visitor(("Visitor"))

node_visitor -->|"uses"| node_react
node_react -->|"renders"| node_authui
node_authui -->|"requests"| node_apiclient
node_timetable -->|"requests"| node_apiclient
node_bookingui -->|"requests"| node_apiclient
node_blogui -->|"requests"| node_apiclient
node_profileui -->|"requests"| node_apiclient
node_apiclient -->|"calls"| node_apiroot
node_apiroot -->|"routes"| node_apiauth
node_apiroot -->|"routes"| node_apiusers
node_apiroot -->|"routes"| node_apisessions
node_apiroot -->|"routes"| node_apibookings
node_apiroot -->|"routes"| node_apiblogs
node_apiroot -->|"routes"| node_apilocations
node_apiauth -->|"reads/writes"| node_users
node_apisessions -->|"queries"| node_sessions
node_apibookings -->|"queries"| node_bookings
node_apibookings -->|"checks"| node_sessions
node_apiusers -.->|"manages"| node_users
node_apilocations -.->|"manages"| node_locations
node_apiblogs -.->|"manages"| node_blogmodel
node_users -->|"queries"| node_mysql
node_sessions -->|"queries"| node_mysql
node_bookings -.->|"queries"| node_mysql
node_activities -.->|"queries"| node_mysql
node_locations -.->|"queries"| node_mysql
node_blogmodel -.->|"queries"| node_mysql
node_visitor -.->|"uses"| node_browserroutes
node_browserroutes -->|"authenticates"| node_browserauth
node_browserauth -->|"authenticates against"| node_users

click node_react "https://github.com/petersem/gym/blob/main/frontend/src/main.jsx"
click node_authui "https://github.com/petersem/gym/blob/main/frontend/src/authentication/useAuthenticate.jsx"
click node_apiclient "https://github.com/petersem/gym/blob/main/frontend/src/api.mjs"
click node_timetable "https://github.com/petersem/gym/blob/main/frontend/src/sessions/TimetableView.jsx"
click node_bookingui "https://github.com/petersem/gym/blob/main/frontend/src/bookings/BookingListView.jsx"
click node_blogui "https://github.com/petersem/gym/tree/main/frontend/src/blogs"
click node_profileui "https://github.com/petersem/gym/blob/main/frontend/src/users/ProfileView.jsx"
click node_apiroot "https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIController.mjs"
click node_apiauth "https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIAuthenticationController.mjs"
click node_apiusers "https://github.com/petersem/gym/tree/main/backend/src/controllers/api"
click node_apisessions "https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APISessionsController.mjs"
click node_apibookings "https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIBookingsController.mjs"
click node_apiblogs "https://github.com/petersem/gym/tree/main/backend/src/controllers/api"
click node_apilocations "https://github.com/petersem/gym/tree/main/backend/src/controllers/api"
click node_users "https://github.com/petersem/gym/blob/main/backend/src/models/UsersModel.mjs"
click node_sessions "https://github.com/petersem/gym/blob/main/backend/src/models/SessionsModel.mjs"
click node_bookings "https://github.com/petersem/gym/blob/main/backend/src/models/BookingsModel.mjs"
click node_activities "https://github.com/petersem/gym/blob/main/backend/src/models/ActivitiesModel.mjs"
click node_locations "https://github.com/petersem/gym/blob/main/backend/src/models/LocationModel.mjs"
click node_mysql "https://github.com/petersem/gym/blob/main/backend/src/models/DatabaseModel.mjs"
click node_browserroutes "https://github.com/petersem/gym/tree/main/backend/src/controllers"
click node_browserauth "https://github.com/petersem/gym/blob/main/backend/src/controllers/AuthenticationController.mjs"
click node_blogmodel "https://github.com/petersem/gym/blob/main/backend/src/models/BlogModel.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_react,node_authui,node_apiclient,node_timetable,node_bookingui,node_blogui,node_profileui toneBlue
class node_apiroot,node_apiauth,node_apiusers,node_apisessions,node_apibookings,node_apiblogs,node_apilocations toneAmber
class node_users,node_sessions,node_bookings,node_activities,node_locations,node_mysql,node_blogmodel toneMint
class node_browserroutes,node_browserauth toneRose
class node_visitor toneIndigo
```

## Components

### React app

- [React routes](https://github.com/petersem/gym/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`
- [Authentication UI](https://github.com/petersem/gym/blob/main/frontend/src/authentication/useAuthenticate.jsx): `frontend/src/authentication/useAuthenticate.jsx`
- [API client](https://github.com/petersem/gym/blob/main/frontend/src/api.mjs): `frontend/src/api.mjs`
- [Timetable](https://github.com/petersem/gym/blob/main/frontend/src/sessions/TimetableView.jsx): `frontend/src/sessions/TimetableView.jsx`
- [Booking management](https://github.com/petersem/gym/blob/main/frontend/src/bookings/BookingListView.jsx): `frontend/src/bookings/BookingListView.jsx`
- [Blog views](https://github.com/petersem/gym/tree/main/frontend/src/blogs): `frontend/src/blogs`
- [Profile view](https://github.com/petersem/gym/blob/main/frontend/src/users/ProfileView.jsx): `frontend/src/users/ProfileView.jsx`

### JSON API

- [API routing](https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIController.mjs): `backend/src/controllers/api/APIController.mjs`
- [API authentication](https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIAuthenticationController.mjs): `backend/src/controllers/api/APIAuthenticationController.mjs`
- [User endpoints](https://github.com/petersem/gym/tree/main/backend/src/controllers/api): `backend/src/controllers/api`
- [Session endpoints](https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APISessionsController.mjs): `backend/src/controllers/api/APISessionsController.mjs`
- [Booking endpoints](https://github.com/petersem/gym/blob/main/backend/src/controllers/api/APIBookingsController.mjs): `backend/src/controllers/api/APIBookingsController.mjs`
- [Blog endpoints](https://github.com/petersem/gym/tree/main/backend/src/controllers/api): `backend/src/controllers/api`
- [Location endpoints](https://github.com/petersem/gym/tree/main/backend/src/controllers/api): `backend/src/controllers/api`

### Gym domain

- [User records](https://github.com/petersem/gym/blob/main/backend/src/models/UsersModel.mjs): `backend/src/models/UsersModel.mjs`
- [Session records](https://github.com/petersem/gym/blob/main/backend/src/models/SessionsModel.mjs): `backend/src/models/SessionsModel.mjs`
- [Booking records](https://github.com/petersem/gym/blob/main/backend/src/models/BookingsModel.mjs): `backend/src/models/BookingsModel.mjs`
- [Activity records](https://github.com/petersem/gym/blob/main/backend/src/models/ActivitiesModel.mjs): `backend/src/models/ActivitiesModel.mjs`
- [Location records](https://github.com/petersem/gym/blob/main/backend/src/models/LocationModel.mjs): `backend/src/models/LocationModel.mjs`
- [MySQL pool](https://github.com/petersem/gym/blob/main/backend/src/models/DatabaseModel.mjs): `backend/src/models/DatabaseModel.mjs`
- [Blog records](https://github.com/petersem/gym/blob/main/backend/src/models/BlogModel.mjs): `backend/src/models/BlogModel.mjs`

### Server-rendered app

- [Page controllers](https://github.com/petersem/gym/tree/main/backend/src/controllers): `backend/src/controllers`
- [Browser authentication](https://github.com/petersem/gym/blob/main/backend/src/controllers/AuthenticationController.mjs): `backend/src/controllers/AuthenticationController.mjs`

### Other components

- **Visitor**

## Connections

- Visitor → React routes: uses
- React routes → Authentication UI: renders (evidence: `frontend/src/main.jsx`)
- Authentication UI → API client: requests (evidence: `frontend/src/authentication/useAuthenticate.jsx`)
- Timetable → API client: requests (evidence: `frontend/src/sessions/TimetableView.jsx`)
- Booking management → API client: requests
- Blog views → API client: requests
- Profile view → API client: requests (evidence: `frontend/src/users/ProfileView.jsx`)
- API client → API routing: calls
- API routing → API authentication: routes (evidence: `backend/src/controllers/api/APIController.mjs`)
- API routing → User endpoints: routes (evidence: `backend/src/controllers/api/APIController.mjs`)
- API routing → Session endpoints: routes (evidence: `backend/src/controllers/api/APIController.mjs`)
- API routing → Booking endpoints: routes (evidence: `backend/src/controllers/api/APIController.mjs`)
- API routing → Blog endpoints: routes (evidence: `backend/src/controllers/api/APIController.mjs`)
- API routing → Location endpoints: routes (evidence: `backend/src/controllers/api/APIController.mjs`)
- API authentication → User records: reads/writes (evidence: `backend/src/controllers/api/APIAuthenticationController.mjs`)
- Session endpoints → Session records: queries (evidence: `backend/src/controllers/api/APISessionsController.mjs`)
- Booking endpoints → Booking records: queries (evidence: `backend/src/controllers/api/APIBookingsController.mjs`)
- Booking endpoints → Session records: checks (evidence: `backend/src/controllers/api/APIBookingsController.mjs`)
- User endpoints → User records: manages (evidence: `backend/src/controllers/api/APIAuthenticationController.mjs`)
- Location endpoints → Location records: manages (evidence: `backend/src/controllers/api/APISessionsController.mjs`)
- Blog endpoints → Blog records: manages
- User records → MySQL pool: queries (evidence: `backend/src/models/UsersModel.mjs`)
- Session records → MySQL pool: queries (evidence: `backend/src/models/SessionsModel.mjs`)
- Booking records → MySQL pool: queries (evidence: `backend/src/models/BookingsModel.mjs`)
- Activity records → MySQL pool: queries (evidence: `backend/src/models/ActivitiesModel.mjs`)
- Location records → MySQL pool: queries (evidence: `backend/src/models/LocationModel.mjs`)
- Blog records → MySQL pool: queries
- Visitor → Page controllers: uses
- Page controllers → Browser authentication: authenticates (evidence: `backend/src/server.mjs`)
- Browser authentication → User records: authenticates against (evidence: `backend/src/controllers/AuthenticationController.mjs`)
