# emtiajium/vocabulary-flashcard-backend architecture

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

- Interactive diagram: https://gitdiagram.com/emtiajium/vocabulary-flashcard-backend
- Repository: https://github.com/emtiajium/vocabulary-flashcard-backend

## Overview

This is the NestJS backend for Firecracker Vocabulary, a collaborative vocabulary and flashcard app. Clients authenticate and then manage users, cohorts, vocabulary, and Leitner flashcards; vocabulary search and guessing-game features are also documented in the source index and changelog. PostgreSQL provides persistent domain state, while Google token verification is an authentication integration. The graph emphasizes relationships shown in excerpts or the source index; several listed capabilities have unsampled implementations, so their internal links are omitted rather than inferred.

Main entry points: [`src/user/services/UserService.ts`](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/services/UserService.ts) (User Service), [`src/vocabulary/services/VocabularyService.ts`](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/VocabularyService.ts) (Vocabulary Service), [`src/common/guards/AuthGuard.ts`](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/common/guards/AuthGuard.ts) (Auth Guard), [`src/user/services/CohortService.ts`](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/services/CohortService.ts) (Cohort Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and Cohorts"]
  node_authguard["Auth Guard<br/>[AuthGuard.ts]"]
  node_tokenmanager["Token Manager<br/>[TokenManager.ts]"]
  node_userservice["User Service<br/>[UserService.ts]"]
  node_usercontroller["User API<br/>[UserController.ts]"]
  node_userrepo["User Repository<br/>[UserRepository.ts]"]
  node_cohortservice["Cohort Service<br/>[CohortService.ts]"]
  node_cohortrepo["Cohort Repository"]
end

subgraph group_vocabulary["Vocabulary Management"]
  node_vocabcontroller["Vocabulary API"]
  node_vocabservice["Vocabulary Service"]
  node_vocabrepo["Vocabulary Repository"]
  node_definitionrepo["Definition Repository"]
end

subgraph group_learning["Learning Features"]
  node_leitnercontroller["Leitner API"]
  node_leitnerservice["Leitner Service"]
  node_leitnerrepo["Leitner Repository"]
  node_guessing["Guessing Game"]
end

subgraph group_platform["Platform Services"]
  node_android["Android API"]
  node_health["Health Check"]
  node_database[("PostgreSQL")]
  node_google["Google Identity"]
end

node_client(("App Client"))

node_client -->|"requests protected routes"| node_authguard
node_authguard -->|"decodes token"| node_tokenmanager
node_authguard -->|"loads user"| node_userservice
node_tokenmanager -->|"verifies identity token"| node_google
node_usercontroller -->|"delegates user actions"| node_userservice
node_usercontroller -->|"guards report routes"| node_authguard
node_usercontroller -.->|"returns user results"| node_client
node_userservice -->|"reads and writes users"| node_userrepo
node_userservice -->|"creates default cohort"| node_cohortservice
node_userservice -->|"decodes signup token"| node_tokenmanager
node_cohortservice -->|"creates and finds cohorts"| node_cohortrepo
node_cohortservice -->|"updates cohort membership"| node_userrepo
node_cohortservice -->|"moves cohort vocabulary"| node_vocabservice
node_vocabcontroller -->|"delegates vocabulary actions"| node_vocabservice
node_vocabcontroller -->|"guards vocabulary routes"| node_authguard
node_vocabservice -->|"searches and persists vocabulary"| node_vocabrepo
node_vocabservice -->|"removes orphan definitions"| node_definitionrepo
node_vocabservice -->|"requests game meanings"| node_guessing
node_leitnercontroller -->|"delegates flashcard actions"| node_leitnerservice
node_leitnerservice -->|"reads and updates boxes"| node_leitnerrepo
node_leitnerservice -->|"loads vocabulary"| node_vocabrepo
node_vocabrepo -->|"queries and persists"| node_database
node_userrepo -.->|"persists user records"| node_database
node_cohortrepo -.->|"persists cohort records"| node_database
node_leitnerrepo -.->|"persists flashcard state"| node_database
node_android -.->|"serves Android metadata"| node_client
node_health -.->|"reports service health"| node_client

click node_authguard "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/common/guards/AuthGuard.ts"
click node_tokenmanager "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/common/services/TokenManager.ts"
click node_userservice "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/services/UserService.ts"
click node_usercontroller "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/controllers/UserController.ts"
click node_userrepo "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/repositories/UserRepository.ts"
click node_cohortservice "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/services/CohortService.ts"
click node_cohortrepo "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/repositories/CohortRepository.ts"
click node_vocabcontroller "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/controllers/VocabularyController.ts"
click node_vocabservice "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/VocabularyService.ts"
click node_vocabrepo "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/repositories/VocabularyRepository.ts"
click node_definitionrepo "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/repositories/DefinitionRepository.ts"
click node_leitnercontroller "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/controllers/LeitnerSystemsController.ts"
click node_leitnerservice "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/LeitnerSystemsService.ts"
click node_leitnerrepo "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/repositories/LeitnerSystemsRepository.ts"
click node_guessing "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/GuessingGameService.ts"
click node_android "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/android/controllers/AndroidController.ts"
click node_health "https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/health-check/controllers/HealthCheckController.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_authguard,node_tokenmanager,node_userservice,node_usercontroller,node_userrepo,node_cohortservice,node_cohortrepo,node_client toneBlue
class node_vocabcontroller,node_vocabservice,node_vocabrepo,node_definitionrepo toneAmber
class node_leitnercontroller,node_leitnerservice,node_leitnerrepo,node_guessing toneMint
class node_android,node_health,node_database,node_google toneRose
```

## Components

### Identity and Cohorts

- [Auth Guard](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/common/guards/AuthGuard.ts): `src/common/guards/AuthGuard.ts`
- [Token Manager](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/common/services/TokenManager.ts): `src/common/services/TokenManager.ts`
- [User Service](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/services/UserService.ts): `src/user/services/UserService.ts`
- [User API](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/controllers/UserController.ts): `src/user/controllers/UserController.ts`
- [User Repository](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/repositories/UserRepository.ts): `src/user/repositories/UserRepository.ts`
- [Cohort Service](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/services/CohortService.ts): `src/user/services/CohortService.ts`
- [Cohort Repository](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/user/repositories/CohortRepository.ts): `src/user/repositories/CohortRepository.ts`

### Vocabulary Management

- [Vocabulary API](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/controllers/VocabularyController.ts): `src/vocabulary/controllers/VocabularyController.ts`
- [Vocabulary Service](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/VocabularyService.ts): `src/vocabulary/services/VocabularyService.ts`
- [Vocabulary Repository](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/repositories/VocabularyRepository.ts): `src/vocabulary/repositories/VocabularyRepository.ts`
- [Definition Repository](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/repositories/DefinitionRepository.ts): `src/vocabulary/repositories/DefinitionRepository.ts`

### Learning Features

- [Leitner API](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/controllers/LeitnerSystemsController.ts): `src/vocabulary/controllers/LeitnerSystemsController.ts`
- [Leitner Service](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/LeitnerSystemsService.ts): `src/vocabulary/services/LeitnerSystemsService.ts`
- [Leitner Repository](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/repositories/LeitnerSystemsRepository.ts): `src/vocabulary/repositories/LeitnerSystemsRepository.ts`
- [Guessing Game](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/vocabulary/services/GuessingGameService.ts): `src/vocabulary/services/GuessingGameService.ts`

### Platform Services

- [Android API](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/android/controllers/AndroidController.ts): `src/android/controllers/AndroidController.ts`
- [Health Check](https://github.com/emtiajium/vocabulary-flashcard-backend/blob/master/src/health-check/controllers/HealthCheckController.ts): `src/health-check/controllers/HealthCheckController.ts`
- **PostgreSQL**
- **Google Identity**

### Other components

- **App Client**

## Connections

- App Client → Auth Guard: requests protected routes (evidence: `src/common/guards/AuthGuard.ts`)
- Auth Guard → Token Manager: decodes token (evidence: `src/common/guards/AuthGuard.ts`)
- Auth Guard → User Service: loads user (evidence: `src/common/guards/AuthGuard.ts`)
- Token Manager → Google Identity: verifies identity token (evidence: `src/common/services/TokenManager.ts`)
- User API → User Service: delegates user actions (evidence: `src/user/controllers/UserController.ts`)
- User API → Auth Guard: guards report routes (evidence: `src/user/controllers/UserController.ts`)
- User API → App Client: returns user results
- User Service → User Repository: reads and writes users (evidence: `src/user/services/UserService.ts`)
- User Service → Cohort Service: creates default cohort (evidence: `src/user/services/UserService.ts`)
- User Service → Token Manager: decodes signup token (evidence: `src/user/services/UserService.ts`)
- Cohort Service → Cohort Repository: creates and finds cohorts (evidence: `src/user/services/CohortService.ts`)
- Cohort Service → User Repository: updates cohort membership (evidence: `src/user/services/CohortService.ts`)
- Cohort Service → Vocabulary Service: moves cohort vocabulary (evidence: `src/user/services/CohortService.ts`)
- Vocabulary API → Vocabulary Service: delegates vocabulary actions (evidence: `src/vocabulary/controllers/VocabularyController.ts`)
- Vocabulary API → Auth Guard: guards vocabulary routes (evidence: `src/vocabulary/controllers/VocabularyController.ts`)
- Vocabulary Service → Vocabulary Repository: searches and persists vocabulary (evidence: `src/vocabulary/services/VocabularyService.ts`)
- Vocabulary Service → Definition Repository: removes orphan definitions (evidence: `src/vocabulary/services/VocabularyService.ts`)
- Vocabulary Service → Guessing Game: requests game meanings (evidence: `src/vocabulary/services/VocabularyService.ts`)
- Leitner API → Leitner Service: delegates flashcard actions (evidence: `src/vocabulary/controllers/LeitnerSystemsController.ts`)
- Leitner Service → Leitner Repository: reads and updates boxes (evidence: `src/vocabulary/services/LeitnerSystemsService.ts`)
- Leitner Service → Vocabulary Repository: loads vocabulary (evidence: `src/vocabulary/services/LeitnerSystemsService.ts`)
- Vocabulary Repository → PostgreSQL: queries and persists (evidence: `src/vocabulary/repositories/VocabularyRepository.ts`)
- User Repository → PostgreSQL: persists user records
- Cohort Repository → PostgreSQL: persists cohort records
- Leitner Repository → PostgreSQL: persists flashcard state
- Android API → App Client: serves Android metadata
- Health Check → App Client: reports service health
