# sarojgrs/github-repository-viewer-assignment-backend architecture

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

- Interactive diagram: https://gitdiagram.com/sarojgrs/github-repository-viewer-assignment-backend
- Repository: https://github.com/sarojgrs/github-repository-viewer-assignment-backend

## Overview

##### Project type and purpose
- This is a backend‐only Node.js service written in TypeScript.
- It exposes HTTP endpoints on port 8080 to fetch GitHub user and repository data, using a personal access token.

##### File structure
- index.ts: application entry point, spins up an Express server.
- routes/githubRoutes.ts: defines HTTP routes and controllers.
- apiLibrary/apiLibrary.ts: service layer that makes outbound calls to the GitHub REST API.
- config/config.ts: loads environment variables (e.g. GITHUB_PERSONAL_ACCESS_TOKEN).
- modal/IUserModal.ts and modal/IRepoModal.ts: TypeScript interfaces for GitHub JSON responses.
- constants/repositoryType.ts: any enums or constant definitions.
- customError/customError.ts: central place for custom error classes and error handling logic.
- Supporting files: tsconfig.json, nodemon.json, package.json.

##### README for additional insights
- Startup sequence: yarn install → add .env → yarn build → yarn start.
- Service binds to http://localhost:8080.
- No frontend—pure API service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    HTTPClient["HTTP Client"]:::external

    %% Backend Service Group
    subgraph "Backend Service"
        ExpressServer["Express Server\n(index.ts)"]:::internal
        RouterController["Router & Controller\n(githubRoutes.ts)"]:::internal
        ServiceLayer["Service Layer / API Library\n(apiLibrary.ts)"]:::internal
        UserModel["IUserModal\n(IUserModal.ts)"]:::internal
        RepoModel["IRepoModal\n(IRepoModal.ts)"]:::internal
        ConstantsModule["Constants Module\n(repositoryType.ts)"]:::internal
        ConfigModule["Configuration Module\n(config/config.ts)"]:::crosscut
        CustomErrorModule["Custom Error Module\n(customError/customError.ts)"]:::crosscut
    end

    %% External GitHub API
    GitHubAPI["GitHub REST API"]:::external

    %% Request/Response Flow
    HTTPClient -->|"HTTP Request"| ExpressServer
    ExpressServer -->|"routes request"| RouterController
    RouterController -->|"invoke service methods"| ServiceLayer
    ServiceLayer -->|"load token"| ConfigModule
    ServiceLayer -->|"API Call with Auth"| GitHubAPI
    GitHubAPI -->|"JSON Response"| ServiceLayer
    ServiceLayer -->|"cast to IUserModal"| UserModel
    ServiceLayer -->|"cast to IRepoModal"| RepoModel
    ServiceLayer -->|"return typed data"| RouterController
    RouterController -->|"send JSON response"| ExpressServer
    ExpressServer -->|"HTTP Response"| HTTPClient

    %% Error Handling Flow
    ServiceLayer -.->|"errors"| CustomErrorModule
    RouterController -.->|"errors"| CustomErrorModule

    %% Click Events
    click ExpressServer "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/index.ts"
    click RouterController "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/routes/githubRoutes.ts"
    click ServiceLayer "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/apiLibrary/apiLibrary.ts"
    click ConfigModule "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/config/config.ts"
    click UserModel "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/modal/IUserModal.ts"
    click RepoModel "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/modal/IRepoModal.ts"
    click ConstantsModule "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/constants/repositoryType.ts"
    click CustomErrorModule "https://github.com/sarojgrs/github-repository-viewer-assignment-backend/blob/main/customError/customError.ts"

    %% Styles
    classDef internal fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef external fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef crosscut fill:#ffffe0,stroke:#000,stroke-width:1px;
```
