# ausaf-ahmad-ansari/chitnotez architecture

> Architecture diagram of the GitHub repository ausaf-ahmad-ansari/chitnotez, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ausaf-ahmad-ansari/chitnotez
- Repository: https://github.com/ausaf-ahmad-ansari/chitnotez

## Overview

##### Project Type and Purpose
- This is a monolithic full-stack web application.
- The “server” directory implements an MVC pattern:
- Models: server/models (User, Notes)
- Views: views/… EJS templates
- Controllers & Routes: server/controllers + server/routes
- The “public” directory holds static assets (CSS, images).
- app.js ties it all together and configures Express, DB, middleware.

##### Main Components
a. Client (Browser)
b. CDN or Static Asset Host (public/*)
c. Web Server (Express app in app.js)
d. Middleware Layer (e.g., checkAuth)
e. Controllers & Routers (auth, chat, dashboard, main)
f. Data Layer (Database, via server/config/db.js)
g. Templating Engine (EJS views/*)
h. External Services (if any, e.g., third-party chat API)

##### Relationships & Data Flows
- Client → HTTP Request → Express Router (server/routes/*.js)
- Router → Middleware (server/middleware/checkAuth.js) → Controller
- Controller → Model Operations (server/models/*.js via Mongoose or ORM)
- Model → Database (MongoDB or SQL)
- Controller → Renders EJS View → HTML Response → Client
- Static asset requests (CSS, JS, images) served directly from public/*

##### Architectural Patterns
- MVC: clear separation of Models, Views, Controllers
- Route-Level Middleware for authentication
- Server-Side Rendering with EJS
- Single server process (monolith) likely deployed to Vercel (vercel.json)

##### Technologies & Frameworks
- Node.js & Express.js
- EJS for templating
- Mongoose (or another ORM) for DB layer (check server/config/db.js)
- Vercel for deployment
- dotenv (.env) for configuration

- Optional: add notes about environment/config (e.g., use of .env for secrets).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client and Static Assets
    subgraph "Client & Static Assets"
        direction TB
        Client["Browser (Client)"]:::client
        subgraph "Static Assets (public)" 
            direction TB
            CSS["CSS Files"]:::static
            IMG["Image Files"]:::static
        end
    end

    %% Server Components
    subgraph "Server (Backend)" 
        direction TB
        ExpressApp["Express App\n(app.js)"]:::server
        DBConfig["DB Config\n(server/config/db.js)"]:::server
        subgraph "Routing Layer"
            direction TB
            AuthRouter["Authentication Routes"]:::server
            ChatRouter["Chat Routes"]:::server
            DashRouter["Dashboard Routes"]:::server
            MainRouter["Main Routes"]:::server
        end
        subgraph "Middleware"
            direction TB
            CheckAuth["Auth Middleware\n(checkAuth.js)"]:::server
        end
        subgraph "Controllers"
            direction TB
            DashCtrl["Dashboard Controller"]:::server
            MainCtrl["Main Controller"]:::server
        end
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::server
            NotesModel["Notes Model"]:::server
        end
        subgraph "Views (EJS Templates)"
            direction TB
            subgraph "Root Templates"
                INDEX["index.ejs"]:::server
                ABOUT["about.ejs"]:::server
                ERR404["404.ejs"]:::server
            end
            subgraph "Layouts"
                LAYOUT_MAIN["layouts/main.ejs"]:::server
                LAYOUT_FRONT["front-page.ejs"]:::server
                LAYOUT_DASH["dashboard.ejs"]:::server
            end
            subgraph "Partials"
                HEADER["partials/header.ejs"]:::server
                FOOTER["partials/footer.ejs"]:::server
                HEADER_DASH["partials/header_dashboard.ejs"]:::server
            end
            subgraph "Dashboard Views"
                DASH_INDEX["dashboard/index.ejs"]:::server
                DASH_ADD["dashboard/add.ejs"]:::server
                DASH_SEARCH["dashboard/search.ejs"]:::server
                DASH_VIEW["dashboard/view-note.ejs"]:::server
            end
        end
    end

    %% Database
    MongoDB["MongoDB\n(Database)"]:::db

    %% Flows
    Client -->|"HTTP Requests"| ExpressApp
    Client -->|"GET static files"| CSS
    Client -->|"GET static files"| IMG
    ExpressApp -->|"uses DB Config"| DBConfig
    ExpressApp -->|"routes to"| AuthRouter
    ExpressApp -->|"routes to"| ChatRouter
    ExpressApp -->|"routes to"| DashRouter
    ExpressApp -->|"routes to"| MainRouter

    AuthRouter -->|"applies"| CheckAuth
    ChatRouter -->|"applies"| CheckAuth
    DashRouter -->|"applies"| CheckAuth
    MainRouter -->|"applies"| CheckAuth

    CheckAuth -->|"calls"| DashCtrl
    CheckAuth -->|"calls"| MainCtrl

    DashCtrl -->|"queries"| UserModel
    DashCtrl -->|"queries"| NotesModel
    MainCtrl -->|"queries"| UserModel

    UserModel -->|"reads/writes"| MongoDB
    NotesModel -->|"reads/writes"| MongoDB

    DashCtrl -->|"renders"| DASH_INDEX
    DashCtrl -->|"renders"| DASH_VIEW
    MainCtrl -->|"renders"| INDEX

    %% Click Events
    click ExpressApp "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/app.js"
    click CSS "https://github.com/ausaf-ahmad-ansari/chitnotez/tree/master/public/"
    click IMG "https://github.com/ausaf-ahmad-ansari/chitnotez/tree/master/public/"
    click DBConfig "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/config/db.js"
    click CheckAuth "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/middleware/checkAuth.js"
    click DashCtrl "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/controllers/dashboardController.js"
    click MainCtrl "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/controllers/mainController.js"
    click UserModel "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/models/User.js"
    click NotesModel "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/models/Notes.js"
    click AuthRouter "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/routes/auth.js"
    click ChatRouter "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/routes/chat.js"
    click DashRouter "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/routes/dashboard.js"
    click MainRouter "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/server/routes/index.js"
    click INDEX "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/index.ejs"
    click ABOUT "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/about.ejs"
    click ERR404 "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/404.ejs"
    click LAYOUT_MAIN "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/layouts/main.ejs"
    click LAYOUT_FRONT "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/layouts/front-page.ejs"
    click LAYOUT_DASH "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/layouts/dashboard.ejs"
    click HEADER "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/partials/header.ejs"
    click FOOTER "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/partials/footer.ejs"
    click HEADER_DASH "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/partials/header_dashboard.ejs"
    click DASH_INDEX "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/dashboard/index.ejs"
    click DASH_ADD "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/dashboard/add.ejs"
    click DASH_SEARCH "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/dashboard/search.ejs"
    click DASH_VIEW "https://github.com/ausaf-ahmad-ansari/chitnotez/blob/master/views/dashboard/view-note.ejs"

    %% Styles
    classDef client fill:#AEDFF7,stroke:#0366d6,color:#000
    classDef server fill:#D5F5E3,stroke:#239B56,color:#000
    classDef db fill:#FAD7A0,stroke:#D35400,color:#000
    classDef static fill:#E0E0E0,stroke:#888888,color:#000
```
