# Backend Development Guidelines

> Backend conventions for the JSP + Servlet + MySQL library-management system.

---

## Overview

The developer has established the backend architecture as a B/S Java web
application using JSP + Servlet, MySQL, Tomcat, and IDEA. The initial scaffold
now exists under `src/main/`; remaining module names below describe conventions
for future feature work.

Use a layered design:

```
JSP/CSS presentation -> Servlet controller -> Service/business -> DAO -> MySQL
```

Controllers handle request dispatch, parameter validation, and result return.
Services handle business workflows and permission checks. DAOs perform database
CRUD. MySQL stores books, categories, readers, borrowing records,
administrators, roles/permissions, and system logs.

---

## Guidelines Index

| Guide | Description | Status |
|-------|-------------|--------|
| [Directory Structure](./directory-structure.md) | Servlet, service, DAO, entity, and config organization | Project decision documented |
| [Database Guidelines](./database-guidelines.md) | MySQL tables, DAO CRUD, keys, and transactions | Project decision documented |
| [Error Handling](./error-handling.md) | Servlet validation, service failures, and safe responses | Project decision documented |
| [Quality Guidelines](./quality-guidelines.md) | Layer boundaries and review constraints | Project decision documented |
| [Logging Guidelines](./logging-guidelines.md) | System logs, key operations, and exception tracing | Project decision documented |

---

## Pre-Development Checklist

Before backend implementation, read:

- `.trellis/spec/backend/directory-structure.md`
- `.trellis/spec/backend/database-guidelines.md`
- `.trellis/spec/backend/error-handling.md`
- `.trellis/spec/backend/logging-guidelines.md`
- `.trellis/spec/backend/quality-guidelines.md`
- `.trellis/tasks/archive/2026-04/00-bootstrap-guidelines/research/project-requirements.md`

---

## Core Backend Modules

- Login and permission management for administrator, librarian, and reader
  roles.
- Book information management for create, update, delete, category maintenance,
  and inventory status.
- Reader information management for profiles, borrowing eligibility, and
  contact information.
- Borrowing and return management for borrow, return, renew, overdue handling,
  and automatic collection status updates.
- Book search and statistics for combined title, author, category, and ID
  search, borrowing rankings, inventory reports, and overdue reports.
- System maintenance and logs for key operation logs, data backup support, and
  exception tracing.

## Evidence

- `.trellis/tasks/archive/2026-04/00-bootstrap-guidelines/research/repo-scan.md`
  records the initial pre-scaffold repo scan.
- `.trellis/tasks/archive/2026-04/00-bootstrap-guidelines/research/project-requirements.md`
  records the developer-provided stack, architecture, modules, and data model.

---

**Language**: All documentation should be written in **English**.
