# sirknightthebrave/projetogestaobiblioteca architecture

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

- Interactive diagram: https://gitdiagram.com/sirknightthebrave/projetogestaobiblioteca
- Repository: https://github.com/sirknightthebrave/projetogestaobiblioteca

## Overview

##### Project type and purpose
- This is a C# console‐based library management application (“ProjetoGestaoBiblioteca”) that persists data in a MySQL database.
- It follows an object‐oriented design with separate concerns for UI, business logic, data access, and domain entities.

##### File structure
- Top‐level files:
- Program.cs – application entry point
- ConsoleUI.cs – handles command‐line user interactions
- DBContext.cs – data‐access layer using MySQL.Data
- *.cs domain entity files (Book.cs, Copy.cs, CopyCondition.cs, Library.cs, User.cs)
- UserFactory.cs – implements a factory pattern to instantiate different user types
- Utils.cs – utility/helper methods
- SQL folder: contains schema creation (library_management.sql) and seed scripts (populate.sql).
- ProjectoGestaoBiblioteca.csproj/.sln – project and solution definitions.

##### README for additional insights
- MySQL.Data NuGet package is required for DB connectivity.
- Two user roles (admin & user) planned.
- Passwords are encrypted.
- Persistence layer = MySQL database.

##### Main components
a. Console UI Layer
- ConsoleUI.cs
- Program.cs (entry point invoking UI methods)
b. Business Logic Layer
- Library.cs orchestrates operations (borrow, return, search)
- UserFactory.cs creates User instances according to role
- Utils.cs for shared helper logic
c. Data Access Layer
- DBContext.cs issues SQL queries to MySQL, maps results to domain objects
d. Domain Model
- Entities: Book, Copy, CopyCondition, User
e. MySQL Database
- “library_management” database with tables (Books, Copies, Users, etc.)
f. External Dependency
- MySQL.Data connector library

##### Relationships and interactions
- Program.cs → ConsoleUI: starts the application.
- ConsoleUI → Library (BLL): calls high‐level methods (AddBook, RegisterUser, etc.).
- Library → DBContext (DAL): calls CRUD operations.
- DBContext ↔ MySQL Database: executes SQL from .sql scripts.
- Library & DBContext ↔ Domain Entities: pass domain objects back and forth.
- UserFactory → creates User domain instances for Library to use.

##### Architectural patterns and design principles
- Layered architecture: UI → BLL → DAL → Database
- Factory pattern for User creation
- Single Responsibility: each class has a clear, narrow role
- Persistence abstraction: DBContext separates SQL logic from business rules

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Program["Program.cs"]:::ui
        ConsoleUI["ConsoleUI.cs"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        Library["Library.cs"]:::bll
        UserFactory["UserFactory.cs"]:::bll
        Utils["Utils.cs"]:::bll
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        DBContext["DBContext.cs"]:::dal
    end

    %% Domain Model
    subgraph "Domain Model"
        direction TB
        Book["Book.cs"]:::entity
        Copy["Copy.cs"]:::entity
        CopyCondition["CopyCondition.cs"]:::entity
        UserEntity["User.cs"]:::entity
    end

    %% Database
    MySQLDB["MySQL Database"]:::db

    %% Project & Documentation
    subgraph "Project & Documentation"
        direction TB
        README["README.md"]:::docs
        Gitignore[".gitignore"]:::docs
        ProjectFile["ProjectoGestaoBiblioteca.csproj"]:::docs
        SolutionFile["ProjectoGestaoBiblioteca.sln"]:::docs
        SchemaSQL["library_management.sql"]:::docs
        SeedSQL["populate.sql"]:::docs
    end

    %% Connections
    Program -->|"starts application"| ConsoleUI
    ConsoleUI -->|"invoke operations"| Library
    Library -->|"calls CRUD"| DBContext
    DBContext -->|"executes SQL queries"| MySQLDB
    Library -->|"uses entities"| Book
    Library -->|"uses entities"| Copy
    Library -->|"uses entities"| CopyCondition
    Library -->|"uses entities"| UserEntity
    DBContext -->|"maps results to entities"| Book
    DBContext -->|"maps results to entities"| Copy
    DBContext -->|"maps results to entities"| CopyCondition
    DBContext -->|"maps results to entities"| UserEntity
    UserFactory -->|"Factory Pattern creates"| UserEntity

    %% Click Events
    click Program "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/Program.cs"
    click ConsoleUI "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/ConsoleUI.cs"
    click Library "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/Library.cs"
    click UserFactory "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/UserFactory.cs"
    click Utils "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/Utils.cs"
    click DBContext "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/DBContext.cs"
    click Book "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/Book.cs"
    click Copy "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/Copy.cs"
    click CopyCondition "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/CopyCondition.cs"
    click UserEntity "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/User.cs"
    click SchemaSQL "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/sql/library_management.sql"
    click SeedSQL "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/sql/populate.sql"
    click README "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/README.md"
    click Gitignore "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/.gitignore"
    click ProjectFile "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/ProjectoGestaoBiblioteca.csproj"
    click SolutionFile "https://github.com/sirknightthebrave/projetogestaobiblioteca/blob/main/ProjectoGestaoBiblioteca.sln"

    %% Styles
    classDef ui fill:#D0E7FF,stroke:#000,stroke-width:1px
    classDef bll fill:#D0FFD0,stroke:#000,stroke-width:1px
    classDef dal fill:#FFD8B0,stroke:#000,stroke-width:1px
    classDef entity fill:#FFFACD,stroke:#000,stroke-width:1px
    classDef db fill:#E0E0E0,stroke:#000,stroke-width:1px
    classDef docs fill:#F0F0F0,stroke:#000,stroke-width:1px
```
