# tira-mis-u/cnpm architecture

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

- Interactive diagram: https://gitdiagram.com/tira-mis-u/cnpm
- Repository: https://github.com/tira-mis-u/cnpm

## Overview

1. **Project type and runtime**
   - This is a **desktop application** for managing student records, built in **C++17** with **Qt 6 Widgets**.
   - The app is organized as a classic **MVC** system and uses **SQLite** through Qt’s `QSQLITE` driver.

2. **Top-level architecture**
   - The repository separates the app into three main layers:
     - **Views**: Qt dialogs and the main window under `src/views`
     - **Controllers**: application logic under `src/controllers`
     - **Models**: domain entities under `src/models`
   - A dedicated **database layer** under `src/database` handles database access.

3. **User interface layer**
   - The UI is implemented with **Qt Widgets** and `.ui` files generated/maintained in **Qt Designer**.
   - Main screens are:
     - `mainwindow`
     - `logindialog`
     - `studentdialog`
     - `classdialog`
     - `departmentdialog`
   - These views are the primary entry points for user actions and data editing.

4. **Application flow**
   - The user interacts with a dialog or the main window.
   - The view triggers a controller method.
   - The controller coordinates validation and persistence.
   - Models represent the data being edited or displayed.
   - The database manager executes SQLite operations.

5. **Controller layer**
   - Controllers exist for the core managed entities:
     - `studentcontroller`
     - `classcontroller`
     - `departmentcontroller`
   - This indicates the app likely supports CRUD-style operations for students, classes, and departments.
   - Controllers form the boundary between UI events and storage logic.

6. **Model layer**
   - The models mirror the core domain objects:
     - `student`
     - `class_model`
     - `department`
   - These are likely used to carry data between controllers, views, and database code.
   - The separation suggests the application avoids putting database logic directly in the UI.

7. **Database subsystem**
   - `src/database/databasemanager.*` is the central persistence component.
   - It likely owns database connection setup and shared query execution against SQLite.
   - This creates a single data-access boundary rather than letting each controller manage its own connection logic.

8. **Data and schema assets**
   - `docs/schema.sql` provides the database schema definition, which is important for understanding the persistent data model.
   - `docs/design.md` likely documents the intended architecture and domain design.
   - Together, these docs are the best source for the logical entity relationships in the system.

9. **Resources and packaging**
   - `src/resources/resources.qrc` bundles Qt resources used by the application.
   - The `deploy/` directory contains a packaged Windows executable and Qt runtime plugins such as `platforms` and `sqldrivers`, showing the app is prepared for desktop distribution.
   - `run.bat` is a convenience launch script for local execution.

10. **Build system**
   - The project uses **CMake** as the build system.
   - The presence of `build/` artifacts and Qt deployment files indicates the repo supports native desktop builds and packaging for Qt.
   - `CMakeLists.txt` is the primary build definition for compiling the widgets app and linking Qt modules.

11. **Boundary summary**
   - The most important architectural boundary is:
     - **UI/interaction** in `views`
     - **business/action coordination** in `controllers`
     - **data representation** in `models`
     - **persistence** in `database`
   - This is a straightforward layered desktop architecture rather than a distributed or service-oriented system.

12. **Diagram guidance**
   - For an architecture diagram, show:
     - user → Qt views
     - views → controllers
     - controllers ↔ models
     - controllers → database manager → SQLite database
   - Treat `docs/schema.sql` as the source of the persistent entity structure, and `deploy/` as packaging/runtime support rather than a runtime subsystem.

