# erev0s/vampi architecture

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

- Interactive diagram: https://gitdiagram.com/erev0s/vampi
- Repository: https://github.com/erev0s/vampi

## Overview

##### Project Type & Purpose
- VAmPI is a Flask-based API intentionally designed with vulnerabilities (e.g., SQL Injection, Broken Object Level Authorization, etc.) for the purpose of testing and evaluating security tools, as well as for educational demonstrations.
- The README explains that it offers a token-based authentication mechanism and includes endpoints for user registration, login, book management, and a debug endpoint.

##### Analyzing the File Structure
- Key directories/files:
- Root-level files: app.py (main entry point), config.py, Dockerfile, docker-compose.yaml, and requirements.txt.
- api_views/ directory: Contains the definitions for endpoints (books.py, users.py, main.py, and json_schemas.py) that define the API’s behavior.
- models/ directory: Holds the data models (books_model.py, user_model.py) representing business logic and database entities.
- database/ directory: Contains database initialization/population code. A specific endpoint (/createdb) in the API is used to trigger these routines.
- openapi_specs/ directory: Provides OpenAPI 3 specifications and a Postman collection for API documentation and testing.
- Presence of Docker-related files (.dockerignore, Dockerfile, docker-compose.yaml) which indicate container-based deployment, including two different configurations (secure and insecure) as mentioned in the README.

##### Main Components & Their Relationships
- Web Server / Application Layer: Represented by app.py running the Flask application.
- API Views: Group the endpoints defined in the api_views/ directory. This separates endpoints concerning users, books, and any shared schemas.
- Models & Database: The models/ directory encapsulates the data layer. The database/ directory then initializes and populates (via the /createdb endpoint) the actual database used by these models.
- Configuration & Environment: The config.py along with environment variables (controlled via Dockerfile and docker-compose) govern security aspects such as vulnerability mode (switching between vulnerable and secure) and token time-to-live settings.
- Documentation & Developer Tools: OpenAPI specs and available Swagger UI (/ui endpoint) provide the interactive documentation interface.
- Containerization: Dockerfile and docker-compose configurations illustrate the application packaging and deployment, including the ability to run different instances (secure/insecure) on different ports.

##### Important Architectural Patterns & Design Principles
- Separation of concerns: The API endpoints (in api_views) are clearly separated from data models (in models) and the database schema/logic.
- Configuration management: Environmental variable configuration (especially regarding security settings) is centralized in the Dockerfile/app.py.
- API-centric design: Emphasize RESTful API principles with clear endpoint definitions and use of an OpenAPI specification for standardization.
- Containerization: Use of Docker enhances consistency across environments, making it easier to switch modes (vulnerable vs. secure).

- Clear Labels:
- “Flask Application (app.py)”
- “API Views (Users, Books, Main, JSON Schemas)”
- “Data Models (books_model, user_model)”
- “Database (Initialization and population via /createdb)”
- “Configuration (env vars, config.py, vulnerability switch, token TTL)”
- “Deployment Container (Docker/Docker Compose)”
- “API Documentation (Swagger UI, OpenAPI Specs)”
- Client request flows to the Flask App.
- Internal routing from API Views to Models/Database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CL("Client"):::client

    subgraph "Application Layer"
        FA("Flask Application (app.py)"):::app
        CF("Configuration (config.py)"):::config
        AV("API Views (Endpoints)"):::api
    end

    subgraph "Data Layer"
        DM("Data Models (models/)"):::models
        DB("Database (Initialization via /createdb)"):::database
    end

    subgraph "Containerization & Deployment"
        DF("Dockerfile"):::deployment
        DC("docker-compose.yaml"):::deployment
        DG(".dockerignore"):::deployment
    end

    subgraph "API Documentation"
        AP("API Documentation & Developer Tools"):::documentation
    end

    %% Relationships
    CL -->|"sendsRequest"| FA
    FA -->|"routesTo"| AV
    AV -->|"callsBusinessLogic"| DM
    DM -->|"persistsTo"| DB
    FA -->|"loads"| CF
    FA -->|"exposesUI"| AP
    DF --> FA
    DC --> FA
    DG --> FA

    %% Click Events
    click FA "https://github.com/erev0s/vampi/blob/master/app.py"
    click AV "https://github.com/erev0s/vampi/tree/master/api_views/"
    click DM "https://github.com/erev0s/vampi/tree/master/models/"
    click DB "https://github.com/erev0s/vampi/blob/master/database/__init__.py"
    click CF "https://github.com/erev0s/vampi/blob/master/config.py"
    click DF "https://github.com/erev0s/vampi/tree/master/Dockerfile"
    click DC "https://github.com/erev0s/vampi/blob/master/docker-compose.yaml"
    click DG "https://github.com/erev0s/vampi/blob/master/.dockerignore"
    click AP "https://github.com/erev0s/vampi/tree/master/openapi_specs/"

    %% Style Definitions
    classDef client fill:#F8F9FA,stroke:#343A40,stroke-width:2px;
    classDef app fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef api fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef models fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#842029,stroke-width:2px;
    classDef config fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef deployment fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef documentation fill:#f5c6cb,stroke:#721c24,stroke-width:2px;
```
