# wildcatco/boj-helper architecture

> Architecture diagram of the GitHub repository wildcatco/boj-helper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wildcatco/boj-helper
- Repository: https://github.com/wildcatco/boj-helper

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Top-level User
    USER["User"]:::frontend

    %% Frontend Layer
    subgraph "Frontend (Presentation/UI Layer)"
        PAGES["Pages"]:::frontend
        COMPONENTS["UI Components"]:::frontend
        HOOKS["Hooks"]:::frontend
        STATES["States"]:::frontend
        STORYBOOK["Storybook"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (API/Server-Side Logic)"
        API["API Endpoints"]:::backend
        SERVICES["Services"]:::backend
        MIDDLEWARE_F["API Middleware (Folder)"]:::backend
        MIDDLEWARE_FI["API Middleware (File)"]:::backend
    end

    %% Data & Persistence Layer
    subgraph "Data & Persistence Layer"
        PRISMA["Prisma Schema & Seed"]:::database
        DB["Database Access Library"]:::database
    end

    %% Utility & Shared Resources
    subgraph "Utility & Shared Resources"
        UTILS["Utility Functions"]:::utilities
        TYPES["Types"]:::utilities
        CONSTANTS["Constants"]:::utilities
    end

    %% Connections - Frontend
    USER -->|"interacts"| PAGES
    PAGES -->|"renders"| COMPONENTS
    PAGES -->|"invokes"| HOOKS
    HOOKS -->|"manages"| STATES
    COMPONENTS -->|"uses"| TYPES

    %% Connections - Frontend to Backend
    HOOKS -->|"calls"| SERVICES

    %% Connections - Backend
    SERVICES -->|"processes"| API
    API -->|"secured by"| MIDDLEWARE_F
    API -->|"secured by"| MIDDLEWARE_FI

    %% Connections - Backend to Data Layer
    API -->|"queries"| PRISMA
    API -->|"queries"| DB

    %% Connections - Backend to Utility
    SERVICES -->|"utilizes"| UTILS
    SERVICES -->|"uses"| TYPES
    SERVICES -->|"uses"| CONSTANTS

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef database fill:#ABEBC6,stroke:#28B463,stroke-width:2px;
    classDef utilities fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;

    %% Click Events
    click PAGES "https://github.com/wildcatco/boj-helper/tree/main/pages"
    click COMPONENTS "https://github.com/wildcatco/boj-helper/tree/main/components"
    click STATES "https://github.com/wildcatco/boj-helper/tree/main/states"
    click HOOKS "https://github.com/wildcatco/boj-helper/tree/main/hooks"
    click STORYBOOK "https://github.com/wildcatco/boj-helper/blob/main/.storybook"
    click API "https://github.com/wildcatco/boj-helper/tree/main/pages/api"
    click SERVICES "https://github.com/wildcatco/boj-helper/tree/main/services"
    click MIDDLEWARE_F "https://github.com/wildcatco/boj-helper/tree/main/pages/api/middlewares"
    click MIDDLEWARE_FI "https://github.com/wildcatco/boj-helper/blob/main/middleware.api.ts"
    click PRISMA "https://github.com/wildcatco/boj-helper/tree/main/prisma"
    click DB "https://github.com/wildcatco/boj-helper/blob/main/libs/db/prisma.ts"
    click UTILS "https://github.com/wildcatco/boj-helper/tree/main/libs/utils"
    click TYPES "https://github.com/wildcatco/boj-helper/tree/main/types"
    click CONSTANTS "https://github.com/wildcatco/boj-helper/tree/main/libs/constants"
```
