# pratham0809/hack-this-fall architecture

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

- Interactive diagram: https://gitdiagram.com/pratham0809/hack-this-fall
- Repository: https://github.com/pratham0809/hack-this-fall

## Overview

##### Project type and purpose
- This is a full-stack, monolithic web application (“KnowledgeKnights”) providing educational games and quizzes.
- Frontend: EJS-templated HTML, SCSS/CSS, Tailwind, static game UIs (Dino, Space, Coin Scraper), TensorFlow.js model for sketch recognition.
- Backend: Node.js + Express.js, MVC pattern (routes → controllers → models), Twilio OTP integration, MongoDB for persistence.
- Use cases: user signup/login with OTP, play games (score persisted), quiz platform, leaderboards, teacher dashboard.

##### File structure
- Top-level
- README.md, .gitignore
- Server/ – contains entire application
- Server/
- index.js – Express entry point, middleware setup, route mounting
- /routes – Express routers per feature (user-routes.js, games.js, twilio-sms.js, dashboard.js)
- /controller – business logic (user_controller.js, games.js, dashboard.js, twilio-sms.js)
- /models – Mongoose schemas: User, Quiz, Leaderboard
- /database/connection.js – MongoDB connection
- /public – static assets: CSS/JS, images, TensorFlow.js model files, sketch.js
- /views – EJS templates organized by feature (login, games, dashboard, etc.)
- package.json / .env.example – dependencies and environment settings

##### Key insights from the README
- System architecture follows MVC pattern
- Twilio OTP for authentication
- Frontend prototype -> EJS + SCSS + Tailwind
- External ML model loaded client-side (model.json + .bin)

- Client Browser – loads EJS views & static assets; runs game logic (sketch.js, TensorFlow.js)
- Web Server (Express) –
– Router Layer (/routes)
– Controller Layer (/controller)
– Model Layer (/models) – Mongoose schemas
– Static Asset Server (/public)
- MongoDB – stores Users, Quizzes, Leaderboards
- External Service – Twilio OTP API
- (Optionally) Client-side ML Inference – TensorFlow.js model files (served by /public)
1. Browser → HTTP Request → Express routers
2. Routers → Controller logic → Model operations → MongoDB
3. Controller → Twilio API calls (HTTP) → Twilio OTP → Controller → Browser
4. Browser loads static JS (sketch.js) & TensorFlow model from /public → ML inference locally
5. Game UI sends score submission → Express → MongoDB → Leaderboard updates
6. Teacher dashboard UI Fetches aggregated data → Express → MongoDB → EJS view render
c. Architectural patterns & design principles
- MVC separation: clear Router / Controller / Model layers
- REST-style endpoints for user, game, dashboard, Twilio
- Static asset delivery for client-side ML + game code
- Single process, monolithic deployment
d. Key technologies & libraries (annotate near components):
- Node.js, Express.js
- MongoDB, Mongoose
- EJS templating, SCSS/Tailwind CSS, p5.js or custom sketch.js
- Twilio OTP service (twilio-sms.js)
- TensorFlow.js for drawing recognition

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client Browser"]:::compute

    subgraph "Express Server"
        direction TB
        Index["index.js"]:::compute

        subgraph "Router Layer"
            direction TB
            UserRoutes["user-routes.js"]:::compute
            GameRoutes["games.js (routes)"]:::compute
            TwilioRoutes["twilio-sms.js"]:::compute
            DashboardRoutes["dashboard.js (routes)"]:::compute
        end

        subgraph "Controller Layer"
            direction TB
            UserCtrl["user_controller.js"]:::compute
            GamesCtrl["games.js (controller)"]:::compute
            TwilioCtrl["twilio-sms.js (controller)"]:::compute
            DashboardCtrl["dashboard.js (controller)"]:::compute
        end

        subgraph "Model Layer"
            direction TB
            UserModel["user.js"]:::compute
            QuizModel["quiz.js"]:::compute
            LeaderboardModel["leaderboard.js"]:::compute
        end

        DBConnection["connection.js"]:::compute

        subgraph "Static Asset Server"
            direction TB
            Public["public/"]:::static
        end
    end

    MongoDB["MongoDB"]:::db
    TwilioAPI["Twilio OTP API"]:::external
    StaticModelFiles["TensorFlow.js Model Files"]:::static

    Client -->|"HTTP Request"| Index
    Index --> UserRoutes
    Index --> GameRoutes
    Index --> TwilioRoutes
    Index --> DashboardRoutes

    UserRoutes --> UserCtrl
    GameRoutes --> GamesCtrl
    TwilioRoutes --> TwilioCtrl
    DashboardRoutes --> DashboardCtrl

    UserCtrl --> UserModel
    GamesCtrl --> QuizModel
    GamesCtrl --> LeaderboardModel
    DashboardCtrl --> QuizModel
    DashboardCtrl --> LeaderboardModel

    UserModel --> DBConnection
    QuizModel --> DBConnection
    LeaderboardModel --> DBConnection
    DBConnection --> MongoDB

    TwilioCtrl -.->|"HTTP Call"| TwilioAPI
    Client -->|"Loads EJS & Static"| Public
    Public --> StaticModelFiles
    Client -->|"ML Inference"| StaticModelFiles

    classDef compute fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef db fill:#E2F0CB,stroke:#519839,color:#519839;
    classDef external fill:#F0F0F0,stroke:#AAAAAA,color:#333333,stroke-dasharray: 5 5;
    classDef static fill:#FFF4C1,stroke:#D4A72C,color:#8C6A00;

    click Index "https://github.com/pratham0809/hack-this-fall/blob/main/Server/index.js"
    click UserRoutes "https://github.com/pratham0809/hack-this-fall/blob/main/Server/routes/user-routes.js"
    click GameRoutes "https://github.com/pratham0809/hack-this-fall/blob/main/Server/routes/games.js"
    click TwilioRoutes "https://github.com/pratham0809/hack-this-fall/blob/main/Server/routes/twilio-sms.js"
    click DashboardRoutes "https://github.com/pratham0809/hack-this-fall/blob/main/Server/routes/dashboard.js"
    click UserCtrl "https://github.com/pratham0809/hack-this-fall/blob/main/Server/controller/user_controller.js"
    click GamesCtrl "https://github.com/pratham0809/hack-this-fall/blob/main/Server/controller/games.js"
    click TwilioCtrl "https://github.com/pratham0809/hack-this-fall/blob/main/Server/controller/twilio-sms.js"
    click DashboardCtrl "https://github.com/pratham0809/hack-this-fall/blob/main/Server/controller/dashboard.js"
    click UserModel "https://github.com/pratham0809/hack-this-fall/blob/main/Server/models/user.js"
    click QuizModel "https://github.com/pratham0809/hack-this-fall/blob/main/Server/models/quiz.js"
    click LeaderboardModel "https://github.com/pratham0809/hack-this-fall/blob/main/Server/models/leaderboard.js"
    click DBConnection "https://github.com/pratham0809/hack-this-fall/blob/main/Server/database/connection.js"
    click Public "https://github.com/pratham0809/hack-this-fall/tree/main/Server/public/"
    click StaticModelFiles "https://github.com/pratham0809/hack-this-fall/blob/main/Server/public/model/model.json"
```
