# triska/simsttab architecture

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

- Interactive diagram: https://gitdiagram.com/triska/simsttab
- Repository: https://github.com/triska/simsttab

## Overview

##### Project type and purpose
- This is an open-source, command-line timetabling engine written in Prolog (a constraint-solver for school schedules).
- Its purpose is to read a requirement specification (reqs.pl), solve the scheduling problem via a Prolog engine, and emit a timetable (timetable.txt).

##### File structure
- Top‐level files:
- simsttab.pl : the main Prolog module/solver
- reqs.pl     : user‐provided constraints (rooms, timeslots, teachers, classes)
- timetable.txt: sample output
- README.md   : project description & usage
- No frontend/backend split – it’s a single‐process CLI tool.
- No build scripts or deployment artifacts beyond “run in Scryer-Prolog.”

##### README for additional insights
- Usage: “scryer-prolog simsttab.pl reqs.pl”
- Key operations:
a. Load library and problem definition (simsttab.pl + reqs.pl)
b. Generate Prolog variables, apply labeling([ff],Vs) – the finite‐domain search
c. Print results via print_classes/1

a. Main components:
1. CLI Interface / Invocation
2. Requirement Loader (reqs.pl parser)
3. Constraint Generator (requirements_variables/2)
4. Prolog Finite-Domain Solver (labeling/2 in the Scryer engine)
5. Output Formatter (print_classes/1)
6. External Runtime (Scryer-Prolog interpreter)
7. File System (input .pl files, output .txt)
b. Relationships & interactions:
- User → CLI
- CLI invokes Prolog interpreter, loads simsttab.pl & reqs.pl
- Requirement Loader → generates internal facts
- Constraint Generator → builds FD variables & constraints
- Prolog Solver → explores search space, finds a solution
- Output Formatter → writes timetable to stdout or timetable.txt
c. Architectural patterns / design principles:
- Modular decomposition: separation of “problem definition” (reqs.pl) from “solver logic” (simsttab.pl).
- Declarative pipeline: load facts → generate constraints → solve → print.
- Single‐process, data-flow architecture.
d. Key technologies / libraries:
- Scryer-Prolog engine (constraint‐solving runtime)
- Prolog FD library (labeling/2)
- Plain text input/output

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User(("User")):::external

    %% CLI Interface
    CLI["CLI Interface / Invocation"]:::code

    %% File System Artifacts
    simsttabFile[(simsttab.pl)]:::data
    reqsFile[(reqs.pl)]:::data
    README[(README.md)]:::data
    OutputFile[(timetable.txt)]:::data

    %% Runtime
    Runtime(["Scryer-Prolog Interpreter"]):::runtime

    %% Code Modules
    subgraph "Solver Logic"
        RL["Requirement Loader"]:::code
        CG["Constraint Generator"]:::code
        FS["Prolog FD Solver"]:::code
        OF["Output Formatter"]:::code
    end

    %% Flow
    User -->|"runs command"| CLI
    CLI -->|invokes| Runtime
    CLI -->|loads| simsttabFile
    CLI -->|loads| reqsFile
    CLI -->|shows docs| README

    Runtime -->|parses facts| RL
    RL -->|generates vars| CG
    CG -->|applies labeling| FS
    FS -->|solves constraints| OF
    OF -->|writes output| OutputFile

    %% Click events
    click CLI "https://github.com/triska/simsttab/blob/master/simsttab.pl"
    click RL "https://github.com/triska/simsttab/blob/master/reqs.pl"
    click CG "https://github.com/triska/simsttab/blob/master/simsttab.pl"
    click FS "https://github.com/triska/simsttab/blob/master/simsttab.pl"
    click OF "https://github.com/triska/simsttab/blob/master/simsttab.pl"
    click README "https://github.com/triska/simsttab/blob/master/README.md"
    click OutputFile "https://github.com/triska/simsttab/blob/master/timetable.txt"

    %% Styles
    classDef code fill:#cce5ff,stroke:#005cbf,color:#005cbf;
    classDef runtime fill:#d4edda,stroke:#155724,color:#155724;
    classDef data fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
