# prince-vaviya/rigged-repo architecture

> Architecture diagram of the GitHub repository prince-vaviya/rigged-repo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prince-vaviya/rigged-repo
- Repository: https://github.com/prince-vaviya/rigged-repo

## Overview

This is a **small full-stack web application** with:
- **Frontend:** static HTML/CSS/vanilla JS served from `public/` (`index.html`, `dashboard.html`)
- **Backend:** a **single Node.js/Express** server (`server.js`) providing auth + notes APIs + AI chat API proxying to OpenAI
- **Data:** **MongoDB via Mongoose**
- **Integrations:** optional **AWS S3** (file storage) and **GitHub Gists** (export/push notes)
- **Auth:** **JWT**, stored client-side in `localStorage`

##### File structure cues → architectural boundaries
From the tree:

- `server.js`
Implies a **monolithic Express server** (likely contains routes/middleware/models wiring in one file or minimal modules).
- `public/` (`index.html`, `dashboard.html`)
Static client; likely `index.html` = login/register, `dashboard.html` = notes/chat UI.
- `.env` / `.env.example` (mentioned), `package.json`
- `private_key.pem`
- `REPORT.md`

##### What to include from README (stack + flows)
Key points that should appear explicitly as labeled components or callouts:
- **Express 4.16** backend
- **MongoDB + Mongoose** persistence
- **JWT auth**; tokens stored in **localStorage** (important security/flow detail)
- **OpenAI API** called from backend for AI chat
- **S3 file storage** (optional) via AWS credentials
- **GitHub Gists** push using a PAT (`GITHUB_TOKEN`)

##### Client-side (Browser)
- Login/Register page (`index.html`)
- Dashboard (`dashboard.html`)
- Notes UI
- Chat UI
- localStorage (JWT token storage)
- HTTP client (fetch/XHR)

##### Server-side (Express)
- Express app + middleware pipeline
- JWT auth middleware
- Notes API
- Chat API (OpenAI proxy)
- Gist export API
- S3 upload/download API (if present)
- Mongoose models / data access layer
- Env/config loader

##### Data + external services
- MongoDB (Users, Notes)
- OpenAI API
- AWS S3 bucket
- GitHub Gists

- **Auth flow**
1. Browser → Express: credentials
2. Express → MongoDB: verify/create user
3. Express → Browser: JWT
4. Browser stores JWT in **localStorage**
5. Browser → Express: subsequent calls with `Authorization` header

- **Notes flow**
- Browser ↔ Express: create/list/update/delete note
- Express ↔ MongoDB: persist notes

- **AI chat flow**
- Browser → Express: user prompt + context
- Express → OpenAI: completion request (server-side key)
- Express → Browser: model response

- **S3 flow (optional)**
- Browser → Express: upload request
- Express → S3: store blob
- Express → MongoDB: store S3 object key/metadata (if implemented)
- Browser → Express: download request
- Express → S3: fetch object

- **GitHub Gist flow (optional)**
- Browser → Express: “export/push note”
- Express → GitHub API: create/update Gist using PAT
- Express → Browser: gist URL/status

- **Express** (routing/middleware)
- **Mongoose** (ODM)
- **JWT** auth (stateless sessions)
- **Secrets via `.env`** (12-factor style)
- **No rate limiting** (explicit “missing control” note)
- Optional: “CORS / static hosting from same server” depending on how `server.js` is set up (most likely same origin `localhost:3000`)

##### Diagramming conventions to use (so it reads well to other principals)
Elements explicitly:

