# adityasharmawork/algosprint architecture

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

- Interactive diagram: https://gitdiagram.com/adityasharmawork/algosprint
- Repository: https://github.com/adityasharmawork/algosprint

## Overview

##### Project’s Main Purpose and Type
- AlgoSprint is a full-stack web application that tracks coding contests from platforms such as Codeforces, CodeChef, and LeetCode.
- Its primary purpose is to fetch and present both upcoming and past contests, allow bookmarking of contests, and provide video solution links.
- The project uses the MERN stack (MongoDB, Express.js, React.js, Node.js) with additional features like web scraping and GraphQL for API data handling.

##### File Structure
- The top-level directories include ‘client’ and ‘server’, indicating a clear separation between the frontend and backend layers.
- The “client” folder contains all the React source code, including various UI components (many of which follow a design system pattern with components in a “ui” subdirectory), pages, hooks, and configuration files (like Tailwind, Vite).
- The “server” folder contains controller files for different contest platforms (organized by platform: Codechef, Codeforces, LeetCode) as well as routes and authentication middleware.
- The presence of configuration files such as package.json (at the root, client, and server) indicates clear dependency management and build processes.

##### Main Components
a. Frontend:
- React Application: Contains UI components (e.g., ContestCard, Navbar), pages (HomePage, AdminPage, NotFound, etc.), and various utility hooks.
- Styling & State Management: Tailwind CSS along with light/dark mode toggling, search functionality and filtering UI.

b. Backend:
- Node.js Server using Express.js:
- Controllers divided by contest platforms (Codechef, Codeforces, LeetCode) for handling API logic.
- Routes that expose endpoints for fetching upcoming and past contests.
- Middleware for authentication (JWT-based) and other request handling.
- Integration of GraphQL endpoints and web scraping logic to fetch contest data.

c. Database:
- MongoDB: Stores user data, bookmarks, and additional contest-related metadata (e.g., saved video solutions).

d. External Services:
- Web sources for contest information (via web scraping and/or API calls).
- Deployment services (Render and possibly Vercel for the frontend).
- YouTube as an external provider for video solution content.

##### Relationships and Interactions
- The frontend communicates with the backend through RESTful API endpoints (e.g., /api/codechef/upcoming, /api/codeforces/past) and possibly GraphQL for more complex queries.
- The backend controllers act as intermediaries: they perform web scraping and API calls to third-party contest platforms, then format the data to be consumed by the frontend.
- The backend likely interacts with MongoDB to manage user sessions, store bookmarks, and save video solution links.
- Authentication middleware protects routes to ensure that only authenticated users can bookmark and access certain functionalities.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear split between client and server functionality.
- MVC-like pattern on the backend: Controllers (handling business logic), Routes (defining API endpoints), and middleware (handling cross-cutting concerns like authentication).
- Component-based architecture in the frontend: Organized UI components and hooks that promote reusability.
- Usage of modern JavaScript frameworks (React, Node.js) and configuration-driven styling (Tailwind CSS).

##### Customize for AlgoSprint Specifics
- For the Frontend: Emphasize the modular structure found in the “client” directory with components and pages, including UI components like ThemeToggle and the various dialog components.
- For the Backend: Highlight how there are separate controllers and routes for the three main contest platforms. Mark the organizational structure that delineates between upcoming and past contests for each platform.
- Since the project involves web scraping and GraphQL, consider adding sub-components within the backend block that represent “Web Scraping Logic” and “GraphQL API Handler.”

##### Final Touches
- Notable configuration elements such as authentication (JWT middleware) and deployment targets (Render for backend, Vercel for frontend).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React App)"
        FE1["React App"]:::frontend
        FE2["UI Components"]:::frontend
        FE2a["UI Subcomponents"]:::frontend
        FE3["Pages"]:::frontend
        FE4["Utility Hooks"]:::frontend
        FE5["API Service Layer"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express Server)"
        BE1["Express Server"]:::backend
        BE2["Auth Middleware"]:::backend
        BE6["Codechef Routes"]:::backend
        BE7["Codeforces Routes"]:::backend
        BE8["LeetCode Routes"]:::backend
        BE3["Codechef Controllers"]:::backend
        BE4["Codeforces Controllers"]:::backend
        BE5["LeetCode Controllers"]:::backend
        BE9["Web Scraping Logic"]:::backend
        BE10["GraphQL API Handler"]:::backend
    end

    %% Database
    subgraph "Database"
        DB["MongoDB"]:::db
    end

    %% External Services
    subgraph "External Services"
        EX1["Contest Data Sources"]:::external
        EX2["YouTube API"]:::external
        EX3["Deployment: Render/Vercel"]:::external
    end

    %% Connections
    FE5 -->|"API_calls"| BE1
    FE5 -.->|"auth_request"| BE2

    BE1 -->|"routes"| BE6
    BE1 -->|"routes"| BE7
    BE1 -->|"routes"| BE8
    BE1 -->|"scrapes"| BE9
    BE1 -->|"graphql"| BE10
    BE1 -->|"DB_ops"| DB
    BE1 -->|"videos"| EX2

    BE6 -->|"handles"| BE3
    BE7 -->|"handles"| BE4
    BE8 -->|"handles"| BE5

    BE9 -->|"fetches"| EX1
    BE10 -->|"queries"| EX1

    %% Click Events for Frontend
    click FE1 "https://github.com/adityasharmawork/algosprint/tree/main/client/src"
    click FE2 "https://github.com/adityasharmawork/algosprint/tree/main/client/src/components"
    click FE2a "https://github.com/adityasharmawork/algosprint/tree/main/client/src/components/ui"
    click FE3 "https://github.com/adityasharmawork/algosprint/tree/main/client/src/pages"
    click FE4 "https://github.com/adityasharmawork/algosprint/tree/main/client/src/hooks"
    click FE5 "https://github.com/adityasharmawork/algosprint/blob/main/client/src/services/api.js"

    %% Click Events for Backend
    click BE1 "https://github.com/adityasharmawork/algosprint/tree/main/server"
    click BE2 "https://github.com/adityasharmawork/algosprint/blob/main/server/middlewares/auth.js"
    click BE3 "https://github.com/adityasharmawork/algosprint/tree/main/server/controllers/codechefControllers"
    click BE4 "https://github.com/adityasharmawork/algosprint/tree/main/server/controllers/codeforcesControllers"
    click BE5 "https://github.com/adityasharmawork/algosprint/tree/main/server/controllers/leetcodeControllers"
    click BE6 "https://github.com/adityasharmawork/algosprint/blob/main/server/routes/codechefRoutes/contest.js"
    click BE7 "https://github.com/adityasharmawork/algosprint/blob/main/server/routes/codeforcesRoutes/contest.js"
    click BE8 "https://github.com/adityasharmawork/algosprint/blob/main/server/routes/leetcodeRoutes/contest.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef db fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
