How aravindr31/watchtower works
Project Type & Purpose
• This is a full-stack web application built on Astro.
• Purpose: serve static and dynamic pages that surface movie, TV, and music data.
• It combines:
• A client‐side UI (Astro pages & components)
• Serverless API endpoints (in src/pages/api/v1)
• A small local database and external third-party services (TMDB, Spotify, torrent metadata, etc.)
File Structure
• Top-level artifacts:
• astro.config.mjs, tailwind.config.mjs, tsconfig.json – Astro & build configurations
• public/ – static assets (favicon, images)
• src/
– layouts/ & pages/ – Astro templates and routes
– components/ – reusable UI pieces (Nav, Searchbar, ContentCard, etc.)
– lib/ – server-side helpers (db.js, authdata.js, tmdb wrappers)
– middleware.ts – global request middleware (auth checks)
• src/pages/api/v1/** – versioned serverless functions for auth, media lookup, user data
• Patterns:
• Atomic UI components + Layout → SSR pages.
• Serverless API layer mapped to /api/v1.
• lib/* modules used by API routes to talk to DB & external services.
Extract Key Insights from README
• It began as Astro’s “basics” starter, then extended with multiple API routes.
Main Components & Interactions
a. Client Browser
• Requests pages (HTML/CSS/JS) and interacts with UI.
b. Astro Server (SSR + Static Assets)
• Serves static files from public/.
• Renders pages/layouts/components on request.
c. Serverless API Layer (/api/v1)
• Auth endpoints: spotifyauth, verifytoken, markaswatched
• Media endpoints: movie, tv, music, tmdb wrappers
d. Local Database
• Handled via src/lib/db.js (e.g., user watch lists, tokens)
e. External Services
• TMDB API for movie/TV details
• Spotify API for music data & user profile
• Torrent metadata API for media availability
f. Middleware (src/middleware.ts)
• Global intercept for token validation, redirects, error handling
Interactions:
• Browser → Astro Server (page navigation)
• Browser JS → /api/v1 endpoints (fetch JSON)
• API endpoints → lib modules → DB & External APIs
• Responses flow back up to Browser
Architectural Patterns & Design Principles
• Separation of concerns: UI vs API vs data
• Versioned API (/api/v1) for future extensibility
• Modular “lib” layer for code reuse
• SSR for SEO + performance, with client fetches for dynamic data