# toufu-cell/vocabulary-app-backend architecture

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

- Interactive diagram: https://gitdiagram.com/toufu-cell/vocabulary-app-backend
- Repository: https://github.com/toufu-cell/vocabulary-app-backend

## Overview

##### Project Overview
- This is a backend API service for a word learning app that implements spaced repetition (SM-2 based FSRS algorithm) to aid vocabulary learning.
- The backend is built with Node.js and Express.js and uses LowDB (a JSON file–based database) for data persistence. The system provides endpoints for managing words, handling study sessions, tracking progress, and enabling data import/export.

##### Main Components
a. API Server (Express.js):
- Server as the central hub that listens for and routes HTTP requests.
- Different API endpoints: word management (GET, POST, DELETE), study functions (GET study data and POST updates), statistics retrieval, and data import/export.

b. Learning & Scheduling Engine:
- Core logic module that implements the spaced repetition algorithm. Even if it isn’t in a separate file, conceptually include it as part of the processing flow for updating learning results and scheduling next reviews.

c. Data Storage (LowDB):
- Data persistence layer; a JSON file (e.g., db.json mentioned in the README) is used as a simple database.
- Dependency between the Express server and the LowDB storage; the backend reads from and writes to this file.

d. External Client (Consumer of API):
- Although not part of the project tree, include an element representing external API consumers (e.g., frontend, mobile client) that interact with the backend.

##### Relationships and Data Flows
- Incoming HTTP requests from clients going into the Express server.
- Within the server, illustrate the flow to the learning engine where business logic (spaced repetition algorithm) is applied.
- Demonstrate interactions between the Express server and the LowDB storage; for example, when a word is added, updated or queried.
- Response path from the server back to the client.

##### Architectural Patterns & Design Principles
- That this is a RESTful API backend, so emphasize the separation between the API layer and the data handling logic.

##### Relevant Technologies Highlight
- Node.js for the runtime environment.
- Express.js as the web framework.
- LowDB as the lightweight JSON-based database.
- The use of an SM-2 based spaced repetition algorithm for scheduling reviews.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["External API Client"]:::client
    Server["Express API Server\n(endpoints: /words, /study, /stats, /import-export)"]:::server
    Engine["Learning & Scheduling Engine\n(SM-2 based algorithm)"]:::engine
    DB["LowDB (db.json)"]:::db

    Client -->|"HTTPRequest"| Server
    Server -->|"ProcessStudyData"| Engine
    Server <-->|"ReadWrite"| DB
    Server -->|"HTTPResponse"| Client

    click Server "https://github.com/toufu-cell/vocabulary-app-backend/blob/main/server.js"
    click Engine "https://github.com/toufu-cell/vocabulary-app-backend/blob/main/server.js"
    click DB "https://github.com/toufu-cell/vocabulary-app-backend/blob/main/README.md"

    classDef client fill:#cce5ff,stroke:#1E90FF,stroke-width:2px;
    classDef server fill:#d1f1d1,stroke:#28a745,stroke-width:2px;
    classDef engine fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef db fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
