# baohuy6505/flashbrain architecture

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

- Interactive diagram: https://gitdiagram.com/baohuy6505/flashbrain
- Repository: https://github.com/baohuy6505/flashbrain

## Overview

FlashBrain is a spaced-repetition flashcard product with an Android client and a Node/Express backend. The user studies and manages decks and cards in the app; documented cloud sync carries data to the authenticated API, which persists user, study, and learning data and exposes progress, statistics, and notification capabilities. The sampled backend confirms route/controller/service boundaries and some repository wiring; Android implementation details and most service internals are not present in the supplied tree or excerpts, so those links are shown only where documented or directly supported.

Main entry points: [`backend/src/application/services/authService.js`](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/authService.js) (Auth service), [`backend/src/presentation/routes/index.js`](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/index.js) (API routes), [`backend/src/app.js`](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/app.js) (Express app), [`backend/src/presentation/routes/authRoutes.js`](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/authRoutes.js) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["API presentation"]
  node_app["Express app<br/>[app.js]"]
  node_routes["API routes<br/>[index.js]"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_deckroutes["Deck routes<br/>[deckRoutes.js]"]
  node_cardroutes["Flashcard routes<br/>[flashcardRoutes.js]"]
  node_authmw["JWT middleware<br/>[authMiddleware.js]"]
  node_authctrl["Auth controller<br/>[authController.js]"]
  node_deckctrl["Deck controller<br/>[deckController.js]"]
  node_cardctrl["Flashcard controller"]
  node_progressctrl["Progress controller"]
  node_statsctrl["Statistics controller"]
  node_notifyctrl["Notification controller"]
end

subgraph group_application["Application services"]
  node_authsvc["Auth service<br/>[authService.js]"]
  node_decksvc["Deck service<br/>[deckService.js]"]
  node_cardsvc["Flashcard service"]
  node_progresssvc["Progress service"]
  node_statssvc["Statistics service<br/>[satisticService.js]"]
  node_notifysvc["Notification service"]
end

subgraph group_persistence["Persistence"]
  node_userrepo["User repository<br/>[userRepository.js]"]
  node_deckrepo["Deck repository<br/>[deckRepository.js]"]
  node_cardrepo["Flashcard repository"]
  node_progressrepo["Progress repository"]
  node_notifyrepo["Notification repository"]
  node_mongo[("MongoDB")]
end

subgraph group_operations["Learning operations"]
  node_job["Notification job<br/>[notificationJob.js]"]
  node_cloudinary["Cloudinary"]
  node_google["Google identity"]
  node_jwt["JWT utility<br/>[jwt.js]"]
end

node_learner(("Learner"))
node_android["Android app"]

node_learner -->|"studies with"| node_android
node_android -->|"syncs via API"| node_app
node_app -->|"mounts routes"| node_routes
node_routes -->|"dispatches"| node_authroutes
node_routes -->|"dispatches"| node_deckroutes
node_routes -->|"dispatches"| node_cardroutes
node_authroutes -->|"guards requests"| node_authmw
node_deckroutes -->|"guards requests"| node_authmw
node_cardroutes -->|"guards requests"| node_authmw
node_authroutes -->|"dispatches"| node_authctrl
node_deckroutes -->|"dispatches"| node_deckctrl
node_cardroutes -->|"dispatches"| node_cardctrl
node_authctrl -->|"calls"| node_authsvc
node_deckctrl -->|"calls"| node_decksvc
node_cardctrl -->|"calls"| node_cardsvc
node_progressctrl -->|"calls"| node_progresssvc
node_statsctrl -->|"calls"| node_statssvc
node_notifyctrl -->|"calls"| node_notifysvc
node_authsvc -->|"reads and writes"| node_userrepo
node_authsvc -->|"generates tokens"| node_jwt
node_authsvc -.->|"verifies identity"| node_google
node_authsvc -.->|"deletes old image"| node_cloudinary
node_cardsvc -->|"uses repository"| node_cardrepo
node_userrepo -->|"stores users"| node_mongo
node_deckrepo -->|"stores decks"| node_mongo
node_cardrepo -->|"stores cards"| node_mongo
node_progressrepo -->|"stores progress"| node_mongo
node_notifyrepo -->|"stores notifications"| node_mongo
node_app -->|"starts job"| node_job
node_android -.->|"studies offline"| node_android

click node_app "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/app.js"
click node_routes "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/index.js"
click node_authroutes "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/authRoutes.js"
click node_deckroutes "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/deckRoutes.js"
click node_cardroutes "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/flashcardRoutes.js"
click node_authmw "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/middlewares/authMiddleware.js"
click node_authctrl "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/authController.js"
click node_deckctrl "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/deckController.js"
click node_cardctrl "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/flashcardController.js"
click node_progressctrl "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/userProgressController.js"
click node_statsctrl "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/statisticController.js"
click node_notifyctrl "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/notificationController.js"
click node_authsvc "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/authService.js"
click node_decksvc "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/deckService.js"
click node_cardsvc "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/flashcardService.js"
click node_progresssvc "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/userProgressService.js"
click node_statssvc "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/satisticService.js"
click node_notifysvc "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/notificationService.js"
click node_userrepo "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/userRepository.js"
click node_deckrepo "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/deckRepository.js"
click node_cardrepo "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/flashcardRepository.js"
click node_progressrepo "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/userProgressRepository.js"
click node_notifyrepo "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/notificationRepository.js"
click node_job "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/jobs/notificationJob.js"
click node_jwt "https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/utils/jwt.js"

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_app,node_routes,node_authroutes,node_deckroutes,node_cardroutes,node_authmw,node_authctrl,node_deckctrl,node_cardctrl,node_progressctrl,node_statsctrl,node_notifyctrl toneBlue
class node_authsvc,node_decksvc,node_cardsvc,node_progresssvc,node_statssvc,node_notifysvc toneAmber
class node_userrepo,node_deckrepo,node_cardrepo,node_progressrepo,node_notifyrepo,node_mongo toneMint
class node_job,node_cloudinary,node_google,node_jwt toneRose
class node_learner,node_android toneIndigo
```

## Components

### API presentation

- [Express app](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/app.js): `backend/src/app.js`
- [API routes](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/index.js): `backend/src/presentation/routes/index.js`
- [Auth routes](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/authRoutes.js): `backend/src/presentation/routes/authRoutes.js`
- [Deck routes](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/deckRoutes.js): `backend/src/presentation/routes/deckRoutes.js`
- [Flashcard routes](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/routes/flashcardRoutes.js): `backend/src/presentation/routes/flashcardRoutes.js`
- [JWT middleware](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/middlewares/authMiddleware.js): `backend/src/presentation/middlewares/authMiddleware.js`
- [Auth controller](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/authController.js): `backend/src/presentation/controllers/authController.js`
- [Deck controller](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/deckController.js): `backend/src/presentation/controllers/deckController.js`
- [Flashcard controller](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/flashcardController.js): `backend/src/presentation/controllers/flashcardController.js`
- [Progress controller](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/userProgressController.js): `backend/src/presentation/controllers/userProgressController.js`
- [Statistics controller](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/statisticController.js): `backend/src/presentation/controllers/statisticController.js`
- [Notification controller](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/presentation/controllers/notificationController.js): `backend/src/presentation/controllers/notificationController.js`

### Application services

- [Auth service](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/authService.js): `backend/src/application/services/authService.js`
- [Deck service](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/deckService.js): `backend/src/application/services/deckService.js`
- [Flashcard service](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/flashcardService.js): `backend/src/application/services/flashcardService.js`
- [Progress service](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/userProgressService.js): `backend/src/application/services/userProgressService.js`
- [Statistics service](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/satisticService.js): `backend/src/application/services/satisticService.js`
- [Notification service](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/services/notificationService.js): `backend/src/application/services/notificationService.js`

### Persistence

- [User repository](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/userRepository.js): `backend/src/infrastructure/repositories/userRepository.js`
- [Deck repository](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/deckRepository.js): `backend/src/infrastructure/repositories/deckRepository.js`
- [Flashcard repository](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/flashcardRepository.js): `backend/src/infrastructure/repositories/flashcardRepository.js`
- [Progress repository](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/userProgressRepository.js): `backend/src/infrastructure/repositories/userProgressRepository.js`
- [Notification repository](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/repositories/notificationRepository.js): `backend/src/infrastructure/repositories/notificationRepository.js`
- **MongoDB**

### Learning operations

- [Notification job](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/infrastructure/jobs/notificationJob.js): `backend/src/infrastructure/jobs/notificationJob.js`
- **Cloudinary**
- **Google identity**
- [JWT utility](https://github.com/baohuy6505/flashbrain/blob/master/backend/src/application/utils/jwt.js): `backend/src/application/utils/jwt.js`

### Other components

- **Learner**
- **Android app**

## Connections

- Learner → Android app: studies with
- Android app → Express app: syncs via API
- Express app → API routes: mounts routes
- API routes → Auth routes: dispatches
- API routes → Deck routes: dispatches
- API routes → Flashcard routes: dispatches
- Auth routes → JWT middleware: guards requests
- Deck routes → JWT middleware: guards requests
- Flashcard routes → JWT middleware: guards requests
- Auth routes → Auth controller: dispatches
- Deck routes → Deck controller: dispatches
- Flashcard routes → Flashcard controller: dispatches
- Auth controller → Auth service: calls
- Deck controller → Deck service: calls
- Flashcard controller → Flashcard service: calls
- Progress controller → Progress service: calls
- Statistics controller → Statistics service: calls
- Notification controller → Notification service: calls
- Auth service → User repository: reads and writes
- Auth service → JWT utility: generates tokens
- Auth service → Google identity: verifies identity
- Auth service → Cloudinary: deletes old image
- Flashcard service → Flashcard repository: uses repository
- User repository → MongoDB: stores users
- Deck repository → MongoDB: stores decks
- Flashcard repository → MongoDB: stores cards
- Progress repository → MongoDB: stores progress
- Notification repository → MongoDB: stores notifications
- Express app → Notification job: starts job
- Android app → Android app: studies offline
