# darwineee/cpproject architecture

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

- Interactive diagram: https://gitdiagram.com/darwineee/cpproject
- Repository: https://github.com/darwineee/cpproject

## Overview

##### Project type and purpose
- This is a monolithic C++ application (“CPProject”) that implements a secure user authentication flow and a points‐based wallet management system.
- It sits between end users (admins and regular users) and two kinds of external systems: an SMTP mail server (for OTP emails) and a local SQLite database (for storing credentials, profiles, and transaction history).

##### File structure
- Top level:
- CMakeLists.txt, CMakePresets.json, CMakeSettings.json – build configuration
- README.md – project overview, features, usage
- CPProject/ directory:
- CPProject.cpp – entry point (CLI UI and orchestrator)
- Five core modules under source and include:
– CredentialReader(.cpp/.h)
– EmailSender(.cpp/.h)
– OTPManager(.cpp/.h)
– UserAuth(.cpp/.h)
– WalletManager(.cpp/.h)

##### README for additional insights
- Dependencies: SQLite3, OpenSSL, Boost, mailio, nlohmann_json
- Features:
- Two‐factor authentication (email OTP)
- Role‐based access (admin vs. regular user)
- Wallet operations (admin top-up/distribute, user transfers)
- Security measures: SQL transaction blocks, password hashing with salt, SQL injection protection

##### Main components and relationships
- CLI Interface (CPProject.exe)
- Core Modules
– CredentialReader: loads configuration, reads credentials from JSON or console
– UserAuth: handles password hashing, salting, login/signup flows
– OTPManager: generates and validates one-time passwords
– EmailSender: sends OTP via SMTP (mailio)
– WalletManager: executes wallet transactions, maintains balances, logs history
- Database: SQLite3 engine (persistent storage)
- External Service: SMTP Mail Server
- Crypto Library: OpenSSL (used by UserAuth and OTPManager)
- Config Parser: nlohmann_json (used by CredentialReader)
- Utility: Boost (date_time for timestamping transactions)

b. Relationships and data flows
- User/Admin → CLI Interface: issues commands (signup, login, view profile, transfer points)
- CLI → CredentialReader → JSON config file
- CLI → UserAuth → SQLite DB (users table, password hashes)
- CLI → OTPManager ↔ OpenSSL (crypto)
- OTPManager → EmailSender → SMTP Server
- CLI → WalletManager ↔ SQLite DB (wallets table, transaction table)
- WalletManager uses Boost to timestamp transactions

c. Architectural patterns and principles
- Modular separation by responsibility (single-responsibility principle)
- Monolithic process with well-defined component boundaries
- Layered interactions: CLI → business logic modules → persistence/external services
- Transactional boundaries: all wallet operations wrapped in SQL transaction blocks

##### Essential elements to capture
- Names of every core class/module
- Data stores and external services
- Direction of control and data flow
- Key technologies alongside each component (e.g., “SQLite3”, “OpenSSL”, “mailio”, “nlohmann_json”, “Boost”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation / CLI"
        direction TB
        CLI["CLI Interface\n(CPProject.exe)"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic Modules"
        direction TB
        CredReader["CredentialReader\n(loads config)"]:::business
        UserAuth["UserAuth\n(password hashing)"]:::business
        OTPMgr["OTPManager\n(generate/validate OTP)"]:::business
        EmailSend["EmailSender\n(send OTP via SMTP)"]:::business
        WalletMgr["WalletManager\n(wallet operations)"]:::business
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        JSONParser["Config Parser\n(nlohmann_json)"]:::infra
        CryptoLib["Crypto Library\n(OpenSSL)"]:::infra
        BoostUtil["Utility\n(Boost date_time)"]:::infra
        SQLiteDB["SQLite3 DB\n(persistent storage)"]:::infra
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        SMTP["SMTP Mail Server"]:::external
    end

    %% Connections
    CLI -->|"reads credentials"| CredReader
    CredReader -->|"parses JSON"| JSONParser

    CLI -->|"signup/login"| UserAuth
    UserAuth -->|"SQL queries"| SQLiteDB

    CLI -->|"initiate OTP"| OTPMgr
    OTPMgr -->|"uses crypto"| CryptoLib
    OTPMgr -->|"request send"| EmailSend
    EmailSend -.->|"SMTP: send mail"| SMTP

    CLI -->|"wallet commands"| WalletMgr
    WalletMgr -->|"SQL queries"| SQLiteDB
    WalletMgr -->|"timestamp"| BoostUtil

    %% Click Events
    click CLI "https://github.com/darwineee/cpproject/blob/master/CPProject/CPProject.cpp"
    click CredReader "https://github.com/darwineee/cpproject/blob/master/CPProject/CredentialReader.cpp"
    click UserAuth "https://github.com/darwineee/cpproject/blob/master/CPProject/UserAuth.cpp"
    click OTPMgr "https://github.com/darwineee/cpproject/blob/master/CPProject/OTPManager.cpp"
    click EmailSend "https://github.com/darwineee/cpproject/blob/master/CPProject/EmailSender.cpp"
    click WalletMgr "https://github.com/darwineee/cpproject/blob/master/CPProject/WalletManager.cpp"
    click JSONParser "https://github.com/darwineee/cpproject/blob/master/CPProject/include/CredentialReader.h"
    click UserAuth "https://github.com/darwineee/cpproject/blob/master/CPProject/include/UserAuth.h"
    click OTPMgr "https://github.com/darwineee/cpproject/blob/master/CPProject/include/OTPManager.h"
    click EmailSend "https://github.com/darwineee/cpproject/blob/master/CPProject/include/EmailSender.h"
    click WalletMgr "https://github.com/darwineee/cpproject/blob/master/CPProject/include/WalletManager.h"
    click CLI "https://github.com/darwineee/cpproject/blob/master/CPProject/include/CPProject.h"
    click RootCMake "https://github.com/darwineee/cpproject/blob/master/CMakeLists.txt"
    click SubCMake "https://github.com/darwineee/cpproject/blob/master/CPProject/CMakeLists.txt"

    %% Styles
    classDef presentation fill:#D6EAF8,stroke:#21618C,color:#1B4F72;
    classDef business fill:#AED6F1,stroke:#1A5276,color:#154360;
    classDef infra fill:#ABEBC6,stroke:#239B56,color:#1D8348;
    classDef external fill:#F9E79F,stroke:#B9770E,color:#7E5109;
```
