How emerss001/api-bibliotech works
Project type and purpose
• This is a standalone Java‐based RESTful API (“api-bibliotec”) that exposes endpoints for managing a virtual library (users, materials, loans, evaluations).
• It follows a layered architecture (Controller → Service → DAO → Database) and uses MySQL (via Docker Compose) plus Firebase for media storage and JWT for authentication.
File structure
Top‐level:
• Server.java – application entrypoint, sets up the HTTP server & routes
• docker-compose.yml – spins up MySQL
• pom.xml – Maven dependencies (Spark/Spring, MySQL, Firebase SDK, JWT libs)
src/controller/ – REST controllers (AuthController, PessoaController, CatalogoController, etc.)
src/service/ – business logic services matching each controller
src/dao/ – data access objects interacting with DB
src/db/ – DB connection (ConnectionDB) + SQL migrations
src/dto/ – request/response payloads
src/entity/ – JPA‐style domain models (Pessoa, Material, Emprestimo, etc.)
src/util/ – helpers (FirebaseInitializer, FirebaseUpload, TokenUtil)
src/exception/ – custom exceptions
README highlights
• Java 24, Maven, Docker Compose (MySQL)
• Endpoints for user CRUD, login, material catalog, evaluations, loans
• No built‐in frontend – purely backend microservice/API
Core components
a. Client (e.g., Web or Mobile app)
b. API Server (Server.java)
– HTTP Router & Authentication Filter (TokenUtil)
– Controllers (AuthController, PessoaController, …)
c. Service Layer
– AuthService, PessoaService, MaterialService, …
– Orchestrates business rules & calls DAOs or util (FirebaseUpload)
d. Persistence Layer
– DAOs (AvaliacaoDAO, EmprestimoDAO, …)
– ConnectionDB → MySQL (container)
– DB Migrations (src/db/migrations)
e. External Services
– Firebase Storage (initialized via FirebaseInitializer)
Relationships and data flow
• Client → HTTP → Server (port 8888)
• Server → Controller (route matching)
• Controller → Service (pass validated DTO)
• Service → DAO (CRUD operations via JDBC/MySQL)
• DAO → MySQL Container
• Service → FirebaseUpload (for digital material files)
• TokenUtil ↔ Controllers (to issue/validate JWT tokens)
Architectural patterns & principles
• Layered Architecture (Presentation / Business / Data)
• DTO Pattern (to decouple domain entities from API models)
• DAO Pattern (for persistence isolation)
• Single Responsibility per layer/component