# safal-gautamm/pwdmanager_api architecture

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

- Interactive diagram: https://gitdiagram.com/safal-gautamm/pwdmanager_api
- Repository: https://github.com/safal-gautamm/pwdmanager_api

## Overview

##### Project Type & Purpose
- A monolithic RESTful API for encrypted password storage, written in C++ using the Drogon framework.
- No external database—uses a JSON file for persistence. Educational/demo focus.

##### File Structure
- main.cc – application entry point, starts Drogon server
- controllers/pwdmanager.{cc,h} – HTTP endpoint handlers (create, add, view, delete)
- models/model.json – JSON schema or model definition
- passwords.json – runtime storage of encrypted passwords
- config.json & config.yaml – server settings (port, file paths, encryption parameters)
- index.html – static instruction page served at “/”

##### Extract Key Components
A. Client / Browser (HTTP client or curl)
B. Drogon Web Server
C. Router & Controllers
– pwdmanagerController: dispatches endpoints (/create, /add, /view, /delete)
D. Service & Business Logic
– Account/API-key management
– XOR encryption/decryption module
E. Data Layer
– JSON file I/O (passwords.json)
– Model definitions (models/model.json)
F. Configuration Loader
G. Static File Handler (serving index.html)

##### Relationships & Data Flows
1) Client → HTTP request → Drogon Router
2) Router → Specific Controller method
3) Controller → Calls Service functions (encrypt/decrypt, validation)
4) Service → Reads/writes passwords.json (via JSON library)
5) Controller → Builds JSON HTTP response → Client
6) Client GET “/” → Server returns index.html

##### Patterns & Principles
- MVC-inspired layering: controllers separate from business logic and data I/O
- Configuration-driven startup (JSON/YAML)
- Single-process design—no external services or microservices

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client / Browser"]:::client
    click Client "https://github.com/safal-gautamm/pwdmanager_api/blob/main/index.html"

    subgraph "Drogon Web Server"
        direction TB
        Entry["main.cc (Entry Point)"]:::web
        click Entry "https://github.com/safal-gautamm/pwdmanager_api/blob/main/main.cc"

        Router["Router"]:::web
        Controller["pwdmanagerController"]:::web
        click Controller "https://github.com/safal-gautamm/pwdmanager_api/blob/main/controllers/pwdmanager.cc"
        Service["Encryption & Validation Service"]:::biz
        click Service "https://github.com/safal-gautamm/pwdmanager_api/blob/main/controllers/pwdmanager.cc"
        Static["Static File Handler"]:::web
        click Static "https://github.com/safal-gautamm/pwdmanager_api/blob/main/index.html"
    end

    subgraph "Data Layer"
        DataFile["passwords.json"]:::data
        click DataFile "https://github.com/safal-gautamm/pwdmanager_api/blob/main/passwords.json"
        ModelDef["models/model.json"]:::data
        click ModelDef "https://github.com/safal-gautamm/pwdmanager_api/blob/main/models/model.json"
    end

    subgraph "Configuration Loader"
        CFG1["config.json"]:::config
        click CFG1 "https://github.com/safal-gautamm/pwdmanager_api/blob/main/config.json"
        CFG2["config.yaml"]:::config
        click CFG2 "https://github.com/safal-gautamm/pwdmanager_api/blob/main/config.yaml"
    end

    Client -->|"HTTP request"| Router
    Client -->|"GET /"| Static
    Entry -->|"initializes server"| Router
    Router -->|"POST /create, /add, /view, /delete"| Controller
    Controller -->|"calls encrypt/decrypt"| Service
    Service -->|"read/write JSON"| DataFile
    Service -->|"uses schema"| ModelDef
    Controller -->|"returns JSON response"| Client
    CFG1 -->|"load settings"| Entry
    CFG2 -->|"load settings"| Entry

    classDef client fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef web fill:#ABEBC6,stroke:#1D8348,color:#0B5345;
    classDef biz fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef data fill:#F5CBA7,stroke:#A04000,color:#4D5656;
    classDef config fill:#D5D8DC,stroke:#566573,color:#1C2833;
```
