# sleepydogx/thechecklist-public architecture

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

- Interactive diagram: https://gitdiagram.com/sleepydogx/thechecklist-public
- Repository: https://github.com/sleepydogx/thechecklist-public

## Overview

1. **Overall shape**
   - This is a **single-page web app** backed by a **Node.js/Express API** and **PostgreSQL**.
   - The browser hosts the entire UI from `frontend/index.html`; the backend exposes all application logic over HTTP.

2. **Primary runtime boundary**
   - The **frontend** is a thin client for interacting with the playbook, managing engagement state, and rendering reports.
   - The **backend** is the authoritative layer for authentication, persistence, file uploads, exports, AI calls, and notebook/notion integrations.

3. **Core backend structure**
   - `backend/server.js` is the entrypoint.
   - `backend/db.js` centralizes database access.
   - `backend/middleware/auth.js` enforces JWT-based authentication across protected routes.
   - The backend is split into route modules by domain rather than by UI page.

4. **Data model and persistence**
   - PostgreSQL is the main system of record.
   - Schema changes are managed through SQL migrations in `backend/migrations/` and applied on startup via `run.js`.
   - The database stores users, clients, engagements, target profiles, playbooks/templates, findings, images, and saved state.

5. **Domain subsystems**
   - `routes/auth.js` handles login/registration and first-user admin bootstrap.
   - `routes/clients.js`, `routes/engagements.js`, and `routes/profiles.js` model the pentest workflow hierarchy: **client → engagement → target profile**.
   - `routes/state.js` likely stores the live playbook/session state: variables, progress, notes, and findings.
   - `routes/templates.js` and `routes/seed.js` support built-in playbook templates and initial template seeding.

6. **Playbook execution layer**
   - The app centers on a structured AD internal pentest playbook with phases and steps.
   - Variable replacement happens across commands and notes using engagement/profile data.
   - The playbook can be edited as a canvas-style structure and persisted as templates or engagement-specific instances.

7. **Findings and evidence**
   - Findings are first-class data, including severity, summaries, subsection association, and screenshots.
   - `routes/uploads.js` handles image/evidence uploads, and the README indicates filenames are randomized with ownership checks.
   - This creates a clear separation between narrative playbook content and evidence artifacts.

8. **AI and analysis integration**
   - `routes/ai.js` connects the app to optional AI providers such as **OpenRouter** or **Ollama**.
   - AI is used for per-section analysis of command output, extracting findings, suggesting variables, and recommending next steps.
   - This is an external-call boundary: the backend mediates all AI traffic rather than the browser calling providers directly.

9. **Notebook and documentation exports**
   - `routes/jupyter.js` supports importing/exporting playbooks as **Jupyter notebooks**.
   - `routes/notion.js` integrates with **Notion** for publishing or exporting content there.
   - These routes act as transformation/export adapters around the same underlying playbook data.

10. **Security and access control**
   - All sensitive API access is JWT-protected.
   - Ownership and isolation are enforced server-side and at the database/query layer.
   - The app is designed so each authenticated user can manage multiple clients and engagements without cross-tenant leakage.

11. **Deployment topology**
   - `docker-compose.yml` and `Dockerfile` indicate a containerized deployment with the app and database.
   - The README describes a simple startup path: configure `.env`, start with Docker Compose, then open the app in a browser.
   - This makes the system deployable as a self-contained internal tool.

12. **How data flows through the system**
   - User action in the browser → Express route → PostgreSQL read/write → updated UI state.
   - Evidence uploads follow the same path but add file storage handling.
   - AI analysis and external exports introduce outbound integrations, but the backend remains the single integration gateway.

