# vladimirvereshchagin/scheduler architecture

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

- Interactive diagram: https://gitdiagram.com/vladimirvereshchagin/scheduler
- Repository: https://github.com/vladimirvereshchagin/scheduler

## Overview

##### Main Components
- Frontend: The user-facing part of the application (found in the “web” directory with HTML, CSS, and JavaScript files). This is the web interface where users interact with the system.
- Backend/API: The core of the application built in Go. The entry point is in “cmd/main.go”, and it handles HTTP requests, routing (via internal/app/routes.go), and middleware setup.
- Authentication Module: Implemented in “internal/auth/jwt.go”, providing JWT token creation and validation to secure API endpoints.
- Business Logic & Services: Found in “internal/services” (such as task_service.go) that encapsulate the application’s core logic for managing tasks.
- Data Access Layer: Consists of “internal/models” (e.g., task.go) for data modeling and “internal/repository” (repository.go) for SQLite database interactions.
- Configuration: Managed via “internal/config/config.go” for reading environment variables and loading configuration settings.
- Time Utilities: In “internal/timeutils/date.go”, which provides helper functions likely used by services or scheduling logic.
- Database: SQLite is managed within “data” (for the persistent file, e.g., scheduler.db) and is auto-created at launch if not present.
- Testing Components: The “tests” directory contains the integration and unit tests, with a dedicated test configuration in “tests/settings.go” and a helper script “run-tests.sh”.

##### Interactions
- The Frontend (web interface) sends HTTP requests (possibly via AJAX or form submissions) to the RESTful backend.
- The Backend (HTTP server initialized in cmd/main.go) routes requests via defined routes (inside internal/app/routes.go) to various handlers in internal/app/handlers.go.
- Authentication: Requests pass through middleware (set up in internal/app/middleware) that checks for valid JWT tokens (as implemented in internal/auth).
- Once authenticated, requests are processed by the backend which calls into business logic (internal/services) that in turn relies on data models (internal/models) and interacts with the SQLite database via the repository layer (internal/repository).
- Utility functions like date formatting (in internal/timeutils) are used by services when scheduling or managing task dates.
- Additionally, configuration settings loaded by internal/config ensure environment variables (such as port, database file path, and JWT password) are correctly applied.
- Docker and CI/CD: Dockerfile, docker-compose.yml, and GitHub Actions workflows indicate containerized deployment and automated testing/builds, which should be depicted as part of the deployment pipeline.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly separates the presentation layer (frontend in “web”), the business logic layer (internal/services), and the data access layer (internal/models and internal/repository).
- RESTful API Design: Clear API endpoints are defined to handle CRUD operations for tasks.
- Middleware for Authentication: JWT-based authentication is centrally managed using middleware, promoting modular security.
- Containerization: With Docker support, the design emphasizes portability and scalability.
- Automated Testing & CI/CD: Robust testing support (with a dedicated tests folder and GitHub workflows) is key to reliability.

##### Relevant Technologies
- Go (primary language, with Go modules for dependency management)
- SQLite (database via the modernc.org/sqlite driver)
- Docker (for containerization and deployment)
- GitHub Actions and Pre-commit Hooks (for CI/CD and code quality)
- JWT for Authentication

##### Final Recommendations
- Do not hesitate to break the system into as many components as the application’s structure allows; the more granular the depiction, the easier it will be to understand the architecture.
- Every component is annotated with clear labels, and include reference to the relevant directories (e.g., “internal/app – Routes and Handlers”, “internal/auth – JWT handling”, “internal/services – Business Logic”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Browser/Client"]:::frontend
    WebInterface["Web Interface (Static Assets)"]:::frontend

    %% Backend Layer
    BackendEntry["API Server (cmd/main.go)"]:::backend
    APIRoutes["API Routes (internal/app/routes.go)"]:::backend
    APIHandlers["API Handlers (internal/app/handlers.go)"]:::backend
    JWTAuth["JWT Auth Module (internal/auth/jwt.go)"]:::auth
    TaskService["Task Service (internal/services/task_service.go)"]:::services

    %% Data Access Layer
    Repository["Repository (internal/repository/repository.go)"]:::data
    DataModels["Data Models (internal/models/task.go)"]:::data
    Database["SQLite Database"]:::data

    %% Support Components
    Config["Configuration (internal/config/config.go)"]:::config
    TimeUtils["Time Utilities (internal/timeutils/date.go)"]:::config

    %% CI/CD and Testing
    CICD["CI/CD & Containerization (Dockerfile, docker-compose, workflows)"]:::cicd
    Tests["Testing Components (tests)"]:::testing

    %% Relationships
    Browser -->|"HTTP Request"| WebInterface
    WebInterface -->|"REST API Call"| BackendEntry
    BackendEntry -->|"Load Routes"| APIRoutes
    BackendEntry -->|"Load Handlers"| APIHandlers
    APIRoutes -->|"JWT Check"| JWTAuth
    APIRoutes -->|"Delegate to Service"| TaskService
    APIHandlers -->|"Process Request"| TaskService
    TaskService -->|"DB Operations"| Repository
    Repository -->|"Uses Models"| DataModels
    Repository -->|"Read/Write"| Database
    Config -->|"Provides Settings"| BackendEntry
    Config -->|"Configures"| TaskService
    TimeUtils -->|"Date Utilities"| TaskService
    CICD -->|"Deploys"| BackendEntry
    CICD -->|"Triggers Tests"| Tests

    %% Legend Subgraph
    subgraph "Legend"
        L1["Browser/Client"]:::frontend
        L2["Web Interface"]:::frontend
        L3["API Server"]:::backend
        L4["Routes & Handlers"]:::backend
        L5["JWT Auth"]:::auth
        L6["Task Service"]:::services
        L7["Repository & Models"]:::data
        L8["SQLite DB"]:::data
        L9["Configuration & Utilities"]:::config
        L10["CI/CD & Testing"]:::cicd
    end

    %% Click Events
    click WebInterface "https://github.com/vladimirvereshchagin/scheduler/tree/main/web/"
    click BackendEntry "https://github.com/vladimirvereshchagin/scheduler/blob/main/cmd/main.go"
    click APIRoutes "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/app/routes.go"
    click APIHandlers "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/app/handlers.go"
    click JWTAuth "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/auth/jwt.go"
    click TaskService "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/services/task_service.go"
    click DataModels "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/models/task.go"
    click Repository "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/repository/repository.go"
    click Config "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/config/config.go"
    click TimeUtils "https://github.com/vladimirvereshchagin/scheduler/blob/main/internal/timeutils/date.go"
    click Database "https://github.com/vladimirvereshchagin/scheduler/tree/main/data/"
    click CICD "https://github.com/vladimirvereshchagin/scheduler/tree/main/Dockerfile"
    click Tests "https://github.com/vladimirvereshchagin/scheduler/tree/main/tests/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef auth fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef services fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef data fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef cicd fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef testing fill:#87CEFA,stroke:#000,stroke-width:2px;
```
