# binarystudioacademy/bsa-2024-gitfit architecture

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

- Interactive diagram: https://gitdiagram.com/binarystudioacademy/bsa-2024-gitfit
- Repository: https://github.com/binarystudioacademy/bsa-2024-gitfit

## Overview

##### Project type and purpose
- This is a full-stack monorepo managed with npm workspaces.
- Frontend: React + Redux Toolkit SPA under apps/frontend
- Backend: Fastify REST API with TypeScript, Knex, Objection under apps/backend
- Shared package: TypeScript/Zod DTOs and helpers under packages/shared
- Analytics script: standalone Node CLI/cron job under scripts/analytics
- Purpose: collect Git commit data (activity logs), manage users/projects/groups/permissions, and display analytics

##### File structure
- Top level: apps/, packages/, scripts/, CI/CD configs (.github/), tooling
- apps/backend:
- db/migrations (PostgreSQL schema)
- src/libs: framework modules (config, http, logger, encryption, token, task-scheduler, server-app)
- src/modules: feature-by-feature (auth, users, projects, permissions, groups, project-groups, project-permissions, project-api-keys, contributors, git-emails, activity-logs, notifications, auth-analytics)
- Controller → Service → Repository → Model → Database flow
- apps/frontend:
- src/libs: shared React components, hooks, helpers, modules (api, config, http, storage, store, toast-notifier)
- src/modules: per-feature API clients + Redux slices
- src/pages: page compositions
- packages/shared: universal DTOs, Zod schemas, helpers used by both frontend and backend
- scripts/analytics: cron-based CLI that uses the shared API client to pull data from backend and generate reports

##### README for additional insights
- Technology stack: TypeScript, npm workspaces, React, Redux, Fastify, Knex, Objection, Zod
- Folder structure guidelines for frontend and backend

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        FrontendUI["React SPA (apps/frontend/src)"]:::ui
        Pages["Pages (Auth, Projects, Analytics, Access Management)"]:::ui
        ModulesFE["Feature Modules (API clients + Redux slices)"]:::ui
        LibsFE["Shared Components & Helpers"]:::ui
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIEntry["Fastify Server Entry Point"]:::api
        subgraph "Server Modules"
            direction TB
            ServerApp["Server Application Module"]:::api
            Controllers["Controllers (HTTP handlers per feature)"]:::api
            Services["Services (Business Logic)"]:::api
            Repositories["Repositories (DB Access)"]:::api
            Models["Models / Entities"]:::api
            Token["Token / Auth Module"]:::api
            BTaskScheduler["Task Scheduler Module"]:::api
        end
        Migrations["Database Migrations"]:::db
    end

    %% Shared Library
    Shared["Shared DTOs & Zod Schemas"]:::shared

    %% Database
    DB["PostgreSQL Database"]:::db

    %% Analytics Scheduler
    subgraph "Analytics Scheduler" 
        direction TB
        AnSched["Scheduler CLI & Cron Job"]:::sched
        subgraph "Scheduler Modules"
            direction TB
            AnAPI["HTTP Client Module"]:::sched
            AnSchedLib["Task Scheduler Module"]:::sched
            AnCLI["Analytics CLI Module"]:::sched
        end
    end

    %% CI/CD
    CI["CI/CD Workflows"]:::ci

    %% Connections
    FrontendUI -->|"uses Pages & Modules"| Pages
    Pages --> ModulesFE
    ModulesFE --> LibsFE
    FrontendUI -->|"HTTP REST/JSON"| APIEntry
    APIEntry --> ServerApp
    ServerApp --> Controllers
    Controllers --> Services
    Services --> Repositories
    Repositories --> Models
    Models --> DB
    APIEntry --> Migrations
    Controllers -->|"SQL queries via Repos"| DB
    AnSched -->|"HTTP REST/JSON (cron trigger)"| APIEntry
    Shared --> FrontendUI
    Shared --> ServerApp
    CI -.-> FrontendUI
    CI -.-> APIEntry
    CI -.-> AnSched

    %% Click Events
    click FrontendUI "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/frontend/src"
    click Pages "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/frontend/src/pages"
    click ModulesFE "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/frontend/src/modules"
    click LibsFE "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/frontend/src/libs"
    click APIEntry "https://github.com/binarystudioacademy/bsa-2024-gitfit/blob/main/apps/backend/src/index.ts"
    click ServerApp "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/libs/modules/server-application"
    click Controllers "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/modules"
    click Services "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/modules"
    click Repositories "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/modules"
    click Models "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/modules"
    click Token "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/libs/modules/token"
    click BTaskScheduler "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/libs/modules/task-scheduler"
    click Migrations "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/apps/backend/src/db/migrations"
    click Shared "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/packages/shared/src"
    click AnSched "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/scripts/analytics/src"
    click AnAPI "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/scripts/analytics/src/libs/modules/api"
    click AnSchedLib "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/scripts/analytics/src/libs/modules/task-scheduler"
    click AnCLI "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/scripts/analytics/src/libs/modules/analytics-cli"
    click CI "https://github.com/binarystudioacademy/bsa-2024-gitfit/tree/main/.github/workflows"

    %% Styles
    classDef ui fill:#CFE2FF,stroke:#0366d6,color:#000;
    classDef api fill:#D9EAD3,stroke:#2e7d32,color:#000;
    classDef db fill:#F9CB9C,stroke:#a35400,color:#000;
    classDef sched fill:#FFF2CC,stroke:#b8860b,color:#000;
    classDef shared fill:#E7E6E6,stroke:#6a6a6a,color:#000;
    classDef ci fill:#F4CCCC,stroke:#d32f2f,color:#000;
```
