# nistont/schedule-generator architecture

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

- Interactive diagram: https://gitdiagram.com/nistont/schedule-generator
- Repository: https://github.com/nistont/schedule-generator

## Overview

##### Project Overview
- Project Type: This is a full-stack scheduling application, built with a Next.js (React) client and a NestJS server.
- Purpose: The application is designed to generate and manage various types of schedules (for cabinets, groups, teachers, etc.), featuring user authorization (with Telegram and email integrations), AI-powered generation enhancements, and local as well as server-side schedule saving. The README even highlights future features like notifications, multi-language support, and an admin panel.

##### Analyzing the File Structure
- Client (Frontend):
- The “client” folder is organized around Next.js’s file-based routing. There are clear directories for “app” pages (like authorization, documentation, profile, setting, and registration), and many reusable UI components (buttons, fields, select inputs, etc.).
- The structure is well modularized: each feature (e.g., “authorization”, “profile”) has its own folder housing pages, providers, and sometimes custom layouts.
- There are dedicated areas for API calls (client/src/api), service calls, constants, hooks, and even state management using jotai.
- Assets such as images and fonts are organized under public and fonts directories.

- Server (Backend):
- The “server” folder shows a NestJS backend structure using modules for authentication (auth), schedule management, and user management.
- It uses Prisma for database interaction (prisma/schema.prisma), and follows common NestJS patterns – controllers, services, DTOs, guards, decorators, and strategies (like JWT for authorization).
- Configuration files (e.g., nest-cli.json, tsconfig, eslint, prettier) indicate a well-structured modern Node.js backend.

a. Main Components to Include:
- Frontend Client: Next.js application with pages, API service modules, state management (jotai), and UI components.
- Backend Server: NestJS application exposing RESTful endpoints organized in modules (auth, schedule, user). Show key services like authentication, schedule generation, and management.
- Database: Represented by Prisma integrations. This will show a connection between the server and the underlying relational database.
- External Services:
– Integration with Telegram (for two-factor authentication and notifications).
– Email systems (like Yandex Mail) for notifications and API key updates.
– AI External API for enhanced schedule generation.
- Local Storage (Optional): The client may use localStorage for schedule persistence, as suggested in the README.

b. Relationships and Interactions:
- Server-to-Database: Represent the backend’s service modules communicating with the database via Prisma.
- Server-to-External Services: Highlight how the server reaches out to Telegram, Email, and AI APIs for notifications, authentication, or schedule generation support.
- Internal Client Interactions: Map out how components (like UI forms, navigation, headers, and various view providers) work together on the frontend.

c. Architectural Patterns and Design Principles:
- Separation of Concerns: Frontend (view, state management, API calls) separated from backend (business logic, database access, external integrations).
- Modular Architecture: Both client and server structures are modular – each domain (auth, profile, schedule) is encapsulated in its own sub-system.
- API-First and Service-Oriented Design: The server serves as an API layer for client interactions, following RESTful principles supported by detailed DTOs and guards.
- Use of External Integrations: Clearly mark integrations (Telegram, Email, and AI APIs) as separate external components that communicate with the backend.

