# sashi-u/juice-shop architecture

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

- Interactive diagram: https://gitdiagram.com/sashi-u/juice-shop
- Repository: https://github.com/sashi-u/juice-shop

## Overview

##### Project type and purpose
- This is a full‑stack, intentionally vulnerable web application (“OWASP Juice Shop”) built for security training, CTFs and demonstration of common web vulnerabilities.
- The README confirms it’s a Node.js/Express backend serving a single‑page Angular front end, with persistence in MongoDB (and optional SQLite for packaged distributions), plus additional services (e.g. FTP folder, file uploads, JWT key server, socket.io notifications).

##### File structure
- Top‑level:
- app.js / server.js – entry points
- config/ – environment‑specific YAML settings
- data/ – data layer (Mongo connector, static data, caching)
- frontend/ – Angular workspace (src/app components, services, assets, environments, build configs)
- routes/ – Express route handlers (REST API endpoints, file server, key server, OAuth, 2FA, etc.)
- models/ – Mongoose schema definitions
- lib/ – startup routines, utilities, security validators, custom middleware
- views/ – server‑side Jade templates for optional pages (e.g. userProfile, themes)
- test/ – unit/integration tests (Mocha/Chai for API, Protractor e2e)
- Dockerfile, Vagrant scripts, CI configs – deployment artifacts
- swagger.yml – API documentation

##### README for additional insights
- Confirms use cases: deploy on Heroku, Docker, Vagrant, EC2, Azure.
- Mentions configuration via YAML files in /config.
- Points to architecture overview on the project site (but we’ll reverse‑engineer from file tree).

##### Detailed coverage
- Swagger documentation component and testing pipelines (optional CI logos).
- Config injection: config/*.yml → Express Startup.
- Don’t forget the key external services (Heroku, Docker Hub).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Browser Client" 
        direction TB
        Angular["Angular SPA"]:::frontend
        TwoFactorService["Two‑Factor Auth Service"]:::frontend
        SocketService["WebSocket Service"]:::frontend
    end

    %% Backend/Application Layer
    subgraph "Backend Application" 
        direction TB

        subgraph "Startup & Configuration"
            direction TB
            Configuration["Configuration Module"]:::backend
            StartupServices["Startup Services"]:::backend
        end

        subgraph "Express API"
            direction TB
            Routes["API Route Handlers"]:::backend
            FileServer["File Server & Uploads"]:::backend
            KeyServer["JWT Key Server"]:::backend
            OAuth2FA["OAuth & 2FA Routes"]:::backend
            SwaggerDoc["Swagger Documentation"]:::backend
            Views["Server‑Side Views"]:::backend
        end

        subgraph "Utilities & Data Layer"
            direction TB
            Utils["Utilities & Security Helpers"]:::backend
            DataLayer["Business Data Layer"]:::backend
            Models["Persistence Models"]:::backend
        end
    end

    %% Data & Storage Layer
    subgraph "Data & Storage"
        direction TB
        MongoDB[(MongoDB)]:::data
        FileStorage[(File Storage)]:::data
    end

    %% External Deployment
    subgraph "Deployment & CI/CD"
        direction TB
        DockerVagrant["Docker / Vagrant / CI"]:::external
        Cloud["Heroku / AWS / Azure"]:::external
        Tests["Automated Tests"]:::external
    end

    %% Connections
    Angular -->|"REST API calls"| Routes
    Angular -->|"WebSocket handshake"| SocketService
    SocketService -->|connects to| StartupServices

    Configuration -->|loaded by| StartupServices
    StartupServices -->|initializes| DataLayer
    StartupServices -->|registers WS events| RegisterWS

    Routes -->|use utils| Utils
    Routes -->|invoke data layer| DataLayer
    Routes -->|use models| Models
    FileServer -->|stores/retrieves| FileStorage
    KeyServer -->|serves keys from| JwtPub
    OAuth2FA -->|handles| TwoFactorService

    DataLayer -->|CRUD via Mongoose| MongoDB
    Utils -->|logs via| Logger
    Utils -->|validates| Insecurity

    Routes -->|exposes| SwaggerDoc
    Routes -->|renders| Views

    DockerVagrant -->|deploys| BackendApplication
    Cloud -->|hosts| Angular
    Tests -->|validate| Routes

    %% Click Events
    click Angular "https://github.com/sashi-u/juice-shop/tree/master/frontend/"
    click TwoFactorService "https://github.com/sashi-u/juice-shop/blob/master/frontend/src/app/Services/two‑factor‑auth‑service.ts"
    click SocketService "https://github.com/sashi-u/juice-shop/blob/master/frontend/src/app/Services/socket‑io.service.ts"
    click Configuration "https://github.com/sashi-u/juice-shop/blob/master/config/default.yml"
    click StartupServices "https://github.com/sashi-u/juice-shop/tree/master/lib/startup/"
    click RegisterWS "https://github.com/sashi-u/juice-shop/blob/master/lib/startup/registerWebsocketEvents.js"
    click Utils "https://github.com/sashi-u/juice-shop/blob/master/lib/utils.js"
    click Logger "https://github.com/sashi-u/juice-shop/blob/master/lib/logger.js"
    click Insecurity "https://github.com/sashi-u/juice-shop/blob/master/lib/insecurity.js"
    click FileServer "https://github.com/sashi-u/juice-shop/blob/master/routes/fileServer.js"
    click KeyServer "https://github.com/sashi-u/juice-shop/blob/master/routes/keyServer.js"
    click JwtPub "https://github.com/sashi-u/juice-shop/blob/master/encryptionkeys/jwt.pub"
    click OAuth2FA "https://github.com/sashi-u/juice-shop/blob/master/routes/2fa.js"
    click SwaggerDoc "https://github.com/sashi-u/juice-shop/blob/master/swagger.yml"
    click Views "https://github.com/sashi-u/juice-shop/blob/master/views/userProfile.jade"
    click DataLayer "https://github.com/sashi-u/juice-shop/blob/master/data/mongodb.js"
    click DataLayer "https://github.com/sashi-u/juice-shop/blob/master/data/datacache.js"
    click DataLayer "https://github.com/sashi-u/juice-shop/blob/master/data/datacreator.js"
    click Models "https://github.com/sashi-u/juice-shop/blob/master/models/user.js"
    click Models "https://github.com/sashi-u/juice-shop/blob/master/models/product.js"
    click DockerVagrant "https://github.com/sashi-u/juice-shop/tree/master/Dockerfile"
    click DockerVagrant "https://github.com/sashi-u/juice-shop/tree/master/vagrant/Vagrantfile"
    click DockerVagrant "https://github.com/sashi-u/juice-shop/blob/master/.gitlab-ci.yml"
    click DockerVagrant "https://github.com/sashi-u/juice-shop/blob/master/.travis.yml"
    click Tests "https://github.com/sashi-u/juice-shop/tree/master/test/api/"
    click Tests "https://github.com/sashi-u/juice-shop/tree/master/test/e2e/"
    click Tests "https://github.com/sashi-u/juice-shop/tree/master/test/server/"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#3B83BD,color:#003366
    classDef backend fill:#DFF2D8,stroke:#60A84A,color:#2F4F2F
    classDef data fill:#FFE8C4,stroke:#E69C00,color:#804000
    classDef external fill:#F0F0F0,stroke:#999999,color:#333333
```
