# lucasfluz/battlerank architecture

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

- Interactive diagram: https://gitdiagram.com/lucasfluz/battlerank
- Repository: https://github.com/lucasfluz/battlerank

## Overview

battleRank is a social fitness platform for planning workouts, recording completed sessions and tracking progress alongside other athletes. The principal workflow runs from workout planning through exercise setup and live session logging to saved history; community feed, athlete following and rankings are parallel capabilities documented or represented in the repository. The frontend and backend excerpts support several concrete calls, but many page and social-service implementations were not sampled, so those links are omitted or marked unverified.

Main entry points: [`backend/src/routes/workoutRoutes.ts`](https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/workoutRoutes.ts) (Workout routes), [`frontend/src/services/api.ts`](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/services/api.ts) (HTTP client), [`frontend/src/hooks/useSessions.ts`](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/hooks/useSessions.ts) (Data hooks), [`backend/src/services/sessionService.ts`](https://github.com/lucasfluz/battlerank/blob/main/backend/src/services/sessionService.ts) (Session processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_web["Web app<br/>[App.tsx]"]
  node_authui["Authentication<br/>[AuthContext.tsx]"]
  node_workoutui["Workout planning<br/>[index.tsx]"]
  node_exerciseui["Exercise setup"]
  node_liveui["Live workout<br/>[index.tsx]"]
  node_historyui["History and progress<br/>[index.tsx]"]
  node_communityui["Community and rankings<br/>[index.tsx]"]
  node_hooks["Data hooks<br/>[useSessions.ts]"]
  node_frontendservices["API services<br/>[sessionService.ts]"]
  node_http["HTTP client<br/>[api.ts]"]
end

subgraph group_api["API and domain"]
  node_routes["API routing<br/>[index.ts]"]
  node_workoutroutes["Workout routes<br/>[workoutRoutes.ts]"]
  node_workoutcontroller["Workout controller"]
  node_workoutservice["Workout rules<br/>[workoutService.ts]"]
  node_exercisectrl["Exercise management"]
  node_sessionctrl["Session management"]
  node_sessionrules["Session processing<br/>[sessionService.ts]"]
  node_authctrl["Account API<br/>[authController.ts]"]
end

subgraph group_social["Social fitness"]
  node_socialroutes["Social routes<br/>[socialRoutes.ts]"]
  node_socialctrl["Social features"]
end

subgraph group_data["Persistence"]
  node_sessionrepo["Session records"]
  node_workoutrepo["Workout records"]
  node_db[("PostgreSQL")]
end

node_athlete(("Athlete"))

node_athlete -->|"uses"| node_web
node_web -->|"provides"| node_authui
node_authui -->|"configures"| node_http
node_workoutui -.->|"requests data"| node_hooks
node_exerciseui -.->|"requests data"| node_hooks
node_liveui -.->|"saves session"| node_hooks
node_historyui -.->|"loads history"| node_hooks
node_hooks -->|"calls"| node_frontendservices
node_frontendservices -->|"sends requests"| node_http
node_http -->|"posts session"| node_workoutroutes
node_routes -->|"mounts"| node_workoutroutes
node_workoutroutes -->|"dispatches"| node_workoutcontroller
node_workoutroutes -->|"dispatches"| node_exercisectrl
node_workoutroutes -->|"dispatches"| node_sessionctrl
node_workoutcontroller -->|"delegates to"| node_workoutservice
node_workoutservice -->|"uses"| node_workoutrepo
node_sessionctrl -->|"delegates to"| node_sessionrules
node_sessionrules -->|"saves and reads"| node_sessionrepo
node_sessionrules -->|"checks ownership"| node_workoutrepo
node_sessionrepo -->|"reads and writes"| node_db
node_workoutrepo -->|"reads and writes"| node_db
node_authctrl -->|"accesses accounts"| node_db
node_communityui -.->|"requests social data"| node_http
node_http -.->|"requests social endpoints"| node_socialroutes
node_routes -->|"mounts"| node_socialroutes
node_socialroutes -->|"dispatches"| node_socialctrl
node_socialctrl -->|"reads and updates"| node_db

click node_web "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/App.tsx"
click node_authui "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/context/AuthContext.tsx"
click node_workoutui "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/Workouts/index.tsx"
click node_exerciseui "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/components/exercises/ExerciseFormModal.tsx"
click node_liveui "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/WorkoutLive/index.tsx"
click node_historyui "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/History/index.tsx"
click node_communityui "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/Community/index.tsx"
click node_hooks "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/hooks/useSessions.ts"
click node_frontendservices "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/services/sessionService.ts"
click node_http "https://github.com/lucasfluz/battlerank/blob/main/frontend/src/services/api.ts"
click node_routes "https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/index.ts"
click node_workoutroutes "https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/workoutRoutes.ts"
click node_workoutcontroller "https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/workoutController.ts"
click node_workoutservice "https://github.com/lucasfluz/battlerank/blob/main/backend/src/services/workoutService.ts"
click node_exercisectrl "https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/exerciseController.ts"
click node_sessionctrl "https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/sessionController.ts"
click node_sessionrules "https://github.com/lucasfluz/battlerank/blob/main/backend/src/services/sessionService.ts"
click node_sessionrepo "https://github.com/lucasfluz/battlerank/blob/main/backend/src/repositories/sessionRepository.ts"
click node_workoutrepo "https://github.com/lucasfluz/battlerank/blob/main/backend/src/repositories/workoutRepository.ts"
click node_authctrl "https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/authController.ts"
click node_socialroutes "https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/socialRoutes.ts"
click node_socialctrl "https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/socialController.ts"

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_web,node_authui,node_workoutui,node_exerciseui,node_liveui,node_historyui,node_communityui,node_hooks,node_frontendservices,node_http toneBlue
class node_routes,node_workoutroutes,node_workoutcontroller,node_workoutservice,node_exercisectrl,node_sessionctrl,node_sessionrules,node_authctrl toneAmber
class node_socialroutes,node_socialctrl toneMint
class node_sessionrepo,node_workoutrepo,node_db toneRose
class node_athlete toneIndigo
```

## Components

### Web application

- [Web app](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Authentication](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Workout planning](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/Workouts/index.tsx): `frontend/src/pages/Workouts/index.tsx`
- [Exercise setup](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/components/exercises/ExerciseFormModal.tsx): `frontend/src/components/exercises/ExerciseFormModal.tsx`
- [Live workout](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/WorkoutLive/index.tsx): `frontend/src/pages/WorkoutLive/index.tsx`
- [History and progress](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/History/index.tsx): `frontend/src/pages/History/index.tsx`
- [Community and rankings](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/pages/Community/index.tsx): `frontend/src/pages/Community/index.tsx`
- [Data hooks](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/hooks/useSessions.ts): `frontend/src/hooks/useSessions.ts`
- [API services](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/services/sessionService.ts): `frontend/src/services/sessionService.ts`
- [HTTP client](https://github.com/lucasfluz/battlerank/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### API and domain

- [API routing](https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/index.ts): `backend/src/routes/index.ts`
- [Workout routes](https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/workoutRoutes.ts): `backend/src/routes/workoutRoutes.ts`
- [Workout controller](https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/workoutController.ts): `backend/src/controllers/workoutController.ts`
- [Workout rules](https://github.com/lucasfluz/battlerank/blob/main/backend/src/services/workoutService.ts): `backend/src/services/workoutService.ts`
- [Exercise management](https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/exerciseController.ts): `backend/src/controllers/exerciseController.ts`
- [Session management](https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/sessionController.ts): `backend/src/controllers/sessionController.ts`
- [Session processing](https://github.com/lucasfluz/battlerank/blob/main/backend/src/services/sessionService.ts): `backend/src/services/sessionService.ts`
- [Account API](https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/authController.ts): `backend/src/controllers/authController.ts`

### Social fitness

- [Social routes](https://github.com/lucasfluz/battlerank/blob/main/backend/src/routes/socialRoutes.ts): `backend/src/routes/socialRoutes.ts`
- [Social features](https://github.com/lucasfluz/battlerank/blob/main/backend/src/controllers/socialController.ts): `backend/src/controllers/socialController.ts`

### Persistence

- [Session records](https://github.com/lucasfluz/battlerank/blob/main/backend/src/repositories/sessionRepository.ts): `backend/src/repositories/sessionRepository.ts`
- [Workout records](https://github.com/lucasfluz/battlerank/blob/main/backend/src/repositories/workoutRepository.ts): `backend/src/repositories/workoutRepository.ts`
- **PostgreSQL**

### Other components

- **Athlete**

## Connections

- Athlete → Web app: uses
- Web app → Authentication: provides (evidence: `frontend/src/App.tsx`)
- Authentication → HTTP client: configures (evidence: `frontend/src/context/AuthContext.tsx`)
- Workout planning → Data hooks: requests data
- Exercise setup → Data hooks: requests data
- Live workout → Data hooks: saves session
- History and progress → Data hooks: loads history
- Data hooks → API services: calls (evidence: `frontend/src/hooks/useSessions.ts`)
- API services → HTTP client: sends requests (evidence: `frontend/src/services/sessionService.ts`)
- HTTP client → Workout routes: posts session
- API routing → Workout routes: mounts (evidence: `backend/src/routes/index.ts`)
- Workout routes → Workout controller: dispatches (evidence: `backend/src/routes/workoutRoutes.ts`)
- Workout routes → Exercise management: dispatches (evidence: `backend/src/routes/workoutRoutes.ts`)
- Workout routes → Session management: dispatches (evidence: `backend/src/routes/workoutRoutes.ts`)
- Workout controller → Workout rules: delegates to (evidence: `backend/src/controllers/workoutController.ts`)
- Workout rules → Workout records: uses (evidence: `backend/src/services/workoutService.ts`)
- Session management → Session processing: delegates to (evidence: `backend/src/controllers/sessionController.ts`)
- Session processing → Session records: saves and reads (evidence: `backend/src/services/sessionService.ts`)
- Session processing → Workout records: checks ownership (evidence: `backend/src/services/sessionService.ts`)
- Session records → PostgreSQL: reads and writes (evidence: `backend/src/repositories/sessionRepository.ts`)
- Workout records → PostgreSQL: reads and writes (evidence: `backend/src/repositories/workoutRepository.ts`)
- Account API → PostgreSQL: accesses accounts (evidence: `backend/src/controllers/authController.ts`)
- Community and rankings → HTTP client: requests social data
- HTTP client → Social routes: requests social endpoints
- API routing → Social routes: mounts (evidence: `backend/src/routes/index.ts`)
- Social routes → Social features: dispatches (evidence: `backend/src/routes/socialRoutes.ts`)
- Social features → PostgreSQL: reads and updates (evidence: `backend/src/controllers/socialController.ts`)