d. Key Technologies/Frameworks:
- Frontend: Next.js (React framework), Tailwind CSS, and state management with jotai.
- Backend: NestJS, Prisma (for ORM), JWT based authentication.
- Development Tools: ESLint, Prettier, and configuration files for consistent coding standards.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend (Next.js Client)
    subgraph "Frontend (Next.js Client)"
        nodeClient["Next.js Client"]:::frontend
        subgraph "Pages"
            nodeAuth["Authorization Page"]:::frontend
            nodeDoc["Documentation Page"]:::frontend
            nodeProfile["Profile Page"]:::frontend
            nodeProfileMain["Profile Main Component"]:::frontend
            nodeSetting["Setting Page"]:::frontend
            nodeRegistration["Registration Page"]:::frontend
        end
        subgraph "Components & Services"
            nodeUI["Reusable UI Components"]:::frontend
            nodeAPI["Client API Services"]:::frontend
            nodeState["State Management (jotai)"]:::frontend
            nodeHooks["Client Hooks"]:::frontend
            nodeService["Frontend Service Layer"]:::frontend
        end
        nodeLocal["Local Storage (Browser)"]:::frontend
    end

    %% Backend (NestJS Server)
    subgraph "Backend (NestJS Server)"
        nodeMain["Main Module"]:::backend
        subgraph "Modules"
            nodeAuthModule["Authentication Module"]:::backend
            nodeScheduleModule["Schedule Management Module"]:::backend
            nodeUserModule["User Management Module"]:::backend
        end
    end

    %% Database Integration
    nodeDB["Prisma Database"]:::database

    %% External Services
    subgraph "External Services"
        nodeTelegram["Telegram Integration"]:::external
        nodeEmail["Email Integration"]:::external
        nodeAI["AI API"]:::external
    end

    %% Interactions
    nodeClient -->|"API_Call"| nodeMain

    %% Frontend uses internal components
    nodeClient -->|"uses"| nodeAPI
    nodeClient -->|"uses"| nodeState
    nodeClient -->|"uses"| nodeHooks
    nodeClient -->|"uses"| nodeService
    nodeClient -->|"uses"| nodeUI
    nodeClient -->|"navigates_to"| nodeAuth
    nodeClient -->|"navigates_to"| nodeDoc
    nodeClient -->|"navigates_to"| nodeProfile
    nodeClient -->|"navigates_to"| nodeProfileMain
    nodeClient -->|"navigates_to"| nodeSetting
    nodeClient -->|"navigates_to"| nodeRegistration
    nodeLocal -.->|"persists"| nodeClient

    %% Backend module interactions with Database
    nodeAuthModule -->|"queries"| nodeDB
    nodeScheduleModule -->|"queries"| nodeDB
    nodeUserModule -->|"queries"| nodeDB

    %% Backend module integrations with External Services
    nodeAuthModule -->|"integrates"| nodeTelegram
    nodeAuthModule -->|"integrates"| nodeEmail
    nodeScheduleModule -->|"integrates"| nodeAI

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20,stroke-width:2px;
    classDef external fill:#FFE0B2,stroke:#E65100,color:#E65100,stroke-width:2px;
    classDef database fill:#FFCCBC,stroke:#BF360C,color:#BF360C,stroke-width:2px;

    %% Click Events for Frontend
    click nodeClient "https://github.com/nistont/schedule-generator/tree/main/client/"
    click nodeAuth "https://github.com/nistont/schedule-generator/tree/main/client/src/app/authorization"
    click nodeDoc "https://github.com/nistont/schedule-generator/tree/main/client/src/app/documentation"
    click nodeProfile "https://github.com/nistont/schedule-generator/tree/main/client/src/app/i/profile"
    click nodeProfileMain "https://github.com/nistont/schedule-generator/tree/main/client/src/components/ProfileMain"
    click nodeSetting "https://github.com/nistont/schedule-generator/tree/main/client/src/app/i/setting"
    click nodeRegistration "https://github.com/nistont/schedule-generator/tree/main/client/src/app/registration"
    click nodeUI "https://github.com/nistont/schedule-generator/tree/main/client/src/components/ui"
    click nodeAPI "https://github.com/nistont/schedule-generator/tree/main/client/src/api"
    click nodeState "https://github.com/nistont/schedule-generator/tree/main/client/src/jotai"
    click nodeHooks "https://github.com/nistont/schedule-generator/tree/main/client/src/hook"
    click nodeService "https://github.com/nistont/schedule-generator/tree/main/client/src/services"

    %% Click Events for Backend and Database
    click nodeMain "https://github.com/nistont/schedule-generator/blob/main/server/src/app.module.ts"
    click nodeAuthModule "https://github.com/nistont/schedule-generator/tree/main/server/src/auth"
    click nodeScheduleModule "https://github.com/nistont/schedule-generator/tree/main/server/src/schedule"
    click nodeUserModule "https://github.com/nistont/schedule-generator/tree/main/server/src/user"
    click nodeDB "https://github.com/nistont/schedule-generator/blob/main/server/prisma/schema.prisma"
```
