How neolaner/scoap-next works
Main Components
• Frontend (Client-Side UI)
• Located primarily under the “src/app” directory.
• Contains numerous pages (e.g., home, login, user, collections, search, stream, help, settings) and a rich set of UI components and layouts.
• Includes several provider components (under “src/app/_providers”) that establish global state management (e.g., for chat data, current media, subtitles, etc.).
• Uses modern React hooks (under “src/app/_hooks”) to manage component-level logic and interactions.
• Backend API and Server Logic
• API endpoints are organized under “src/app/api” (for authentication and tRPC routes) and further elaborated in the “src/server/api/routers” directory (routers for addons, collections, media sources, room, source, subtitle, and user).
• tRPC integration is used for strongly typed API communication between the client and server.
• The “src/server” directory contains additional server files, including authentication (NextAuth integration) and database connection/configuration.
• Database
• The “prisma” directory includes both the Prisma schema and migration files. This establishes the connection and data modeling used by the app.
• Shared Libraries/Utilities and Third-Party Services
• The “src/lib” folder holds shared types, utilities, event emitters, socket configuration, collections handling, and stream functions.
• Under “src/app/_services”, you see further abstractions for sockets, streaming (stremIo), and addons which abstract external service communications.
• Static Assets & Configurations
• The “public” folder holds static assets.
• Config files (Tailwind config, ESLint, Prettier, Next config) support project configuration and styling.
Interactions and Data Flow
• Frontend components (pages and UI) interact with provider components which encapsulate global state.
• These UI components call API endpoints via tRPC (or traditional routes under “src/app/api”) to perform operations such as authentication or interacting with media, sources, and rooms.
• Server-side endpoints (in “src/server/api/routers” and “src/server/api/trpc”) handle these requests, enforce business logic, and interact with the database (using Prisma).
• Communication with external services (via socket connections and streaming services) is managed by dedicated services in the “src/app/_services” and “src/lib/socket” folders.
• Data flows from the client through API gateways to the database and external integrations, with feedback and state propagation managed via React providers and event emitters.
Architectural Patterns & Design Principles
• The application adheres to a separation of concerns:
• UI Layer/Presentation: All components in “src/app/_ui”, “src/components”, and corresponding providers.
• API/Business Logic Layer: Managed by Next.js API routes and tRPC routers.
• Data Access Layer: Encapsulated with Prisma (migrations, schema) in the “prisma” directory.
• Emphasis on modularity and reusability is apparent by splitting utilities (src/lib) and hooks (src/app/_hooks) for common functionality.
• Real-time or reactive elements are supported via socket services and event emitters.
• File-based routing, a Next.js staple, is used to structure the UI and API endpoints, fostering clarity and ease of navigation.