# michalwr88/stats-generator architecture

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

- Interactive diagram: https://gitdiagram.com/michalwr88/stats-generator
- Repository: https://github.com/michalwr88/stats-generator

## Overview

##### Main Architectural Components
- Frontend/UI Layer: Represented by the Next.js pages and components in the “src/app” and “src/components” folders. This layer consists of:
– Pages and Layouts: e.g., (WithNavBar) pages, calendar, charts.
– Hooks and Utilities: Custom hooks (useGetSprints, useEditSprint etc.) and helper utilities that add client-side logic.
- API Layer: Next.js API routes are defined under “src/api” and “src/app/api”. This contains:
– Authentication Routes (using NextAuth, see folder “auth”).
– MongoDB Endpoints: API routes for handling configurations, reports, sprints, etc. (under “mongo”).
– Slack Integration: API endpoints to interact with Slack.
- Data Access and Business Logic:
– Mongo Service: The “src/mongoService” directory encapsulates the database operations with modules like MongoSprint, MongoEvents, MongoUsers. They handle CRUD operations and query helpers.
– Models & Schemes: The “src/models” (and subfolder “mongo”) define the data structures and schemas that map and validate data.
- External Services:
– MongoDB: Used as the primary data store.
– Slack: For communication and notifications.

##### Out the Data Flow and Interactions
- UI Interaction: Users interact with the Next.js front-end (pages, components, forms) which use custom hooks to handle events such as adding or editing a sprint.
- Business Logic: API endpoints often call on the Mongo Service layer which wraps calls to MongoDB and handles necessary business logic and data mapping using the defined models.

##### Highlighting Architectural Patterns and Key Technologies
- Next.js’s File-Based Routing: Showcase how the “src/app” and “src/app/api” directories map to UI pages and API endpoints.
- Separation of Concerns: Different directories are cleanly separated (UI, API, data services, hooks, models).
- Component Reuse: Many shared UI components (buttons, forms, navbars) suggest a modular component design.
- Data Flow: Emphasize client-server interactions using RESTful or Next.js API paradigms.
- MongoDB Integration: Note the use of mongoService files and models as the abstraction layer over the database.
- External Integrations: Include Slack and potentially Vercel deployment (via vercel.json).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Layer
    subgraph "Frontend/UI"
        subgraph "Pages & Layouts"
            AddSprint["Add Sprint Page"]
            CurrSprint["Current Sprint Page"]
            SprintList["Sprint List Page"]
            Calendar["Calendar Page"]
            Charts["Charts Page"]
        end
        Components["React Components"]
        Hooks["Custom Hooks & Utils"]
    end

    %% API Layer
    subgraph "API Layer"
        AuthAPI["Auth API"]
        subgraph "Mongo Endpoints"
            ConfigAPI["Config API"]
            ReportAPI["Report API"]
            ReportDetailAPI["Report Detail API"]
            SprintAPI["Sprint API"]
            SprintsAPI["Sprints API"]
        end
        SlackAPI["Slack API"]
    end

    %% Business Logic & Data Access
    subgraph "Business Logic & Data Access"
        MongoService["Mongo Service"]
        Models["Models & Schemas"]
    end

    %% External Services
    subgraph "External Services"
        MongoDB["MongoDB"]
        Slack["Slack"]
    end

    %% Connections from Frontend to API
    AddSprint -->|"triggers"| Hooks
    CurrSprint -->|"triggers"| Hooks
    SprintList -->|"triggers"| Hooks
    Calendar -->|"triggers"| Hooks
    Charts -->|"triggers"| Hooks
    Components -->|"supports"| Hooks

    Hooks -->|"calls"| AuthAPI
    Hooks -->|"calls"| ConfigAPI
    Hooks -->|"calls"| ReportAPI
    Hooks -->|"calls"| ReportDetailAPI
    Hooks -->|"calls"| SprintAPI
    Hooks -->|"calls"| SprintsAPI
    Hooks -->|"calls"| SlackAPI

    %% Connections from API to Business Logic
    AuthAPI -->|"processes"| MongoService
    ConfigAPI -->|"processes"| MongoService
    ReportAPI -->|"processes"| MongoService
    ReportDetailAPI -->|"processes"| MongoService
    SprintAPI -->|"processes"| MongoService
    SprintsAPI -->|"processes"| MongoService

    MongoService -->|"utilizes"| Models
    Models -->|"persists to"| MongoDB

    %% Slack Integration
    SlackAPI -->|"notifies"| Slack

    %% Styles
    class AddSprint,CurrSprint,SprintList,Calendar,Charts,Components,Hooks ui;
    class AuthAPI,ConfigAPI,ReportAPI,ReportDetailAPI,SprintAPI,SprintsAPI,SlackAPI api;
    class MongoService,Models biz;
    class MongoDB,Slack external;
    
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef biz fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;

    %% Click Events for Frontend/UI Layer - Pages and Layouts
    click AddSprint "https://github.com/michalwr88/stats-generator/blob/main/src/app/(WithNavBar)/add-sprint/page.tsx"
    click CurrSprint "https://github.com/michalwr88/stats-generator/blob/main/src/app/(WithNavBar)/current-sprint/page.tsx"
    click SprintList "https://github.com/michalwr88/stats-generator/blob/main/src/app/(WithNavBar)/sprint-list/page.tsx"
    click Calendar "https://github.com/michalwr88/stats-generator/blob/main/src/app/(WithNavBar)/calendar/page.tsx"
    click Charts "https://github.com/michalwr88/stats-generator/blob/main/src/app/(WithNavBar)/charts/page.tsx"

    %% Click Event for React Components
    click Components "https://github.com/michalwr88/stats-generator/tree/main/src/components"

    %% Click Events for Custom Hooks and Utilities
    click Hooks "https://github.com/michalwr88/stats-generator/tree/main/src/hooks"

    %% Click Events for API Layer
    click AuthAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click ConfigAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/mongo/config/route.tsx"
    click ReportAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/mongo/report/route.tsx"
    click ReportDetailAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/mongo/report/[id]/route.tsx"
    click SprintAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/mongo/sprint/route.tsx"
    click SprintsAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/mongo/sprints/route.tsx"
    click SlackAPI "https://github.com/michalwr88/stats-generator/blob/main/src/app/api/slack/route.tsx"

    %% Click Events for Business Logic & Data Access
    click MongoService "https://github.com/michalwr88/stats-generator/tree/main/src/mongoService"
    click Models "https://github.com/michalwr88/stats-generator/tree/main/src/models"
```
