# cappricio-securities/camjacking architecture

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

- Interactive diagram: https://gitdiagram.com/cappricio-securities/camjacking
- Repository: https://github.com/cappricio-securities/camjacking

## Overview

##### Project type and purpose
- This is a Node.js-based CLI/web tool (“CamJacking”) that spins up a local Express server with EJS views and static assets, captures webcam photos in the browser (via client-side JS), and forwards those photos to a Telegram chat using a bot.

##### File structure
- Top level:
- app.js – entry point that bootstraps the CLI interface and starts the Express app
- includes/ – core modules (bot.js, config.js, help.js, route.js)
- views/ – EJS templates (index.ejs plus header/footer components)
- Assets/ – public front-end assets (css/style.css, js/cam.js)
- You see the MVC pattern:
- Routes in includes/route.js
- Views in views/
- Public assets in Assets/
- CLI behavior and configuration (includes/help.js, includes/config.js) integrate with app.js.

##### README for additional insights
- The tool is installed globally, invoked with `CamJacking -p <port>` and `-c <chatid>`.
- It exposes a UI where the user grants webcam permission; snapshots are captured and saved under `~/camjacking/`.
- Bot module sends images to Telegram via the Bot API.

a. Main components:
1. CLI Launcher (CamJacking command-line interface)
2. Express Server (app.js + includes/route.js + includes/config.js)
3. View Layer (EJS templates + Assets/css + Assets/js)
4. Browser Client (renders UI, runs cam.js)
5. Bot Module (includes/bot.js communicating with Telegram API)
6. File Storage (local filesystem under `~/camjacking/`)
7. External Service (Telegram Bot API)
b. Relationships & interactions:
- CLI Launcher parses flags (`-p`, `-c`), passes config into Express Server.
- Express Server exposes HTTP endpoints (`GET /`, `POST /snapshot`).
- Browser Client requests `/`, gets EJS-rendered page + static assets.
- cam.js in the browser captures webcam frames, POSTs image data to `POST /snapshot`.
- Express Server route receives image, writes file to disk, and invokes Bot Module.
- Bot Module calls Telegram Bot API, sending the image to the configured chat ID.
c. Architectural patterns/design principles:
- MVC-style separation (routes/controllers vs. views vs. public assets)
- Modularization of concerns: config, help, routes, bot logic in separate modules
- Single-process, event-driven server with a thin client capturing media
d. Relevant technologies/frameworks/libraries:
- Node.js + Express.js
- EJS templating engine
- Client-side webcam capture via JavaScript (getUserMedia in cam.js)
- Telegram Bot API for outbound notifications

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Launcher
    CLI["CLI Launcher"]:::internal

    %% Express Server and Modules
    subgraph "Express Server" 
        direction TB
        AppJS["app.js"]:::internal
        Config["Config Module"]:::internal
        Help["Help Module"]:::internal
        Route["Routing Logic"]:::internal
    end

    %% View Layer
    Views["EJS Views"]:::view

    %% Static Assets
    CSS["style.css"]:::internal
    CamJS["cam.js"]:::internal

    %% Browser Client
    Browser["Browser Client"]:::client

    %% Bot Module
    Bot["Bot Module"]:::internal

    %% File Storage
    FileStore["Image Storage"]:::internal

    %% External Service
    Telegram["Telegram Bot API"]:::external

    %% Connections
    CLI -->|"bootstrap server"| AppJS
    CLI -->|"load config"| Config
    CLI -->|"show help"| Help

    AppJS -->|"use routes"| Route
    AppJS -->|"render view"| Views
    AppJS -->|"serve assets"| CSS
    AppJS -->|"serve assets"| CamJS

    Browser -->|"GET /"| AppJS
    AppJS -->|"GET / -> serve index"| Browser

    Browser -->|"load cam.js"| CamJS
    CamJS -->|"POST /snapshot"| Route

    Route -->|"write snapshot"| FileStore
    Route -->|"call sendPhoto()"| Bot

    Bot -->|"sendPhoto(chatid,file)"| Telegram

    %% Click Events
    click CLI "https://github.com/cappricio-securities/camjacking/blob/main/app.js"
    click Config "https://github.com/cappricio-securities/camjacking/blob/main/includes/config.js"
    click Help "https://github.com/cappricio-securities/camjacking/blob/main/includes/help.js"
    click AppJS "https://github.com/cappricio-securities/camjacking/blob/main/app.js"
    click Route "https://github.com/cappricio-securities/camjacking/blob/main/includes/route.js"
    click Views "https://github.com/cappricio-securities/camjacking/tree/main/views/"
    click CSS "https://github.com/cappricio-securities/camjacking/blob/main/Assets/css/style.css"
    click CamJS "https://github.com/cappricio-securities/camjacking/blob/main/Assets/js/cam.js"
    click Bot "https://github.com/cappricio-securities/camjacking/blob/main/includes/bot.js"
    click FileStore "https://github.com/cappricio-securities/camjacking/tree/main/images/"

    %% Styles
    classDef internal fill:#D6EAF8,stroke:#1B4F72
    classDef client fill:#D5F5E3,stroke:#196F3D
    classDef external fill:#FADBD8,stroke:#922B21
    classDef view fill:#FCF3CF,stroke:#B7950B
```
