# nghiavn1/notetaking-app architecture

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

- Interactive diagram: https://gitdiagram.com/nghiavn1/notetaking-app
- Repository: https://github.com/nghiavn1/notetaking-app

## Overview

##### Project type and purpose
- This is a MERN-stack (MongoDB, Express, React, Node.js) note-taking application with two distinct frontends:
a) “admin/frontend” – an administrative dashboard client.
b) “frontend” – the end-user note-taking client.
- The backend (“backend” directory) is an Express/Node.js REST API using Mongoose models for notes, users, labels, checklists, trash, and authentication via JWT.

##### File structure
- Top-level services:
- admin/frontend (React app)
- frontend (React app)
- backend (Node.js/Express API)
- Infrastructure as code:
- compose.yaml (defines multi-container Docker Compose setup)
- Dockerfiles under “frontend” and “backend”
- build-deploy.sh (deployment script)
- GitHub workflows for Docker publish & auto-deploy
- Backend: organized into src/configs, controllers, middlewares, models, routes, utils.
- Frontends share typical React/Vite setup with components, routes, context, and API client wrappers under frontend/api.

##### README
- Title: “mern-notetaking-app.”

a. Main components to include
- Admin Web Client (React/Vite)
- User Web Client (React/Vite)
- REST API Server (Node.js + Express)
- MongoDB Database
- Authentication Service (JWT module in backend)
- Docker & Orchestration (Docker Compose)
- CI/CD Pipeline (GitHub Actions workflows)
b. Relationships & interactions
– Both React frontends ↔ HTTP(S) ↔ REST API
– REST API ↔ MongoDB (via Mongoose)
– REST API issues and verifies JWT tokens for protected routes (auth middleware)
– Docker Compose spins up API and DB containers; frontends can be containerized/deployed separately
– GitHub Actions → builds Docker images → pushes to registry → triggers build-deploy.sh / auto-deploy
c. Architectural patterns & principles
– Layered architecture in backend (controllers → services/models → database)
– Separation of concerns: two distinct UIs (admin vs. end-user) consuming shared API
– Stateless RESTful API with token-based (JWT) authentication
– Infrastructure as code and containerization for reproducible deployments
d. Key technologies
– React + Vite for UIs
– Node.js + Express for API
– MongoDB + Mongoose for persistence
– JSON Web Tokens (JWT) for auth
– Docker, Docker Compose for container orchestration
– GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Clients"
        Admin["Admin React App"]:::frontend
        User["User React App"]:::frontend
    end

    subgraph "Backend Service"
        API["Express API (app.js)"]:::backend
        ROUTES["routes.js"]:::backend
        subgraph "Configs"
            DBConfig["Database Config"]:::config
        end
        subgraph "Middlewares"
            AuthMW["Auth Middleware"]:::backend
        end
        subgraph "Utils"
            JWTUtil["JWT Utils"]:::backend
        end
        subgraph "Controllers"
            Signup["signup.js"]:::backend
            Login["login.js"]:::backend
            Logout["logout.js"]:::backend
            NotesCtrl["notes.js"]:::backend
            LabelsCtrl["labels.js"]:::backend
        end
        subgraph "Models"
            NotesModel["notes.js"]:::model
            UsersModel["users.js"]:::model
            LabelModel["label.js"]:::model
            ChecklistModel["checklists.js"]:::model
            ChecklistItemModel["checklistitems.js"]:::model
            TrashModel["trash.js"]:::model
            NotesLabelsModel["notes_labels.js"]:::model
        end
    end

    DB["MongoDB"]:::db

    subgraph "Infrastructure"
        DockerComp["Docker Compose"]:::infra
        BackendDocker["backend/Dockerfile"]:::infra
        FrontendDocker["frontend/Dockerfile"]:::infra
        CI["GitHub Actions"]:::infra
        PublishWF["docker-publish.yml"]:::infra
        DeployWF["notetaking-app-AutoDeployTrigger.yml"]:::infra
        DeployScript["build-deploy.sh"]:::infra
    end

    Admin -->|"HTTP(S)"| API
    User -->|"HTTP(S)"| API
    API -->|"uses"| ROUTES
    ROUTES -->|"invokes"| Controllers
    Controllers -->|"access"| Models
    API -->|"connects"| DBConfig
    DBConfig -->|"connects"| DB
    API -->|"uses"| AuthMW
    AuthMW -->|"verifies/ issues"| JWTUtil
    API -->|"performs CRUD"| DB
    CI -->|builds images| DockerComp
    DockerComp -->|orchestrates| API
    DockerComp -->|orchestrates| DB
    CI -->|triggers| DeployScript

    classDef frontend fill:#ccffcc,stroke:#008800
    classDef backend fill:#cce5ff,stroke:#0044cc
    classDef model fill:#e5ccff,stroke:#660099
    classDef db fill:#ffe5cc,stroke:#cc6600,stroke-width:2px
    classDef infra fill:#f2f2f2,stroke:#666666,stroke-dasharray:5 5
    classDef config fill:#ccffff,stroke:#009999

    click Admin "https://github.com/nghiavn1/notetaking-app/tree/main/admin/frontend/"
    click User "https://github.com/nghiavn1/notetaking-app/tree/main/frontend/"
    click API "https://github.com/nghiavn1/notetaking-app/blob/main/backend/app.js"
    click DBConfig "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/configs/database.js"
    click NotesModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/notes.js"
    click UsersModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/users.js"
    click LabelModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/label.js"
    click ChecklistModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/checklists.js"
    click ChecklistItemModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/checklistitems.js"
    click TrashModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/trash.js"
    click NotesLabelsModel "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/models/notes_labels.js"
    click Signup "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/controllers/signup.js"
    click Login "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/controllers/login.js"
    click Logout "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/controllers/logout.js"
    click NotesCtrl "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/controllers/notes.js"
    click LabelsCtrl "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/controllers/labels.js"
    click ROUTES "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/routes/routes.js"
    click JWTUtil "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/utils/jwt.js"
    click AuthMW "https://github.com/nghiavn1/notetaking-app/blob/main/backend/src/middlewares/auth.js"
    click DockerComp "https://github.com/nghiavn1/notetaking-app/blob/main/compose.yaml"
    click BackendDocker "https://github.com/nghiavn1/notetaking-app/tree/main/backend/Dockerfile"
    click FrontendDocker "https://github.com/nghiavn1/notetaking-app/tree/main/frontend/Dockerfile"
    click PublishWF "https://github.com/nghiavn1/notetaking-app/blob/main/.github/workflows/docker-publish.yml"
    click DeployWF "https://github.com/nghiavn1/notetaking-app/blob/main/.github/workflows/notetaking-app-AutoDeployTrigger-e392ae65-3d1a-42f5-86e5-03b003d82abb.yml"
    click DeployScript "https://github.com/nghiavn1/notetaking-app/blob/main/build-deploy.sh"
```
