# leanlag87/gymapp architecture

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

- Interactive diagram: https://gitdiagram.com/leanlag87/gymapp
- Repository: https://github.com/leanlag87/gymapp

## Overview

#### 1. Purpose and Runtime Topology
GymControl is a Yarn monorepo for gym operations: authentication, users/roles, members, trainers, check-ins, membership state, and payments. It runs a Next.js frontend, NestJS REST API, PostgreSQL, and Nginx reverse proxy/static server through Docker. Primary deployment definitions: `docker-compose.yaml`, `Dockerfile.backend`, `Dockerfile.frontend`, `ngnix.conf`.

#### 2. Entrypoints and Composition
The backend starts from `apps/backend/src/main.ts`; Nest dependency composition is centralized in `apps/backend/src/app.module.ts`. HTTP is organized by feature presentation modules/controllers under `apps/backend/src/presentation/`. The frontend uses the Next App Router, rooted at `apps/frontend/app/layout.tsx`, with public landing, login, and dashboard routes in `apps/frontend/app/page.tsx`, `apps/frontend/app/login/page.tsx`, and `apps/frontend/app/dashboard/page.tsx`.

#### 3. Framework-Independent Domain Core
`domain/` is the clean-architecture center and owns business types, rules, use cases, and dependency contracts; it should not depend on Nest, Prisma, or UI. Core aggregates include `domain/src/entities/Member.ts`, `domain/src/entities/Payment.ts`, and `domain/src/entities/User.ts`. Repository and infrastructure seams are declared in `domain/src/repositories/member-repository.ts`, `domain/src/repositories/payment-repository.ts`, and `domain/src/ports/password-hasher.ts`.

#### 4. Membership and Payment Lifecycle
Member registration, credential creation, and status transitions are domain use cases in `domain/src/use-cases/members/register-member.ts`, `domain/src/use-cases/members/create-credentials-for-member.ts`, and `domain/src/use-cases/members/change-member-status.ts`. Payment processing and membership updates are separated into `domain/src/use-cases/payments/process-payment.ts`, `domain/src/use-cases/payments/validate-payment.ts`, and `domain/src/use-cases/payments/update-membership.ts`. Membership validity logic is isolated in `domain/src/services/business-rules/verify-membership-status.ts`, allowing status policies to evolve independently of delivery and storage.

#### 5. API Boundary, Authentication, and Authorization
Nest controllers validate/translate HTTP DTOs, invoke application services, and expose feature endpoints. Key boundaries are `apps/backend/src/presentation/auth/auth.controller.ts`, `apps/backend/src/presentation/members/members.controller.ts`, and `apps/backend/src/presentation/payments/payments.controller.ts`. JWT authentication and role enforcement occur before protected endpoints via `apps/backend/src/presentation/auth/guards/jwt-auth.guard.ts` and `apps/backend/src/presentation/auth/guards/roles.guard.ts`. Application orchestration sits between controllers and domain logic in `apps/backend/src/application/auth/auth.service.ts`, `apps/backend/src/application/members/members.service.ts`, and `apps/backend/src/application/payments/payments.service.ts`.

#### 6. Persistence and Concrete Adapters
PostgreSQL persistence is modeled and migrated with Prisma via `apps/backend/prisma/schema.prisma` and `apps/backend/prisma/migrations/`. Nest accesses Prisma through `apps/backend/src/infrastructure/database/prisma/prisma.service.ts`; repository implementations satisfy domain contracts, including `apps/backend/src/infrastructure/repositories/prisma-member.repository.ts`, `apps/backend/src/infrastructure/repositories/prisma-payment.repository.ts`, and `apps/backend/src/infrastructure/repositories/prisma-user.repository.ts`. Security and identity implementations are infrastructure adapters: `apps/backend/src/infrastructure/security/bcrypt-password-hasher.ts` and `apps/backend/src/infrastructure/security/uuid-id-generator.ts`.

