# lovechoudoufu/baselinecheck_cdf architecture

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

- Interactive diagram: https://gitdiagram.com/lovechoudoufu/baselinecheck_cdf
- Repository: https://github.com/lovechoudoufu/baselinecheck_cdf

## Overview

##### Main Components
- Web Frontend: The user interface is built using HTML templates (in app/templates) and static assets (in app/static, including CSS, JS, and third‐party plugins like AdminLTE, Bootstrap, FontAwesome, etc.). This layer is responsible for displaying login pages, reports, and options for both online and offline modes.
- Web Backend: The Flask application (notice the app/__init__.py file and the separation into modules like app/auth and app/main) handles routing, user authentication (admin/login), form handling, and page rendering. It implements the controller and view logic in an MVC-like pattern.
- Database Layer: The presence of baseline.sqlite and the database setup module (app/dbset.py) indicates that the tool uses SQLite to store user accounts, baseline check records, and potentially other configuration or result data.
- Baseline Check Logic (Models/Business Logic): The models directory contains various modules (e.g., Check_Lin.py, Check_Win.py, Ssh_Exec.py, Smb_Exec.py, and others) that implement the core baseline check functions. They include scripts for executing checks on Linux and Windows, managing offline script downloads, and processing results.
- External Scripts/Tools: The models/Script and models/Tools directories include scripts (e.g., linuxcheck.sh, windows-2008.bat) and executables (e.g., PsExec.exe) used for remote baseline checks. These may be invoked by the backend for online checks or provided for offline execution.
- Configuration: The conf directory (with conf/config.py) centralizes configuration settings, such as environment-specific parameters and potential security-related options.

##### Out Relationships and Interactions
- Users in the browser interact with the Web Frontend, which submits forms (login, IP/port, credentials) to endpoints implemented in app/auth/views.py and app/main/view.py.
- The Backend handles the business logic, calling functions in the models directory to perform the actual baseline checking. For online mode, the backend may invoke functions/scripts to remotely connect and run checks (leveraging Ssh_Exec.py and Smb_Exec.py).
- The backend interacts with the SQLite database (baseline.sqlite) using appropriate modules (likely via app/dbset.py) to store or retrieve check results and user info.
- Offline mode is supported by providing downloadable scripts (see the static/download and models/Script directories) that administrators can run directly on target systems. After execution, the results are uploaded back through the web interface.
- Configuration settings in conf/config.py determine how the various layers (web server, database, script execution) collaborate.

##### Architectural Patterns & Design Principles
- MVC (Model-View-Controller): The clear separation between templates (View), route handlers (Controller), and business logic/data management (Model) ensures clean organization.
- Modularization: Splitting functionality into distinct directories (auth, main, models, conf) demonstrates a commitment to separation of concerns.
- Extensibility: The design allows adjustments—for example, adding new baseline checks or modifying the front end for a better user experience.

##### Relevant Technologies
- Python3 and Flask as the core web framework.
- SQLite for lightweight database storage of baseline results.
- HTML5, CSS and JavaScript along with third-party libraries like AdminLTE, Bootstrap, FontAwesome, etc., for the presentation layer.
- External system tools and scripts to perform remote or offline baseline checks.

## Diagram (Mermaid)

```mermaid
graph TD
    BROWSER["User's Browser"]:::browser

    subgraph "Presentation Layer"
        TEMPLATES["HTML Templates"]:::frontend
        STATIC["Static Assets"]:::frontend
    end

    subgraph "Application Layer"
        subgraph "Flask Backend"
            INIT["Init"]:::backend
            AUTH["Authentication Module"]:::backend
            MAIN["Main Module"]:::backend
        end
        CONF["Configuration Settings"]:::config
    end

    subgraph "Data Layer"
        DBSET["DB Setup Module"]:::db
        DB["SQLite Database"]:::db
    end

    subgraph "Baseline Check Modules"
        CLIN["Check_Lin"]:::logic
        CWIN["Check_Win"]:::logic
        LEXE["Lin_exec_check"]:::logic
        WEXE["win_exec_check"]:::logic
        SSHEXE["Ssh_Exec"]:::logic
        SMBEXE["Smb_Exec"]:::logic
    end

    subgraph "External Scripts/Tools"
        SCRIPT_NODE["Scripts Directory"]:::external
        TOOLS_NODE["Tools Directory"]:::external
    end

    %% Connections
    BROWSER -->|"request"| TEMPLATES
    BROWSER -->|"request"| STATIC

    TEMPLATES -->|"HTTP_Request"| INIT
    STATIC -->|"HTTP_Request"| INIT

    INIT -->|"DB_ops"| DBSET
    DBSET -->|"configures"| DB

    INIT -->|"invokes_checks"| CLIN
    INIT -->|"executes_scripts"| SCRIPT_NODE
    SCRIPT_NODE -->|"uploads_results"| INIT

    INIT -->|"uses_config"| CONF

    %% Styles
    classDef browser fill:#f0d5ff,stroke:#c36eff,stroke-width:2px;
    classDef frontend fill:#a3d5ff,stroke:#1c6ea4,stroke-width:2px;
    classDef backend fill:#d5ffb3,stroke:#5ab85a,stroke-width:2px;
    classDef config fill:#ffd5a3,stroke:#d08400,stroke-width:2px;
    classDef db fill:#ffe4a3,stroke:#d08400,stroke-width:2px;
    classDef logic fill:#ffb3b3,stroke:#d85a5a,stroke-width:2px;
    classDef external fill:#e5ccff,stroke:#a64ca6,stroke-width:2px;

    %% Click Events
    click TEMPLATES "https://github.com/lovechoudoufu/baselinecheck_cdf/tree/master/app/templates"
    click STATIC "https://github.com/lovechoudoufu/baselinecheck_cdf/tree/master/app/static"
    click INIT "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/app/__init__.py"
    click AUTH "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/app/auth/views.py"
    click MAIN "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/app/main/view.py"
    click DB "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/baseline.sqlite"
    click DBSET "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/app/dbset.py"
    click CLIN "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/models/Check_Lin.py"
    click CWIN "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/models/Check_Win.py"
    click LEXE "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/models/Lin_exec_check.py"
    click WEXE "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/models/win_exec_check.py"
    click SSHEXE "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/models/Ssh_Exec.py"
    click SMBEXE "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/models/Smb_Exec.py"
    click SCRIPT_NODE "https://github.com/lovechoudoufu/baselinecheck_cdf/tree/master/models/Script"
    click TOOLS_NODE "https://github.com/lovechoudoufu/baselinecheck_cdf/tree/master/models/Tools"
    click CONF "https://github.com/lovechoudoufu/baselinecheck_cdf/blob/master/conf/config.py"
```