- “HTTPS JSON”
- “MongoDB wire protocol via Mongoose”
- “OpenAI REST”
- “S3 REST (Put/Get)”
- “GitHub REST (Gists)”
- Blue rectangles: your code (Browser UI, Express server)
- Orange clouds: external services (OpenAI, AWS S3, GitHub)
- **Trust boundaries** (high value here):
- Boundary 1: Browser (untrusted client)
- Boundary 2: Server (trusted boundary where secrets live)
- Boundary 3: External SaaS (third-party trust)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% Level 1: System Context
    %% =========================
    subgraph "System Context (C4 L1)"
        direction TB

        User["User (Web Browser)"]:::actor
        System["Team Notes AI Web App"]:::system

        Mongo[("MongoDB (Atlas/Cluster)")]:::db
        OpenAI["OpenAI API"]:::external
        S3["AWS S3 (Optional)"]:::external
        GitHub["GitHub API (Gists) (Optional)"]:::external

        User -->|"Use UI (login, notes, chat)"| System
        System -->|"Store users, notes"| Mongo
        System -->|"Chat completion requests"| OpenAI
        System -->|"Upload/download attachments"| S3
        System -->|"Create/update Gists (export notes)"| GitHub
    end

    %% =========================
    %% Level 2: Container Diagram
    %% =========================
    subgraph "Container View (C4 L2)"
        direction TB

        subgraph "Client (Untrusted Boundary)"
            direction TB
            Browser["Browser Client (Static Pages + Vanilla JS)"]:::frontend
            Index["Login/Register UI (index.html)"]:::frontend
            Dash["Dashboard UI (notes + chat) (dashboard.html)"]:::frontend
            LS[("localStorage (JWT token)")]:::store
            Http["HTTP client (fetch/XHR)"]:::frontend

            Browser -->|"Renders"| Index
            Browser -->|"Renders"| Dash
            Browser -->|"Stores/Reads JWT"| LS
            Browser -->|"Uses"| Http
        end

        subgraph "Server (Trusted Boundary)"
            direction TB
            Express["Node.js/Express API Server (monolith)"]:::backend
            Secrets["Config/Secrets (.env, keys)"]:::secret
            KeyMat["Key material (private_key.pem)"]:::secret
            NoRL["Missing/Optional: Rate limiter (future work)"]:::warning

            Secrets -->|"Loads env vars"| Express
            KeyMat -->|"Sign/verify JWT (or TLS)"| Express
            NoRL -.->|"Not implemented"| Express
        end

        subgraph "Data / Third-Party (External Boundary)"
            direction TB
            Mongo2[("MongoDB via Mongoose")]:::db
            OpenAI2["OpenAI REST API"]:::external
            S32["AWS S3 REST API"]:::external
            GitHub2["GitHub REST API (Gists)"]:::external
        end

        Http -->|"HTTPS JSON (auth, notes, chat)"| Express
        Express -->|"JWT issued"| Http
        Http -->|"Authorization: Bearer JWT"| Express

        Express -->|"Mongoose ODM queries"| Mongo2
        Express -->|"OpenAI requests (server-side key)"| OpenAI2
        Express -->|"S3 Put/Get (if used)"| S32
        Express -->|"Gist create/update (PAT)"| GitHub2
    end

    %% =========================
    %% Level 3: Component Diagram (server.js)
    %% =========================
    subgraph "Express Server Components (C4 L3 - server.js)"
        direction TB

        ExpressApp["Express app + middleware pipeline"]:::backend

        Static["Static file handler (/public/*)"]:::backend
        Auth["Auth module (login/register + JWT)"]:::backend
        JwtMW["JWT auth middleware (verify token)"]:::backend
        Notes["Notes API (CRUD endpoints)"]:::backend
        Chat["AI Chat API proxy (OpenAI)"]:::backend
        Integrations["Integrations module"]:::backend

        subgraph "Adapters (Optional)"
            direction TB
            S3Adapter["S3 adapter (upload/download)"]:::backend
            GistAdapter["GitHub Gist adapter (export/push)"]:::backend
        end

        Models["Mongoose models / Data access (Users, Notes)"]:::backend

        ExpressApp -->|"Serves"| Static
        ExpressApp -->|"Routes"| Auth
        ExpressApp -->|"Protects"| JwtMW
        JwtMW -->|"Guards"| Notes
        JwtMW -->|"Guards"| Chat
        JwtMW -->|"Guards"| Integrations

        Auth -->|"Create/verify user"| Models
        Notes -->|"CRUD notes"| Models

        Chat -->|"Calls"| OpenAI2
        Notes -.->|"Store attachment metadata"| Models
        Notes -.->|"Optional attachments"| S3Adapter

        Integrations -->|"Uses"| S3Adapter
        Integrations -->|"Uses"| GistAdapter
        GistAdapter -->|"Calls"| GitHub2
        S3Adapter -->|"Calls"| S32
        Models -->|"Persists"| Mongo2
    end

    %% =========================
    %% Cross-links between levels
    %% =========================
    System -->|"Implemented by"| Browser
    System -->|"Implemented by"| Express
    Mongo -->|"Same as"| Mongo2
    OpenAI -->|"Same as"| OpenAI2
    S3 -->|"Same as"| S32
    GitHub -->|"Same as"| GitHub2

    %% =========================
    %% Hidden helper nodes for click mapping (not shown)
    %% =========================
    REPORT["Architecture/Design Notes (REPORT.md)"]:::hidden
    PKG["Dependencies/Scripts (package.json)"]:::hidden
    REPORT -.-> System
    PKG -.-> Express

    %% =========================
    %% Click Events (from component_mapping)
    %% =========================
    click Browser "https://github.com/prince-vaviya/rigged-repo/tree/main/public/"
    click Index "https://github.com/prince-vaviya/rigged-repo/blob/main/public/index.html"
    click Dash "https://github.com/prince-vaviya/rigged-repo/blob/main/public/dashboard.html"
    click Express "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click ExpressApp "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Static "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Auth "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Notes "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Chat "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Integrations "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Secrets "https://github.com/prince-vaviya/rigged-repo/blob/main/.env"
    click KeyMat "https://github.com/prince-vaviya/rigged-repo/blob/main/private_key.pem"
    click System "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click NoRL "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click Models "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click S3Adapter "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click GistAdapter "https://github.com/prince-vaviya/rigged-repo/blob/main/server.js"
    click REPORT "https://github.com/prince-vaviya/rigged-repo/blob/main/REPORT.md"
    click PKG "https://github.com/prince-vaviya/rigged-repo/blob/main/package.json"

    %% =========================
    %% Styles
    %% =========================
    classDef actor fill:#E8F1FF,stroke:#2B6CB0,stroke-width:2px,color:#102A43
    classDef system fill:#CDE7FF,stroke:#1E5AA8,stroke-width:2px,color:#102A43
    classDef frontend fill:#D9ECFF,stroke:#2B6CB0,stroke-width:2px,color:#102A43
    classDef backend fill:#BFE3FF,stroke:#1E5AA8,stroke-width:2px,color:#102A43
    classDef db fill:#D7F7E5,stroke:#1F7A3F,stroke-width:2px,color:#0B3D1E
    classDef external fill:#FFE3C2,stroke:#C05621,stroke-width:2px,color:#5A2B0C
    classDef secret fill:#FFD6D6,stroke:#C53030,stroke-width:2px,color:#5A1010
    classDef store fill:#E6FFFA,stroke:#2C7A7B,stroke-width:2px,color:#234E52
    classDef warning fill:#FFF3BF,stroke:#B7791F,stroke-width:2px,color:#5A3A0C
    classDef hidden fill:#FFFFFF,stroke:#FFFFFF,color:#FFFFFF
```
