How wildcatco/boj-helper works
Main Components
• Frontend (Presentation/UI Layer):
• Pages: Found under the “pages” directory, this includes routes like index, signin, snippet, problems, exercise, solve, etc.
• Components: Located in the “components” directory. This folder hosts a myriad of UI elements including Layouts (with headers, navigation, profiles), UI components (Buttons, Input, Modal, Table, etc.), and specific feature components (Snippet lists, snippet modals, solution components, problem details).
• States & Hooks: The “states” and “hooks” directories manage local state and business logic that coordinate user actions and data fetching.
• Storybook: Located in the “.storybook” folder, for UI component development and testing.
• Backend (API / Server-Side Logic):
• API Endpoints: Under “pages/api,” you have various routes handling business logic such as authentication (NextAuth integration), snippet management, categories, solutions, problem saving, and code execution testing.
• Services: The “services” folder abstracts operations for problems, run-code (execution), and solutions, acting as a bridge between the API and the data layer.
• Middleware: API middlewares (e.g., require-auth) to secure endpoints.
• Data & Persistence Layer:
• Database Access: The “prisma” directory contains the Prisma schema and seed files to define and populate the database.
• Libraries for DB: The “libs/db” folder (prisma.ts) and “libs/api” for API error handling indicate a clear separation for data access and error management.
• Utility & Shared Resources:
• Utility Functions: Located in “libs/utils,” these offer debounce, fetcher, formatter, language utilities, and query-string helpers.
• Types & Constants: The “types” and “libs/constants” folders define shared TypeScript types, DTOs (data transfer objects), errors, languages, and pagination details, ensuring type safety and consistency.
• Configuration Files: Files like next.config.js, tsconfig.json, package-related configs, ESLint and Prettier configs contribute to project configurations.
Relationships and Interactions
• The UI components (React components in “components”) render pages based on the routing defined in the “pages” folder.
• Pages often call services (from the “services” folder) via hooks found in the “hooks” directory to fetch or manipulate data.
• API routes (in “pages/api”) are the backend endpoints that interact with the database using Prisma (in the “prisma” folder) and utilize utility functions/libraries.
• Shared Types and constants abstract the data contracts between the frontend, backend services, and database.
• There is clear separation of concerns: UI components concern themselves solely with presentation while API endpoints handle business logic and data access.
Architectural Patterns and Design Principles
• Component-Based Architecture: The project leverages a modular React design with reusable UI components.
• Next.js Routing: The separation between pages (for direct routing) and components helps in organizing route-driven pages and UI layout.
• API Layer Abstraction: Using services to abstract data logic and API endpoints helps separate client and server code.
• State Management & Hooks: The states and custom React hooks are used to manage local state and side effects efficiently.
• Type Safety and Consistency: Extensive use of TypeScript types and DTOs enforces robust contracts between components.