How hunga516/vi-frontend works
Project Type & Purpose
• This is a full-stack web application built on Next.js.
• Its purpose appears to be delivering a web interface for user authentication (sign‑in/sign‑up), home page functionalities (with community (“cong-dong”), vi‑short, etc.), and API endpoints, while also providing server‑side functionality using TRPC and database operations.
• The presence of modules (like src/modules/auth and src/modules/home) indicates a separation of concerns with dedicated components for authentication and home page management.
Main Components
a. Frontend (Next.js Routes/Pages):
• The app directory contains multiple route segments (e.g., (auth), (home)) that define the user-facing pages.
• The layout components in the various subdirectories (like src/app/(auth)/layout.tsx and src/app/(home)/layout.tsx) provide structural frameworks.
• UI components (in src/components, src/components/ui, and modules directories) serve as the building blocks for the frontend interface.
b. Backend API:
• The API routes (under src/app/api) expose endpoints like /api/trpc and /api/users/webhook, which handle TRPC calls and webhooks.
• The TRPC integration (with files in src/trpc and src/app/api/trpc) connects frontend requests to server-side business logic.
c. Database & Data Layer:
• The project uses Drizzle (see drizzle.config.ts) and has a dedicated database folder (src/db) with schemas and connection files.
• Additional utilities for Redis connections (src/lib/redis.ts) and rate limiting (src/lib/ratelimit.ts) hint at caching and request control mechanisms.
d. Modules and Business Logic:
• The modules directory (e.g., src/modules/auth and src/modules/home) separates feature-specific logic and UI.
• Each module encapsulates its own UI components, server-side logic, or procedures (for instance, in category/server).
Architectural Relationships & Interactions
• The frontend communicates with backend API endpoints via fetch/TRPC calls.
• Authentication flows are handled in the (auth) route, which interacts with backend security and database modules.
• The TRPC server acts as a bridge between API requests from the frontend and the business logic inside various modules.
• Database operations, performed through Drizzle in the src/db directory, support dynamic data fetching for pages and API responses.
• Shared UI and utility components facilitate cross-feature consistency (e.g., shared components like navigation, modals, etc.).
Architectural Patterns and Design Principles
• The project uses Next.js’s app router to manage routes and layouts, following a component-based architecture.
• Modularization is evident with dedicated directories for modules (auth, home, category) promoting separation of concerns.
• The TRPC integration suggests an API design that embraces type safety and end-to-end contracts.
• Use of middleware (src/middleware.ts) signals that cross-cutting concerns (such as authentication or error handling) are managed centrally.