How crafael23/sistema-bibliotecario works
Project Type and Purpose
• This is a full-stack web application built with Next.js 13’s app router.
• It serves as a library management system (“Sistema Bibliotecario”) with two main user roles: administrators (who manage books, inventory, reports, reservations, and users) and end-users (who browse, reserve, and view their profile).
• It uses Drizzle ORM to interact with a relational database (likely PostgreSQL), Uploadthing for file uploads, and custom server-side code under src/server.
File Structure Analysis
• Top-level config and dependency files (.env, tsconfig.json, tailwind.config.ts, drizzle.config.ts).
• src/app: Next.js app router – comprised of separate routes for /admin, /homepage, /usuario and API endpoints under src/app/api.
• src/app/admin: Admin UI pages (book addition, inventory, reports, reservations, user management).
• src/app/homepage: Public catalog/browsing and user profile.
• src/app/usuario: New-user onboarding flow.
• src/components + src/components/ui: Shared UI primitives and global components.
• src/hooks, src/lib, src/utils: Reusable client-side utilities and hooks.
• src/server/db: Server-side database schema, queries, seeding, demo data.
• API routes under src/app/api: Uploadthing integration, user-specific fines & reservations, webhooks.
Key Architectural Patterns
• Layered architecture:
• Presentation layer: Next.js pages & React components (split into server vs. client components).
• Application/API layer: Next.js server actions and API routes.
• Data layer: Drizzle ORM + raw SQL queries + repository pattern in src/server/db.
• Next.js app-router conventions (layouts, page.tsx, loading.tsx per route).
• Shared component library follows an atomic design approach.
• Use of React Server Components (RSC) for data fetching and UI hydration.
Main Components
a. Client (Browser)
• Administrator UI (under /admin)
• Public UI (catalog & profile under /homepage)
b. Next.js Application (Server + API)
• App Router: route handlers & server actions
• React Server Components & Client Components
• API Routes: /api/uploadthing, /api/user, /api/webhooks
c. Database
• PostgreSQL (Drizzle ORM + SQL schema + queries + seeding)
d. File Storage Service
• Uploadthing (handles image/book cover uploads)
e. External Integrations (optional)
• Webhooks (incoming events)
Relationships & Data Flows
• Client → Next.js pages (SSR/SSG/Client)
• Server actions & API routes → Drizzle ORM → PostgreSQL
• Upload requests → Uploadthing service → storage bucket
• Server receives webhooks → Next.js API → internal processing → Database
• Admin UI requests reservation/report data → Next.js server actions → DB queries