# chentim1011/happynote architecture

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

- Interactive diagram: https://gitdiagram.com/chentim1011/happynote
- Repository: https://github.com/chentim1011/happynote

## Overview

##### Project type and purpose
- This is a full-stack web application called “HappyNote” for managing knowledge cards and whiteboards.
- Frontend: React (Vite) single-page app that lets users create, edit, and link cards on a whiteboard.
- Backend: Node.js + Express REST API serving card, user, login, and whiteboard endpoints.
- Database: MongoDB for storing users, cards, and whiteboards.
- Goal: Offer a free, core feature–complete alternative to paid tools like Heptabase.

##### File structure
- Top-level directories:
- docs/planning – design docs and planning artifacts
- src/backend – server code, controllers, models, routes, middleware, config
- src/frontend/react-frontend – React code, components, pages, services, build configs
- Patterns:
- Backend follows an MVC-style separation: models in /models, controllers in /controllers, routes in /routes.
- Middleware layer for rate limiting and sanitization.
- Frontend organized by pages, components (common, specific, UI), interfaces, and services for API calls.
- Config files:
- .env_template/.env.production_template for environment variables
- package.json, Vite and TypeScript configs for frontend build
- package.json for backend dependencies

##### README for additional insights
- Technical stack callouts: Vite, React, Node.js, Express, Nginx (for reverse proxy / production), MongoDB.
- Team conventions: Git branching, commit messages, coding style.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Zone
    subgraph "Client (Browser)"
        ReactSPA["React SPA"]:::frontend
        subgraph "Frontend Services"
            cardService["Card Service"]:::frontend
            userService["User Service"]:::frontend
            loginService["Login Service"]:::frontend
            whiteboardService["Whiteboard Service"]:::frontend
        end
        subgraph "Routes & Pages"
            routesIndex["Routes Entry"]:::frontend
            protectedRoute["ProtectedRoute Component"]:::frontend
            loginPage["Login Page"]:::frontend
            homePage["Home Page"]:::frontend
            whiteboardPage["Whiteboard Page"]:::frontend
            managementPage["Management Page"]:::frontend
            mapPage["Map Page"]:::frontend
        end
        ReactSPA -->|use services| cardService
        ReactSPA -->|use services| userService
        ReactSPA -->|use services| loginService
        ReactSPA -->|use services| whiteboardService
        ReactSPA -->|render pages via| routesIndex
        routesIndex --> protectedRoute
        routesIndex --> loginPage
        routesIndex --> homePage
        routesIndex --> whiteboardPage
        routesIndex --> managementPage
        routesIndex --> mapPage
        cardService -->|REST API calls| Nginx
        userService -->|REST API calls| Nginx
        loginService -->|REST API calls| Nginx
        whiteboardService -->|REST API calls| Nginx
    end

    %% Server Zone
    subgraph "Backend"
        Nginx["Nginx (Reverse Proxy)"]:::infra
        serverjs["server.js"]:::backend
        appjs["app.js"]:::backend
        dbConfig["Database Config"]:::backend

        Nginx -->|forwards to| serverjs
        serverjs --> appjs
        appjs -->|uses| dbConfig
        appjs --> MiddlewareLimiter
        appjs --> MiddlewareSanitize

        subgraph "Middleware"
            MiddlewareLimiter["Rate-limiting Middleware"]:::backend
            MiddlewareSanitize["Sanitization Utility"]:::backend
        end

        subgraph "Routes"
            cardRoutes["Card Routes"]:::backend
            userRoutes["User Routes"]:::backend
            loginRoutes["Login Routes"]:::backend
            whiteboardRoutes["Whiteboard Routes"]:::backend
        end

        subgraph "Controllers"
            cardController["Card Controller"]:::backend
            userController["User Controller"]:::backend
            loginController["Login Controller"]:::backend
            whiteboardController["Whiteboard Controller"]:::backend
        end

        subgraph "Models"
            cardModel["Card Model"]:::backend
            userModel["User Model"]:::backend
            whiteboardModel["Whiteboard Model"]:::backend
        end

        appjs --> cardRoutes
        appjs --> userRoutes
        appjs --> loginRoutes
        appjs --> whiteboardRoutes

        cardRoutes --> cardController
        userRoutes --> userController
        loginRoutes --> loginController
        whiteboardRoutes --> whiteboardController

        cardController --> cardModel
        userController --> userModel
        loginController --> userModel
        whiteboardController --> whiteboardModel

        dbConfig --> MongoDB
    end

    %% Data Layer
    MongoDB["MongoDB"]:::database

    %% Env templates
    envDev[".env_template"]:::infra
    envProd[".env.production_template"]:::infra
    envDev -.-> appjs
    envProd -.-> appjs

    %% Click Events
    click ReactSPA "https://github.com/chentim1011/happynote/tree/main/src/frontend/react-frontend"
    click cardService "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/services/cardService.ts"
    click userService "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/services/userService.ts"
    click loginService "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/services/loginService.ts"
    click whiteboardService "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/services/whiteboardService.ts"
    click routesIndex "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/routes/index.tsx"
    click protectedRoute "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/routes/ProtectedRoute/index.tsx"
    click loginPage "https://github.com/chentim1011/happynote/tree/main/src/frontend/react-frontend/src/pages/Login"
    click homePage "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/pages/Home/index.tsx"
    click whiteboardPage "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/pages/Whiteboard/index.tsx"
    click managementPage "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/pages/Management/index.tsx"
    click mapPage "https://github.com/chentim1011/happynote/blob/main/src/frontend/react-frontend/src/pages/Map/index.tsx"
    click serverjs "https://github.com/chentim1011/happynote/blob/main/src/backend/server.js"
    click appjs "https://github.com/chentim1011/happynote/blob/main/src/backend/app.js"
    click dbConfig "https://github.com/chentim1011/happynote/blob/main/src/backend/config/db.js"
    click cardController "https://github.com/chentim1011/happynote/blob/main/src/backend/controllers/cardController.js"
    click userController "https://github.com/chentim1011/happynote/blob/main/src/backend/controllers/userController.js"
    click loginController "https://github.com/chentim1011/happynote/blob/main/src/backend/controllers/loginController.js"
    click whiteboardController "https://github.com/chentim1011/happynote/blob/main/src/backend/controllers/whiteboardController.js"
    click cardModel "https://github.com/chentim1011/happynote/blob/main/src/backend/models/Card.js"
    click userModel "https://github.com/chentim1011/happynote/blob/main/src/backend/models/User.js"
    click whiteboardModel "https://github.com/chentim1011/happynote/blob/main/src/backend/models/Whiteboard.js"
    click cardRoutes "https://github.com/chentim1011/happynote/blob/main/src/backend/routes/cardRoutes.js"
    click userRoutes "https://github.com/chentim1011/happynote/blob/main/src/backend/routes/userRoutes.js"
    click loginRoutes "https://github.com/chentim1011/happynote/blob/main/src/backend/routes/loginRoutes.js"
    click whiteboardRoutes "https://github.com/chentim1011/happynote/blob/main/src/backend/routes/whiteboardRoutes.js"
    click MiddlewareLimiter "https://github.com/chentim1011/happynote/blob/main/src/backend/middlewares/loginLimiter.js"
    click MiddlewareSanitize "https://github.com/chentim1011/happynote/blob/main/src/backend/utils/sanitize.js"
    click envDev "https://github.com/chentim1011/happynote/blob/main/src/backend/.env_template"
    click envProd "https://github.com/chentim1011/happynote/blob/main/src/backend/.env.production_template"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#DFFFE0,stroke:#333,stroke-width:1px
    classDef infra fill:#FFE0B3,stroke:#333,stroke-width:1px
    classDef database fill:#FFE0E0,stroke:#333,stroke-width:1px
```