#### 7. Frontend Integration Boundary
The frontend’s authenticated client state is managed by `apps/frontend/contexts/auth-context.tsx`; backend communication is abstracted through `apps/frontend/contexts/api-context.tsx` and `apps/frontend/hooks/use-api.ts`. Route protection is a client-side boundary in `apps/frontend/components/auth/protected-route.tsx`. It also has an internal health proxy endpoint at `apps/frontend/app/api/health/route.ts`, while operational backend health is provided by `apps/backend/src/presentation/health/health.controller.ts`.

Main entry points: [`apps/frontend/app/layout.tsx`](https://github.com/leanlag87/gymapp/blob/main/apps/frontend/app/layout.tsx) (App Router routes), [`apps/backend/src/application/members/members.service.ts`](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/application/members/members.service.ts) (Application services), [`docker-compose.yaml`](https://github.com/leanlag87/gymapp/blob/main/docker-compose.yaml) (Docker Compose), [`apps/backend/src/presentation/members/members.controller.ts`](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/members/members.controller.ts) (Feature controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_compose{{"Docker Compose<br/>deployment"}}
  node_proxy["Nginx<br/>reverse proxy<br/>[ngnix.conf]"]
end

subgraph group_frontend["Next.js Frontend"]
  node_frontend_routes["App Router routes<br/>Next.js routes<br/>[layout.tsx]"]
  node_auth_context["Auth client state<br/>React context<br/>[auth-context.tsx]"]
  node_api_client["API client boundary<br/>React context and hook<br/>[api-context.tsx]"]
  node_route_protection["Protected routes<br/>client auth guard"]
  node_frontend_health["Health proxy<br/>Next.js route handler<br/>[route.ts]"]
end

subgraph group_backend["NestJS Backend"]
  node_nest_bootstrap["Nest bootstrap<br/>API entrypoint<br/>[main.ts]"]
  node_app_module["Application module<br/>Nest composition<br/>[app.module.ts]"]
  node_controllers["Feature controllers<br/>HTTP presentation"]
  node_auth_guards["JWT and role guards<br/>authorization boundary<br/>[jwt-auth.guard.ts]"]
  node_application_services["Application services<br/>use-case orchestration<br/>[members.service.ts]"]
  node_backend_health["Backend health<br/>health controller"]
end

subgraph group_domain["Domain Core"]
  node_entities["Business aggregates<br/>domain entities<br/>[Member.ts]"]
  node_member_lifecycle["Member lifecycle<br/>domain use cases<br/>[register-member.ts]"]
  node_payment_lifecycle["Payment lifecycle<br/>domain use cases<br/>[process-payment.ts]"]
  node_membership_policy["Membership policy<br/>business rule"]
  node_repository_contracts["Repository contracts<br/>domain ports"]
end

subgraph group_data["Persistence"]
  node_prisma_repositories["Prisma repositories<br/>repository adapters"]
  node_prisma["Prisma data access<br/>ORM service and schema<br/>[prisma.service.ts]"]
  node_postgres[("PostgreSQL<br/>database<br/>[schema.prisma]")]
end

node_compose -->|"runs"| node_proxy
node_compose -->|"runs"| node_frontend_routes
node_compose -->|"runs"| node_nest_bootstrap
node_compose -->|"runs"| node_postgres
node_proxy -->|"serves"| node_frontend_routes
node_proxy -->|"proxies API"| node_nest_bootstrap
node_frontend_routes -->|"uses"| node_auth_context
node_frontend_routes -->|"protects dashboard"| node_route_protection
node_frontend_routes -->|"calls through"| node_api_client
node_frontend_health -->|"proxies"| node_backend_health
node_api_client -->|"HTTP requests"| node_controllers
node_nest_bootstrap -->|"boots"| node_app_module
node_app_module -->|"composes"| node_controllers
node_app_module -->|"wires"| node_application_services
node_controllers -->|"protected by"| node_auth_guards
node_controllers -->|"invokes"| node_application_services
node_application_services -->|"orchestrates"| node_member_lifecycle
node_application_services -->|"orchestrates"| node_payment_lifecycle
node_member_lifecycle -->|"applies rules to"| node_entities
node_payment_lifecycle -->|"validates via"| node_membership_policy
node_member_lifecycle -.->|"depends on"| node_repository_contracts
node_payment_lifecycle -.->|"depends on"| node_repository_contracts
node_prisma_repositories -.->|"implements"| node_repository_contracts
node_application_services -->|"uses adapters"| node_prisma_repositories
node_prisma_repositories -->|"persists through"| node_prisma
node_prisma -->|"reads and writes"| node_postgres

click node_compose "https://github.com/leanlag87/gymapp/blob/main/docker-compose.yaml"
click node_proxy "https://github.com/leanlag87/gymapp/blob/main/ngnix.conf"
click node_frontend_routes "https://github.com/leanlag87/gymapp/blob/main/apps/frontend/app/layout.tsx"
click node_auth_context "https://github.com/leanlag87/gymapp/blob/main/apps/frontend/contexts/auth-context.tsx"
click node_api_client "https://github.com/leanlag87/gymapp/blob/main/apps/frontend/contexts/api-context.tsx"
click node_route_protection "https://github.com/leanlag87/gymapp/blob/main/apps/frontend/components/auth/protected-route.tsx"
click node_frontend_health "https://github.com/leanlag87/gymapp/blob/main/apps/frontend/app/api/health/route.ts"
click node_nest_bootstrap "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/main.ts"
click node_app_module "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/app.module.ts"
click node_controllers "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/members/members.controller.ts"
click node_auth_guards "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/auth/guards/jwt-auth.guard.ts"
click node_application_services "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/application/members/members.service.ts"
click node_backend_health "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/health/health.controller.ts"
click node_entities "https://github.com/leanlag87/gymapp/blob/main/domain/src/entities/Member.ts"
click node_member_lifecycle "https://github.com/leanlag87/gymapp/blob/main/domain/src/use-cases/members/register-member.ts"
click node_payment_lifecycle "https://github.com/leanlag87/gymapp/blob/main/domain/src/use-cases/payments/process-payment.ts"
click node_membership_policy "https://github.com/leanlag87/gymapp/blob/main/domain/src/services/business-rules/verify-membership-status.ts"
click node_repository_contracts "https://github.com/leanlag87/gymapp/blob/main/domain/src/repositories/member-repository.ts"
click node_prisma_repositories "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/infrastructure/repositories/prisma-member.repository.ts"
click node_prisma "https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/infrastructure/database/prisma/prisma.service.ts"
click node_postgres "https://github.com/leanlag87/gymapp/blob/main/apps/backend/prisma/schema.prisma"

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_compose,node_proxy toneBlue
class node_frontend_routes,node_auth_context,node_api_client,node_route_protection,node_frontend_health toneAmber
class node_nest_bootstrap,node_app_module,node_controllers,node_auth_guards,node_application_services,node_backend_health toneMint
class node_entities,node_member_lifecycle,node_payment_lifecycle,node_membership_policy,node_repository_contracts toneRose
class node_prisma_repositories,node_prisma,node_postgres toneIndigo
```

## Components

### Runtime

- [Docker Compose](https://github.com/leanlag87/gymapp/blob/main/docker-compose.yaml): deployment · Runs the frontend, API, PostgreSQL, and proxy. · `docker-compose.yaml`
- [Nginx](https://github.com/leanlag87/gymapp/blob/main/ngnix.conf): reverse proxy · `ngnix.conf`

### Next.js Frontend

- [App Router routes](https://github.com/leanlag87/gymapp/blob/main/apps/frontend/app/layout.tsx): Next.js routes · Landing, login, and dashboard UI. · `apps/frontend/app/layout.tsx`
- [Auth client state](https://github.com/leanlag87/gymapp/blob/main/apps/frontend/contexts/auth-context.tsx): React context · `apps/frontend/contexts/auth-context.tsx`
- [API client boundary](https://github.com/leanlag87/gymapp/blob/main/apps/frontend/contexts/api-context.tsx): React context and hook · `apps/frontend/contexts/api-context.tsx`
- [Protected routes](https://github.com/leanlag87/gymapp/blob/main/apps/frontend/components/auth/protected-route.tsx): client auth guard · `apps/frontend/components/auth/protected-route.tsx`
- [Health proxy](https://github.com/leanlag87/gymapp/blob/main/apps/frontend/app/api/health/route.ts): Next.js route handler · `apps/frontend/app/api/health/route.ts`

### NestJS Backend

- [Nest bootstrap](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/main.ts): API entrypoint · `apps/backend/src/main.ts`
- [Application module](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/app.module.ts): Nest composition · `apps/backend/src/app.module.ts`
- [Feature controllers](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/members/members.controller.ts): HTTP presentation · Auth, members, and payments REST endpoints. · `apps/backend/src/presentation/members/members.controller.ts`
- [JWT and role guards](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/auth/guards/jwt-auth.guard.ts): authorization boundary · `apps/backend/src/presentation/auth/guards/jwt-auth.guard.ts`
- [Application services](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/application/members/members.service.ts): use-case orchestration · Auth, member, and payment service layer. · `apps/backend/src/application/members/members.service.ts`
- [Backend health](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/presentation/health/health.controller.ts): health controller · `apps/backend/src/presentation/health/health.controller.ts`

### Domain Core

Framework-independent business rules and contracts.

- [Business aggregates](https://github.com/leanlag87/gymapp/blob/main/domain/src/entities/Member.ts): domain entities · Member, Payment, and User aggregates. · `domain/src/entities/Member.ts`
- [Member lifecycle](https://github.com/leanlag87/gymapp/blob/main/domain/src/use-cases/members/register-member.ts): domain use cases · Registration, credentials, and status transitions. · `domain/src/use-cases/members/register-member.ts`
- [Payment lifecycle](https://github.com/leanlag87/gymapp/blob/main/domain/src/use-cases/payments/process-payment.ts): domain use cases · Payment processing, validation, and membership updates. · `domain/src/use-cases/payments/process-payment.ts`
- [Membership policy](https://github.com/leanlag87/gymapp/blob/main/domain/src/services/business-rules/verify-membership-status.ts): business rule · `domain/src/services/business-rules/verify-membership-status.ts`
- [Repository contracts](https://github.com/leanlag87/gymapp/blob/main/domain/src/repositories/member-repository.ts): domain ports · Member and payment persistence abstractions. · `domain/src/repositories/member-repository.ts`

### Persistence

- [Prisma repositories](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/infrastructure/repositories/prisma-member.repository.ts): repository adapters · Concrete member, payment, and user persistence. · `apps/backend/src/infrastructure/repositories/prisma-member.repository.ts`
- [Prisma data access](https://github.com/leanlag87/gymapp/blob/main/apps/backend/src/infrastructure/database/prisma/prisma.service.ts): ORM service and schema · `apps/backend/src/infrastructure/database/prisma/prisma.service.ts`
- [PostgreSQL](https://github.com/leanlag87/gymapp/blob/main/apps/backend/prisma/schema.prisma): database · `apps/backend/prisma/schema.prisma`

## Connections

- Docker Compose → Nginx: runs
- Docker Compose → App Router routes: runs
- Docker Compose → Nest bootstrap: runs
- Docker Compose → PostgreSQL: runs
- Nginx → App Router routes: serves
- Nginx → Nest bootstrap: proxies API
- App Router routes → Auth client state: uses
- App Router routes → Protected routes: protects dashboard
- App Router routes → API client boundary: calls through
- Health proxy → Backend health: proxies
- API client boundary → Feature controllers: HTTP requests
- Nest bootstrap → Application module: boots
- Application module → Feature controllers: composes
- Application module → Application services: wires
- Feature controllers → JWT and role guards: protected by
- Feature controllers → Application services: invokes
- Application services → Member lifecycle: orchestrates
- Application services → Payment lifecycle: orchestrates
- Member lifecycle → Business aggregates: applies rules to
- Payment lifecycle → Membership policy: validates via
- Member lifecycle → Repository contracts: depends on
- Payment lifecycle → Repository contracts: depends on
- Prisma repositories → Repository contracts: implements
- Application services → Prisma repositories: uses adapters
- Prisma repositories → Prisma data access: persists through
- Prisma data access → PostgreSQL: reads and writes
