# namjsdev/computer_room_schedule architecture

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

- Interactive diagram: https://gitdiagram.com/namjsdev/computer_room_schedule
- Repository: https://github.com/namjsdev/computer_room_schedule

## Overview

##### Project Type and Purpose
- This is a full-stack web application built on Laravel. Its primary focus appears to be managing and displaying timetables (likely for a university, hinted by “vnua”) with functionalities that include user authentication, calendar scheduling, notifications, and even schedule scraping (as indicated by the ScrapeSchedule console command and CrawlerController).
- The system likely supports both a user-facing web interface (frontend) and backend management features (APIs, background commands, and administrative pages).

##### Analyzing the File Structure
- Core Laravel Structure: The “app”, “routes”, “config”, “database”, and “resources” directories indicate adherence to Laravel’s MVC pattern.
- The “app/Http/Controllers” directory groups controllers (like AccountController, AuthController, CalendarController, CrawlerController, etc.) that deal with incoming HTTP requests.
- The “app/Models” directory contains Eloquent ORM models representing database entities (e.g., TaiKhoan, HocKy, ThoiKhoaBieu) that implement the application’s domain.
- “resources/views” holds Blade templates to render dynamic UI for different pages, and “public” includes assets—CSS, JS, images, etc.
- Middleware and routing (in “app/Http/Middleware” and “routes”) clearly indicate that HTTP requests flow through layers such as authentication, security, and other validations before hitting controllers.
- Background processing: The “app/Console/Commands/ScrapeSchedule.php” points to a scheduled or on-demand scraping of schedule data.
- Containerization and deployment are also present with the Dockerfile and docker-compose.yml, indicating that the application might be deployed in a containerized environment.

##### Key Components and Their Interactions (
a. Frontend Component:
- Includes “resources/views” (for UI) and “public” assets (CSS, JavaScript, images).
- Technologies: Blade templating engine, JavaScript libraries (like FullCalendar for calendar views and possibly jQuery).

b. Backend Components:
- HTTP Layer: Routes (from “routes/web.php”, “routes/api.php”) directing traffic to controllers.
- Controllers: Handle different domains such as user accounts (AccountController, AuthController), scheduling/timetables (CalendarController, TimeTableController, SemesterController, RoomController, TietHocController), notifications (NotificationController), and external data fetching (CrawlerController).
- Middleware: Handle tasks like authentication (Authenticate.php), CSRF, role-based access (AdminMiddleware, GiangVienMiddleware) to secure and pre-process requests.
- Models and Domain Entities: Represent data such as accounts (TaiKhoan), roles (VaiTro), notifications (Notification), and timetable specifics (ThoiKhoaBieu, TietHoc, etc.). This layer leverages Laravel’s Eloquent ORM to interact with the database.
- Console Commands: For background tasks such as scraping schedule data (ScrapeSchedule command), encapsulated in “app/Console/Commands”.

c. Persistence/Database Layer:
- Database migrations and seeders in “database/migrations” and “database/seeders” define the schema for tables like “tai_khoan”, “hoc_ky”, “thoi_khoa_bieu”, etc.
- Interaction with models to store and retrieve application data.

d. External and Integration Points:
- Scraping: Components like the CrawlerController and ScrapeSchedule command suggest integration with external websites/APIs to pull timetable data.
- Docker and Deployment: Dockerfile and docker-compose.yml indicate that container orchestration, environment configuration, and possibly additional services (like Redis, if applicable, even though not explicitly visible) might be part of the deployment stack.

##### Architectural Patterns & Design Principles
- MVC Pattern: Clear separation between Models (business logic/data layer), Views (presentation layer), and Controllers (application logic).
- Layered Architecture: Requests flow from web routes through middleware to controllers and then to models, reflecting a standard layered approach.
- Command Pattern for the scraping task, implemented as a Laravel Console command.
- Containerization: Use of Docker for encapsulating the application along with its dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User/Client
    User["User/Client"]:::client

    %% Frontend Subgraph
    subgraph "Web Client / Frontend"
        Views["Views (Blade Templates)"]:::frontend
        Public["Public Assets"]:::frontend
    end

    %% HTTP Routing Layer Subgraph
    subgraph "HTTP Routing Layer"
        WebRoutes["Web Routes"]:::routing
        ApiRoutes["API Routes"]:::routing
    end

    %% Application Layer Subgraph
    subgraph "Application Layer"
        Controllers["Controllers"]:::controller
        Middleware["Middleware"]:::middleware
    end

    %% Domain Layer
    Models["Domain Models"]:::model

    %% Persistence/Database Layer
    Database["Database (Migrations/Seeders)"]:::database

    %% Background Task Processing
    Background["ScrapeSchedule Command"]:::background

    %% Containerization & Deployment Subgraph
    subgraph "Containerization & Deployment"
        Dockerfile["Dockerfile"]:::deployment
        DockerCompose["docker-compose.yml"]:::deployment
    end

    %% Connections (vertical flow)
    User -->|"accesses"| Views
    User -->|"accesses"| Public

    Views -->|"loads"| WebRoutes
    Public -->|"loads"| WebRoutes

    WebRoutes -->|"routes_to"| ApiRoutes
    WebRoutes -->|"passes_through"| Middleware
    ApiRoutes -->|"passes_through"| Middleware

    Middleware -->|"invokes"| Controllers
    Controllers -->|"processes"| Models
    Models -->|"persists_in"| Database

    %% Background Task updating schedule data
    Background -->|"updates"| Models

    %% Deployment influence on core components
    Dockerfile --- Controllers
    Dockerfile --- Models
    DockerCompose --- Controllers
    DockerCompose --- Database

    %% Click Events for Component Mapping
    click Views "https://github.com/namjsdev/computer_room_schedule/tree/main/resources/views"
    click Public "https://github.com/namjsdev/computer_room_schedule/tree/main/public"
    click WebRoutes "https://github.com/namjsdev/computer_room_schedule/blob/main/routes/web.php"
    click ApiRoutes "https://github.com/namjsdev/computer_room_schedule/blob/main/routes/api.php"
    click Controllers "https://github.com/namjsdev/computer_room_schedule/tree/main/app/Http/Controllers"
    click Middleware "https://github.com/namjsdev/computer_room_schedule/tree/main/app/Http/Middleware"
    click Models "https://github.com/namjsdev/computer_room_schedule/tree/main/app/Models"
    click Database "https://github.com/namjsdev/computer_room_schedule/tree/main/database/migrations"
    click Background "https://github.com/namjsdev/computer_room_schedule/blob/main/app/Console/Commands/ScrapeSchedule.php"
    click Dockerfile "https://github.com/namjsdev/computer_room_schedule/tree/main/Dockerfile"
    click DockerCompose "https://github.com/namjsdev/computer_room_schedule/blob/main/docker-compose.yml"

    %% Styles for Colour Coding
    classDef frontend fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef routing fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef controller fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef middleware fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef model fill:#FFDEAD,stroke:#333,stroke-width:2px;
    classDef database fill:#FF8C00,stroke:#333,stroke-width:2px;
    classDef background fill:#40E0D0,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FF69B4,stroke:#333,stroke-width:2px;
    classDef client fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