Main entry points: [`src/views/mainwindow.cpp`](https://github.com/tira-mis-u/cnpm/blob/main/src/views/mainwindow.cpp) (Main window), [`src/controllers/studentcontroller.cpp`](https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/studentcontroller.cpp) (Student controller), [`src/database/databasemanager.cpp`](https://github.com/tira-mis-u/cnpm/blob/main/src/database/databasemanager.cpp) (DB manager), [`src/controllers/classcontroller.cpp`](https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/classcontroller.cpp) (Class controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_ui["UI layer"]
  node_mainwindow["Main window<br/>view<br/>[mainwindow.cpp]"]
  node_logindialog["Login dialog<br/>view<br/>[logindialog.cpp]"]
  node_studentdialog["Student dialog<br/>view<br/>[studentdialog.cpp]"]
  node_classdialog["Class dialog<br/>view<br/>[classdialog.cpp]"]
  node_departmentdialog["Department dialog<br/>view"]
end

subgraph group_group_logic["Application logic"]
  node_main_cpp["App entry<br/>entrypoint<br/>[main.cpp]"]
  node_studentcontroller["Student controller"]
  node_classcontroller["Class controller"]
  node_departmentcontroller["Department controller"]
end

subgraph group_group_domain["Domain model"]
  node_student_model["Student<br/>model<br/>[student.cpp]"]
  node_class_model["Class<br/>model<br/>[class_model.cpp]"]
  node_department_model["Department<br/>model<br/>[department.cpp]"]
end

subgraph group_group_data["Persistence"]
  node_db_manager[("DB manager<br/>database layer")]
  node_sqlite_db[("SQLite DB<br/>persistent store")]
  node_schema_sql["Schema<br/>[schema.sql]"]
  node_design_md["Design notes<br/>architecture doc<br/>[design.md]"]
  node_resources_qrc["Qt resources<br/>resource bundle<br/>[resources.qrc]"]
  node_cmake["CMake<br/>build system<br/>[CMakeLists.txt]"]
  node_deploy["Deployment<br/>packaging"]
end

node_main_cpp -->|"launches"| node_mainwindow
node_main_cpp -->|"starts"| node_logindialog
node_mainwindow -->|"opens"| node_studentdialog
node_mainwindow -->|"opens"| node_classdialog
node_mainwindow -->|"opens"| node_departmentdialog
node_logindialog -.->|"auth flow"| node_studentcontroller
node_studentdialog -->|"uses"| node_studentcontroller
node_classdialog -->|"uses"| node_classcontroller
node_departmentdialog -->|"uses"| node_departmentcontroller
node_studentcontroller -->|"reads/writes"| node_student_model
node_classcontroller -->|"reads/writes"| node_class_model
node_departmentcontroller -->|"reads/writes"| node_department_model
node_studentcontroller -->|"persists"| node_db_manager
node_classcontroller -->|"persists"| node_db_manager
node_departmentcontroller -->|"persists"| node_db_manager
node_db_manager -->|"queries"| node_sqlite_db
node_schema_sql -.->|"defines"| node_sqlite_db
node_design_md -.->|"guides"| node_studentcontroller
node_resources_qrc -.->|"supports"| node_mainwindow
node_cmake -.->|"builds"| node_main_cpp
node_cmake -.->|"packages"| node_deploy

click node_main_cpp "https://github.com/tira-mis-u/cnpm/blob/main/src/main.cpp"
click node_mainwindow "https://github.com/tira-mis-u/cnpm/blob/main/src/views/mainwindow.cpp"
click node_logindialog "https://github.com/tira-mis-u/cnpm/blob/main/src/views/logindialog.cpp"
click node_studentdialog "https://github.com/tira-mis-u/cnpm/blob/main/src/views/studentdialog.cpp"
click node_classdialog "https://github.com/tira-mis-u/cnpm/blob/main/src/views/classdialog.cpp"
click node_departmentdialog "https://github.com/tira-mis-u/cnpm/blob/main/src/views/departmentdialog.cpp"
click node_studentcontroller "https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/studentcontroller.cpp"
click node_classcontroller "https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/classcontroller.cpp"
click node_departmentcontroller "https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/departmentcontroller.cpp"
click node_student_model "https://github.com/tira-mis-u/cnpm/blob/main/src/models/student.cpp"
click node_class_model "https://github.com/tira-mis-u/cnpm/blob/main/src/models/class_model.cpp"
click node_department_model "https://github.com/tira-mis-u/cnpm/blob/main/src/models/department.cpp"
click node_db_manager "https://github.com/tira-mis-u/cnpm/blob/main/src/database/databasemanager.cpp"
click node_schema_sql "https://github.com/tira-mis-u/cnpm/blob/main/docs/schema.sql"
click node_design_md "https://github.com/tira-mis-u/cnpm/blob/main/docs/design.md"
click node_resources_qrc "https://github.com/tira-mis-u/cnpm/blob/main/src/resources/resources.qrc"
click node_cmake "https://github.com/tira-mis-u/cnpm/blob/main/CMakeLists.txt"
click node_deploy "https://github.com/tira-mis-u/cnpm/blob/main/deploy/QuanLyHoSoSinhVien.exe"

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_mainwindow,node_logindialog,node_studentdialog,node_classdialog,node_departmentdialog toneBlue
class node_main_cpp,node_studentcontroller,node_classcontroller,node_departmentcontroller toneAmber
class node_student_model,node_class_model,node_department_model toneMint
class node_db_manager,node_sqlite_db,node_schema_sql,node_design_md,node_resources_qrc,node_cmake,node_deploy toneRose
```

## Components

### UI layer

Qt Widgets screens and dialogs used for user interaction.

- [Main window](https://github.com/tira-mis-u/cnpm/blob/main/src/views/mainwindow.cpp): view · Primary application shell for navigation and user actions. · `src/views/mainwindow.cpp`
- [Login dialog](https://github.com/tira-mis-u/cnpm/blob/main/src/views/logindialog.cpp): view · Authentication or startup gate dialog. · `src/views/logindialog.cpp`
- [Student dialog](https://github.com/tira-mis-u/cnpm/blob/main/src/views/studentdialog.cpp): view · Student editing and detail dialog. · `src/views/studentdialog.cpp`
- [Class dialog](https://github.com/tira-mis-u/cnpm/blob/main/src/views/classdialog.cpp): view · Class editing and detail dialog. · `src/views/classdialog.cpp`
- [Department dialog](https://github.com/tira-mis-u/cnpm/blob/main/src/views/departmentdialog.cpp): view · Department editing and detail dialog. · `src/views/departmentdialog.cpp`

### Application logic

Controllers and app entry that coordinate actions.

- [App entry](https://github.com/tira-mis-u/cnpm/blob/main/src/main.cpp): entrypoint · Starts the Qt application and opens the main UI. · `src/main.cpp`
- [Student controller](https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/studentcontroller.cpp): controller · Coordinates student-related actions and persistence. · `src/controllers/studentcontroller.cpp`
- [Class controller](https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/classcontroller.cpp): controller · Coordinates class-related actions and persistence. · `src/controllers/classcontroller.cpp`
- [Department controller](https://github.com/tira-mis-u/cnpm/blob/main/src/controllers/departmentcontroller.cpp): controller · Coordinates department-related actions and persistence. · `src/controllers/departmentcontroller.cpp`

### Domain model

Core student, class, and department entities.

- [Student](https://github.com/tira-mis-u/cnpm/blob/main/src/models/student.cpp): model · Student domain entity used across the app. · `src/models/student.cpp`
- [Class](https://github.com/tira-mis-u/cnpm/blob/main/src/models/class_model.cpp): model · Class domain entity used across the app. · `src/models/class_model.cpp`
- [Department](https://github.com/tira-mis-u/cnpm/blob/main/src/models/department.cpp): model · Department domain entity used across the app. · `src/models/department.cpp`

### Persistence

Database access, schema, and deployment/runtime support.

- [DB manager](https://github.com/tira-mis-u/cnpm/blob/main/src/database/databasemanager.cpp): database layer · Central SQLite access and query coordination. · `src/database/databasemanager.cpp`
- **SQLite DB**: persistent store · Application data stored through the Qt SQL driver.
- [Schema](https://github.com/tira-mis-u/cnpm/blob/main/docs/schema.sql): schema doc · Database schema definition for the persistent model. · `docs/schema.sql`
- [Design notes](https://github.com/tira-mis-u/cnpm/blob/main/docs/design.md): architecture doc · Repository documentation for intended structure and domain rules. · `docs/design.md`
- [Qt resources](https://github.com/tira-mis-u/cnpm/blob/main/src/resources/resources.qrc): resource bundle · Bundled application resources referenced by Qt. · `src/resources/resources.qrc`
- [CMake](https://github.com/tira-mis-u/cnpm/blob/main/CMakeLists.txt): build system · Build definition for compiling and linking the desktop app. · `CMakeLists.txt`
- [Deployment](https://github.com/tira-mis-u/cnpm/blob/main/deploy/QuanLyHoSoSinhVien.exe): packaging · Packaged executable and Qt runtime plugins for distribution. · `deploy/QuanLyHoSoSinhVien.exe`

## Connections

- App entry → Main window: launches · Application entry creates and shows the main window.
- App entry → Login dialog: starts · Startup flow may present the login dialog first.
- Main window → Student dialog: opens · Main window opens student management screens.
- Main window → Class dialog: opens · Main window opens class management screens.
- Main window → Department dialog: opens · Main window opens department management screens.
- Login dialog → Student controller: auth flow · Login or startup actions route into application control.
- Student dialog → Student controller: uses · Student dialog delegates actions to the controller.
- Class dialog → Class controller: uses · Class dialog delegates actions to the controller.
- Department dialog → Department controller: uses · Department dialog delegates actions to the controller.
- Student controller → Student: reads/writes · Controller works with student domain objects.
- Class controller → Class: reads/writes · Controller works with class domain objects.
- Department controller → Department: reads/writes · Controller works with department domain objects.
- Student controller → DB manager: persists · Student operations are stored through the database manager.
- Class controller → DB manager: persists · Class operations are stored through the database manager.
- Department controller → DB manager: persists · Department operations are stored through the database manager.
- DB manager → SQLite DB: queries · Database manager executes SQL against SQLite.
- Schema → SQLite DB: defines · Schema document defines the persistent tables and relationships.
- Design notes → Student controller: guides · Design documentation informs the layered controller structure.
- Qt resources → Main window: supports · Qt resources are consumed by the UI layer.
- CMake → App entry: builds · CMake builds the application entry and linked modules.
- CMake → Deployment: packages · Build and deployment outputs are prepared for distribution.
