# cisagov/decider architecture

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

- Interactive diagram: https://gitdiagram.com/cisagov/decider
- Repository: https://github.com/cisagov/decider

## Overview

##### Main Components

- Web Server / Application Layer:
– Represent the core Python application. This is centered around the “app” directory, where you have configuration files (conf.py, constants.py, env_vars.py), route-handling modules (routes/*), and utility scripts.
– Include the “decider.py” entry-point and “decider.service” files, suggesting service management.
– Note that uWSGI configuration files (uwsgi.ini and docker-specific ones) indicate that the application is served via uWSGI.

- Frontend/UI:
– Identify the static assets stored in “app/static” (CSS, JavaScript, fonts) and HTML templates under “app/templates”. These work together to deliver the responsive, login-less user interface that shows the Question Tree, Search, and other pages.
– Inclusion of third-party libraries (Bootstrap, AlpineJS, jQuery, etc.) is crucial to the frontend’s function.

- Database Layer:
– The project’s “app/utils/db” folder contains subdirectories (actions, create, destroy, read, dumps) which indicate custom scripts to manage and interact with the database (e.g., adding versions, dumping data or tables).
– Docker environment and environment variables (e.g., DB_ADMIN_PASS, DB_KIOSK_PASS) as specified in the README confirm the importance of this layer.

- Configuration & Deployment:
– The presence of multiple environment files (.env.docker, .env.manual) shows that configuration is carefully managed.
– The “config” and “default_config” directories house default parameters, build sources (which include JSON files for ATT&CK content), and certificates.
– Docker Compose files (docker-compose.yaml) and the Docker directory (docker/web with its Dockerfile and entrypoint scripts) indicate deployment via containers.
– CI/CD workflows (inside .github/workflows) suggest automated testing/security checks.

##### Relationships and Interactions between Components

- The User interacts with the Frontend (browsers load HTML from the “app/templates” and assets from “app/static”).
- The Frontend communicates with the Python Web Server via HTTP routes defined under “app/routes”. These routes serve pages (e.g., admin, auth, search) and possibly API endpoints.
- The Web Server, upon receiving requests, interacts with the Database using the utility scripts (in app/utils/db) for actions like reading, creating, updating, or dumping data.
- Configuration and Environment Variables are injected into the app at startup (via .env files and Docker Compose settings).
- The entire setup is deployed within Docker containers orchestrated by Docker Compose, making sure that changes to the configuration trigger container rebuilds.

##### Architectural Patterns and Technologies

- MVC / Route-based Pattern: The division between “routes” (controllers/views) and “templates” (views) clearly outlines an MVC-like separation.
- Containerization: With Docker and Docker Compose, the application is designed for containerized environments.
- Modular Database Management: The use of separate scripts for creation, reading, destruction, and dumping tables indicates a modular approach to database management.
- Config & Environment Separation: Utilizing multiple configuration files and environment variables ensures that code remains environment-agnostic.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    A["User"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        B1["HTML Templates (app/templates)"]:::frontend
        B2["Static Assets (CSS, JS, Fonts) (app/static)"]:::frontend
    end

    %% Backend/Application Layer
    subgraph "Backend/Application Layer"
        C1["Service Entrypoint (decider.py)"]:::backend
        C2["Route Handlers (app/routes)"]:::backend
        C3["Core Config Files (conf.py, constants.py, env_vars.py)"]:::backend
        C4["uWSGI Configuration (uwsgi.ini)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        D1["Database Management (app/utils/db)"]:::database
    end

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        E1["Environment Config (.env.docker, .env.manual)"]:::config
        E2["Additional Config & Certificates (config, default_config)"]:::config
        E3["Docker & CI/CD (docker/web, .github/workflows)"]:::config
    end

    %% Relationships
    A -->|"HTTPRequest"| B1
    A -->|"HTTPRequest"| B2

    B1 -->|"Serves Content"| C2
    B2 -->|"Serves Assets"| C2

    C2 -->|"CRUD Operations"| D1

    E1 -->|"Injects"| C3
    E2 -->|"Provides External Data"| C3
    E3 -->|"Orchestrates"| C1
    E3 -->|"Orchestrates"| D1

    %% Click Events for Web Server / Application Layer
    click C3 "https://github.com/cisagov/decider/blob/develop/app/conf.py"
    click C3 "https://github.com/cisagov/decider/blob/develop/app/constants.py"
    click C3 "https://github.com/cisagov/decider/blob/develop/app/env_vars.py"
    click C1 "https://github.com/cisagov/decider/blob/develop/decider.py"
    click C1 "https://github.com/cisagov/decider/blob/develop/decider.service"
    click C2 "https://github.com/cisagov/decider/tree/develop/app/routes"
    click C4 "https://github.com/cisagov/decider/blob/develop/uwsgi.ini"
    click C4 "https://github.com/cisagov/decider/blob/develop/docker/web/root_files/uwsgi-http-kiosk.ini"
    click C4 "https://github.com/cisagov/decider/blob/develop/docker/web/root_files/uwsgi-https-kiosk.ini"

    %% Click Events for Frontend/UI
    click B2 "https://github.com/cisagov/decider/tree/develop/app/static"
    click B1 "https://github.com/cisagov/decider/tree/develop/app/templates"

    %% Click Events for Database Layer
    click D1 "https://github.com/cisagov/decider/tree/develop/app/utils/db"
    click D1 "https://github.com/cisagov/decider/blob/develop/app/utils/db/source_loader.py"
    click D1 "https://github.com/cisagov/decider/blob/develop/app/utils/db/util.py"

    %% Click Events for Configuration & Deployment
    click E1 "https://github.com/cisagov/decider/blob/develop/.env.docker"
    click E1 "https://github.com/cisagov/decider/blob/develop/.env.manual"
    click E2 "https://github.com/cisagov/decider/tree/develop/config"
    click E2 "https://github.com/cisagov/decider/tree/develop/default_config"
    click E2 "https://github.com/cisagov/decider/tree/develop/default_config/build_sources"
    click E2 "https://github.com/cisagov/decider/tree/develop/default_config/certs"
    click E3 "https://github.com/cisagov/decider/tree/develop/docker/web"
    click E3 "https://github.com/cisagov/decider/tree/develop/.github/workflows"

    %% Style Definitions
    classDef user fill:#D5F5E3,stroke:#196F3D,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#ABEBC6,stroke:#145A32,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef config fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