Main entry points: [`backend/server.js`](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/server.js) (API server), [`backend/db.js`](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/db.js) (DB access), [`backend/routes/ai.js`](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/ai.js) (AI analysis), [`backend/routes/state.js`](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/state.js) (Playbook state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_frontend["Frontend"]
  node_n_frontend_app["SPA UI<br/>single-page app<br/>[index.html]"]
end

subgraph group_grp_backend["Backend API"]
  node_n_server["API server<br/>express entrypoint<br/>[server.js]"]
  node_n_auth_mw{{"Auth middleware<br/>jwt guard<br/>[auth.js]"}}
  node_n_db[("DB access<br/>postgres client<br/>[db.js]")]
  node_n_route_auth["Auth routes<br/>login bootstrap<br/>[auth.js]"]
  node_n_route_clients["Clients<br/>tenant route<br/>[clients.js]"]
  node_n_route_engagements["Engagements<br/>workflow route<br/>[engagements.js]"]
  node_n_route_profiles["Profiles<br/>target route<br/>[profiles.js]"]
  node_n_route_state["Playbook state<br/>session state<br/>[state.js]"]
  node_n_route_templates["Templates<br/>[templates.js]"]
  node_n_route_seed["Seed data<br/>bootstrap data<br/>[seed.js]"]
  node_n_route_uploads["Uploads<br/>evidence files<br/>[uploads.js]"]
end

subgraph group_grp_data["Persistence"]
  node_n_migrate_run["Migration runner<br/>startup migrator<br/>[run.js]"]
  node_n_schema_migrations["SQL migrations<br/>versioned schema<br/>[001_initial.sql]"]
  node_n_schema_core[("Core schema<br/>postgres schema<br/>[001_initial.sql]")]
end

subgraph group_grp_external["External Integrations"]
  node_n_route_ai{{"AI analysis<br/>llm adapter<br/>[ai.js]"}}
  node_n_route_jupyter["Jupyter<br/>notebook adapter<br/>[jupyter.js]"]
  node_n_route_notion["Notion<br/>publishing adapter<br/>[notion.js]"]
end

node_n_frontend_app -->|"HTTP API"| node_n_server
node_n_server -->|"protects"| node_n_auth_mw
node_n_server -->|"routes"| node_n_route_auth
node_n_server -->|"routes"| node_n_route_clients
node_n_server -->|"routes"| node_n_route_engagements
node_n_server -->|"routes"| node_n_route_profiles
node_n_server -->|"routes"| node_n_route_state
node_n_server -->|"routes"| node_n_route_templates
node_n_server -->|"routes"| node_n_route_seed
node_n_server -->|"routes"| node_n_route_uploads
node_n_server -->|"routes"| node_n_route_ai
node_n_server -->|"routes"| node_n_route_jupyter
node_n_server -->|"routes"| node_n_route_notion
node_n_route_auth -->|"reads/writes"| node_n_db
node_n_route_clients -->|"reads/writes"| node_n_db
node_n_route_engagements -->|"reads/writes"| node_n_db
node_n_route_profiles -->|"reads/writes"| node_n_db
node_n_route_state -->|"reads/writes"| node_n_db
node_n_route_templates -->|"reads/writes"| node_n_db
node_n_route_seed -->|"initializes"| node_n_db
node_n_route_uploads -->|"records"| node_n_db
node_n_route_ai -->|"uses context"| node_n_route_state
node_n_route_ai -->|"reads/writes"| node_n_db
node_n_route_jupyter -->|"transforms"| node_n_db
node_n_route_notion -->|"transforms"| node_n_db
node_n_migrate_run -->|"applies"| node_n_schema_migrations
node_n_schema_migrations -->|"defines"| node_n_schema_core
node_n_migrate_run -->|"prepares"| node_n_db
node_n_db -->|"operates on"| node_n_schema_core

click node_n_frontend_app "https://github.com/sleepydogx/thechecklist-public/blob/main/frontend/index.html"
click node_n_server "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/server.js"
click node_n_auth_mw "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/middleware/auth.js"
click node_n_db "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/db.js"
click node_n_route_auth "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/auth.js"
click node_n_route_clients "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/clients.js"
click node_n_route_engagements "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/engagements.js"
click node_n_route_profiles "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/profiles.js"
click node_n_route_state "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/state.js"
click node_n_route_templates "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/templates.js"
click node_n_route_seed "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/seed.js"
click node_n_route_uploads "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/uploads.js"
click node_n_route_ai "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/ai.js"
click node_n_route_jupyter "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/jupyter.js"
click node_n_route_notion "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/notion.js"
click node_n_migrate_run "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/migrations/run.js"
click node_n_schema_migrations "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/migrations/001_initial.sql"
click node_n_schema_core "https://github.com/sleepydogx/thechecklist-public/blob/main/backend/migrations/001_initial.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_frontend_app toneBlue
class node_n_server,node_n_auth_mw,node_n_db,node_n_route_auth,node_n_route_clients,node_n_route_engagements,node_n_route_profiles,node_n_route_state,node_n_route_templates,node_n_route_seed,node_n_route_uploads toneAmber
class node_n_migrate_run,node_n_schema_migrations,node_n_schema_core toneMint
class node_n_route_ai,node_n_route_jupyter,node_n_route_notion toneRose
```

## Components

### Frontend

Browser-hosted single-page UI.

- [SPA UI](https://github.com/sleepydogx/thechecklist-public/blob/main/frontend/index.html): single-page app · Browser entrypoint that hosts the entire client interface. · `frontend/index.html`

### Backend API

Express server, route modules, middleware, and shared DB access.

- [API server](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/server.js): express entrypoint · Bootstraps the HTTP server and wires backend routes. · `backend/server.js`
- [Auth middleware](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/middleware/auth.js): jwt guard · Protects authenticated routes and enforces request-level access control. · `backend/middleware/auth.js`
- [DB access](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/db.js): postgres client · Central database access layer used by backend routes. · `backend/db.js`
- [Auth routes](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/auth.js): login bootstrap · Handles registration, login, and first-user admin setup. · `backend/routes/auth.js`
- [Clients](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/clients.js): tenant route · Manages client records in the engagement hierarchy. · `backend/routes/clients.js`
- [Engagements](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/engagements.js): workflow route · Manages engagements under each client. · `backend/routes/engagements.js`
- [Profiles](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/profiles.js): target route · Manages target profiles and playbook context for an engagement. · `backend/routes/profiles.js`
- [Playbook state](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/state.js): session state · Stores live playbook variables, progress, notes, and findings state. · `backend/routes/state.js`
- [Templates](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/templates.js): playbook templates · Serves built-in templates and template CRUD for playbooks. · `backend/routes/templates.js`
- [Seed data](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/seed.js): bootstrap data · Loads initial built-in playbook content into the system. · `backend/routes/seed.js`
- [Uploads](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/uploads.js): evidence files · Handles image and evidence uploads with ownership checks. · `backend/routes/uploads.js`

### Persistence

PostgreSQL schema lifecycle and migration startup.

- [Migration runner](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/migrations/run.js): startup migrator · Applies database migrations during startup. · `backend/migrations/run.js`
- [SQL migrations](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/migrations/001_initial.sql): versioned schema · Versioned SQL files that define and extend the PostgreSQL schema. · `backend/migrations/001_initial.sql`
- [Core schema](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/migrations/001_initial.sql): postgres schema · Primary records for users, clients, engagements, profiles, templates, findings, images, and saved state. · `backend/migrations/001_initial.sql`

### External Integrations

Outbound adapters for AI, notebooks, and publishing.

- [AI analysis](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/ai.js): llm adapter · Mediates outbound AI requests for analysis, extraction, and recommendations. · `backend/routes/ai.js`
- [Jupyter](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/jupyter.js): notebook adapter · Imports and exports playbooks as Jupyter notebooks. · `backend/routes/jupyter.js`
- [Notion](https://github.com/sleepydogx/thechecklist-public/blob/main/backend/routes/notion.js): publishing adapter · Exports or publishes playbook content to Notion. · `backend/routes/notion.js`

## Connections

- SPA UI → API server: HTTP API · The SPA talks to the backend for all application logic.
- API server → Auth middleware: protects · Server wires authentication into protected routes.
- API server → Auth routes: routes · Exposes login and registration endpoints.
- API server → Clients: routes · Exposes client management endpoints.
- API server → Engagements: routes · Exposes engagement management endpoints.
- API server → Profiles: routes · Exposes target profile endpoints.
- API server → Playbook state: routes · Exposes live playbook state endpoints.
- API server → Templates: routes · Exposes playbook template endpoints.
- API server → Seed data: routes · Exposes bootstrap seeding endpoints.
- API server → Uploads: routes · Exposes evidence upload endpoints.
- API server → AI analysis: routes · Exposes analysis endpoints that proxy AI providers.
- API server → Jupyter: routes · Exposes notebook import/export endpoints.
- API server → Notion: routes · Exposes Notion export/publish endpoints.
- Auth routes → DB access: reads/writes · Authentication data is persisted through the shared DB layer.
- Clients → DB access: reads/writes · Client records are stored in PostgreSQL.
- Engagements → DB access: reads/writes · Engagement records are stored in PostgreSQL.
- Profiles → DB access: reads/writes · Profile records and playbook context are stored in PostgreSQL.
- Playbook state → DB access: reads/writes · Live playbook state is persisted in PostgreSQL.
- Templates → DB access: reads/writes · Template data is persisted in PostgreSQL.
- Seed data → DB access: initializes · Seeds built-in content through the database layer.
- Uploads → DB access: records · Upload metadata and ownership data are stored in PostgreSQL.
- AI analysis → Playbook state: uses context · AI analysis consumes playbook state, variables, and findings.
- AI analysis → DB access: reads/writes · AI-assisted results are persisted through the DB layer.
- Jupyter → DB access: transforms · Notebook import/export operates on stored playbook data.
- Notion → DB access: transforms · Notion publishing/export operates on stored playbook data.
- Migration runner → SQL migrations: applies · Startup runner executes versioned SQL migrations.
- SQL migrations → Core schema: defines · Migrations establish and extend the PostgreSQL schema.
- Migration runner → DB access: prepares · Database access depends on the schema being migrated first.
- DB access → Core schema: operates on · Shared DB access reads and writes the core schema.
