# aws-samples/service-screener-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/service-screener-v2
- Repository: https://github.com/aws-samples/service-screener-v2

## Overview

##### Project type and purpose
- This is a full-stack, CLI-driven AWS guidance tool (“Service Screener”) written in Python.
- It runs in AWS CloudShell (or any Linux shell), invokes AWS APIs (via boto3/drivers) to gather resource configurations, evaluates them against best-practice rules, then generates a static HTML/JS report (using AdminLTE assets and Jinja-like templates).
- It also includes auxiliary “use cases” (cross-account scaffolding, scheduled runs via CDK/Lambda, etc.) but its core is a single CLI application with pluggable service modules and a presentation layer.

a. CLI “screener” entrypoint
- main.py, CreateService.py, Screener.py
- utils/ArguParser.py, utils/Config.py
b. Core Engine
- services/Service.py (Service manager)
- Evaluator.py (applies rules)
- PageBuilder.py (ties findings to frameworks)
- Reporter.py (orchestrates writing API JSON & HTML)
c. Service Modules
- services/{s3,ec2,iam,…}/X.py + their drivers/…
- Each service module invokes AWS SDK via a common driver interface
d. Frameworks (HTML page assembly)
- frameworks/Framework.py + per-framework maps & PageBuilder
e. Presentation layer
- templates/*.template.html
- adminlte/aws/res (CSS/JS assets)
f. Output
- output.zip → unzipped to index.html + static assets + per-account JSON (api-raw.json, api-full.json)
g. Utilities
- utils/ExcelBuilder.py, utils/RuleReader.py, utils/Tools.py
h. Optional Use Cases (external deployments)
- Cross-account role CFN template (usecases/crossAccounts)
- Scheduler CDK stack + Lambdas + DynamoDB/S3 triggers (usecases/scheduler)

1) User invokes CLI (main.py) with region/service flags
2) CLI parses args → loads Config → instantiates Screener
3) Screener iterates requested services:
→ Service manager loads each services/{name}/X.py
→ Calls driver interfaces to perform AWS describe/get calls
→ Returns raw JSON findings
→ Evaluator filters/scores findings
4) Findings passed to PageBuilder & frameworks:
→ Framework loads map.json to structure pages
→ Templates (Jinja-style) + AdminLTE assets used to assemble HTML
5) Reporter writes:
- per-account JSON (api-raw.json, api-full.json)
- HTML files + static assets
- Zips into output.zip
6) User downloads report from CloudShell

Separately, the scheduler use case:
- CDK deploys Lambdas (configUpdater, envInserter, resultProcesser)
- CloudWatch Event Rule triggers configUpdater on schedule
- configUpdater writes to DynamoDB
- DDB Stream / S3 events invoke resultProcesser → pushes findings to S3 / triggers CLI

##### Architectural patterns & design principles
- Modular service plugins: each AWS service scanner lives in its own folder + driver abstraction
- Strict separation: Core engine (CLI + orchestration), Service modules (data gather), Evaluator (logic), Presentation (frameworks + templates)
- Template-based static site generation (AdminLTE) for the UI
- Use of AWS CloudShell for host environment, boto3 SDK for service calls

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Environment
    User["User"]:::external
    CloudShell["AWS CloudShell"]:::aws

    User -->|"runs CLI"| CloudShell

    %% CLI Entrypoint
    subgraph "CLI Entrypoint"
        direction TB
        Main["main.py"]:::python
        CreateService["CreateService.py"]:::python
        Screener["Screener.py"]:::python
        ArgParser["utils/ArguParser.py"]:::python
        Config["utils/Config.py"]:::python
    end

    CloudShell -->|invokes| Main
    Main -->|imports| ArgParser
    Main -->|loads| Config
    Main -->|calls| Screener
    Main -->|calls| CreateService

    %% Core Engine
    subgraph "Core Engine"
        direction TB
        ServiceMgr["services/Service.py"]:::python
        Evaluator["services/Evaluator.py"]:::python
        PageBuilderCore["services/PageBuilder.py"]:::python
        Reporter["services/Reporter.py"]:::python
    end

    Screener -->|manages| ServiceMgr
    ServiceMgr -->|passes raw JSON| Evaluator
    Evaluator -->|filtered findings| PageBuilderCore
    PageBuilderCore -->|to Reporter| Reporter

    %% Service Modules
    subgraph "Service Modules"
        direction TB
        S3Module["services/s3/S3.py"]:::python
        EC2Module["services/ec2/Ec2.py"]:::python
        IAMModule["services/iam/Iam.py"]:::python
        RDSModule["services/rds/Rds.py"]:::python
        subgraph "Drivers"
            direction TB
            S3Drivers["services/s3/drivers/..."]:::python
            EC2Drivers["services/ec2/drivers/..."]:::python
            IAMDrivers["services/iam/drivers/..."]:::python
            RDSDrivers["services/rds/drivers/..."]:::python
        end
    end

    ServiceMgr -->|"loads modules"| S3Module
    ServiceMgr --> EC2Module
    ServiceMgr --> IAMModule
    ServiceMgr --> RDSModule
    S3Module -->|uses| S3Drivers
    EC2Module --> EC2Drivers
    IAMModule --> IAMDrivers
    RDSModule --> RDSDrivers
    S3Drivers -->|AWS SDK via boto3| AWSAPI["AWS APIs"]:::aws
    EC2Drivers --> AWSAPI
    IAMDrivers --> AWSAPI
    RDSDrivers --> AWSAPI

    AWSAPI -->|returns JSON| ServiceMgr

    %% Frameworks
    subgraph "Frameworks"
        direction TB
        FrameworkMgr["frameworks/Framework.py"]:::python
        FWPageBuilder["frameworks/FrameworkPageBuilder.py"]:::python
        CIS["frameworks/CIS/CIS.py"]:::python
        CISBuilder["frameworks/CIS/CISPageBuilder.py"]:::python
        CISMap["frameworks/CIS/map.json"]:::asset
        NIST["frameworks/NIST/NIST.py"]:::python
        NISTBuilder["frameworks/NIST/NISTPageBuilder.py"]:::python
        NISTMap["frameworks/NIST/map.json"]:::asset
    end

    PageBuilderCore -->|uses| FrameworkMgr
    FrameworkMgr --> FWPageBuilder
    FWPageBuilder --> CIS
    FWPageBuilder --> NIST
    CIS --> CISBuilder
    CISBuilder --> CISMap
    NIST --> NISTBuilder
    NISTBuilder --> NISTMap

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Templates["templates/*.template.html"]:::asset
        AdminLTE["adminlte/aws/res"]:::asset
    end

    FWPageBuilder -->|renders| Templates
    Templates -->|includes assets| AdminLTE
    AdminLTE -->|CSS/JS/img| Reporter

    %% Reporter Output
    Reporter -->|writes| RawJSON["api-raw.json<br/>api-full.json"]:::output
    Reporter -->|writes| HTMLFiles["index.html + static assets"]:::output
    Reporter -->|zips| Zip["output.zip"]:::output
    Zip -->|download| User

    %% Use Case: Scheduler
    subgraph "Use Cases - Scheduler"
        direction TB
        CDKStack["service_screener_automation_stack.py"]:::python
        CloudWatch["CloudWatch Event Rule"]:::aws
        ConfigUpdater["configUpdater.py"]:::python
        EnvInserter["envInsert.py"]:::python
        ResultProcessor["resultProcesser.py"]:::python
        DynamoDB["DynamoDB"]:::aws
        S3Bucket["S3 Bucket"]:::aws
    end

    CDKStack --> CloudWatch
    CloudWatch -->|triggers| ConfigUpdater
    ConfigUpdater -->|writes to| DynamoDB
    DynamoDB -->|stream event| ResultProcessor
    ResultProcessor --> S3Bucket
    ResultProcessor -->|can trigger| Main

    %% Use Case: Cross-Account
    subgraph "Use Cases - Cross-Account"
        direction TB
        CFN["crossAccountRoleCF.yml"]:::asset
        IAMRoleFlow["STS Assume-Role Flow"]:::aws
    end

    CFN --> IAMRoleFlow
    IAMRoleFlow --> Main

    %% Click Events
    click Main "https://github.com/aws-samples/service-screener-v2/blob/main/main.py"
    click CreateService "https://github.com/aws-samples/service-screener-v2/blob/main/CreateService.py"
    click Screener "https://github.com/aws-samples/service-screener-v2/blob/main/Screener.py"
    click ArgParser "https://github.com/aws-samples/service-screener-v2/blob/main/utils/ArguParser.py"
    click Config "https://github.com/aws-samples/service-screener-v2/blob/main/utils/Config.py"
    click ServiceMgr "https://github.com/aws-samples/service-screener-v2/blob/main/services/Service.py"
    click Evaluator "https://github.com/aws-samples/service-screener-v2/blob/main/services/Evaluator.py"
    click PageBuilderCore "https://github.com/aws-samples/service-screener-v2/blob/main/services/PageBuilder.py"
    click Reporter "https://github.com/aws-samples/service-screener-v2/blob/main/services/Reporter.py"
    click S3Module "https://github.com/aws-samples/service-screener-v2/blob/main/services/s3/S3.py"
    click S3Drivers "https://github.com/aws-samples/service-screener-v2/blob/main/services/s3/drivers/S3Bucket.py"
    click EC2Module "https://github.com/aws-samples/service-screener-v2/blob/main/services/ec2/Ec2.py"
    click EC2Drivers "https://github.com/aws-samples/service-screener-v2/blob/main/services/ec2/drivers/Ec2Instance.py"
    click IAMModule "https://github.com/aws-samples/service-screener-v2/blob/main/services/iam/Iam.py"
    click IAMDrivers "https://github.com/aws-samples/service-screener-v2/blob/main/services/iam/drivers/IamUser.py"
    click RDSModule "https://github.com/aws-samples/service-screener-v2/blob/main/services/rds/Rds.py"
    click RDSDrivers "https://github.com/aws-samples/service-screener-v2/blob/main/services/rds/drivers/RdsCommon.py"
    click FrameworkMgr "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/Framework.py"
    click FWPageBuilder "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/FrameworkPageBuilder.py"
    click CIS "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/CIS/CIS.py"
    click CISBuilder "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/CIS/CISPageBuilder.py"
    click CISMap "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/CIS/map.json"
    click NIST "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/NIST/NIST.py"
    click NISTBuilder "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/NIST/NISTPageBuilder.py"
    click NISTMap "https://github.com/aws-samples/service-screener-v2/blob/main/frameworks/NIST/map.json"
    click Templates "https://github.com/aws-samples/service-screener-v2/blob/main/templates/breadcrumb.template.html"
    click AdminLTE "https://github.com/aws-samples/service-screener-v2/tree/main/adminlte/aws/res"
    click CDKStack "https://github.com/aws-samples/service-screener-v2/blob/main/usecases/scheduler/src/infra/service_screener_automation/service_screener_automation_stack.py"
    click ConfigUpdater "https://github.com/aws-samples/service-screener-v2/blob/main/usecases/scheduler/src/lambda/ssv2_configUpdater/configUpdater.py"
    click EnvInserter "https://github.com/aws-samples/service-screener-v2/blob/main/usecases/scheduler/src/lambda/ssv2_envInserter/envInsert.py"
    click ResultProcessor "https://github.com/aws-samples/service-screener-v2/blob/main/usecases/scheduler/src/lambda/ssv2_resultProcesser/resultProcesser.py"
    click CFN "https://github.com/aws-samples/service-screener-v2/blob/main/usecases/crossAccounts/crossAccountRoleCF.yml"

    %% Styles
    classDef python fill:#B3CDE3,stroke:#333,stroke-width:1px
    classDef aws fill:#FBB4AE,stroke:#333,stroke-width:1px
    classDef asset fill:#CCEBC5,stroke:#333,stroke-width:1px
    classDef output fill:#DECBE4,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
