# ishaannene/elitecode-brew architecture

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

- Interactive diagram: https://gitdiagram.com/ishaannene/elitecode-brew
- Repository: https://github.com/ishaannene/elitecode-brew

## Overview

##### Project Type and Purpose
- This is a Go-based command-line interface (CLI) tool called “Elitecode CLI” built with Cobra.
- It implements commands for user authentication, problem management, solution submission, and stats by calling out to external backend services (Firebase Firestore via Firebase SDK and GitHub).
- It also has support for local Firebase emulators (via Docker) and stores user configuration in a local JSON file.

##### File Structure Analysis
- cmd/ – entry points for each CLI command (login, logout, problems, submit, run, push, etc.), all hooked into Cobra’s root command (root.go).
- internal/
- auth/ – token management, session handling.
- config/ – load and watch ~/.elitecode/config.json, handle environment overrides.
- firebase/ – wrapper over Firebase SDK for Firestore operations.
- github/ – wrapper over GitHub API for OAuth and repo operations.
- docker/ – client to launch/connect to Firebase emulator (Docker).
- models/ – domain types (Problem, Submission, Ranking).
- problem/ – business logic (fetching problems, setting up, submissions).
- utils/ – helpers (language detection, CLI helpers).
- main.go initializes configuration, sets up clients, and executes the root Cobra command.
- Config files: .firebaserc, firebase.json, firestore.rules/indexes, Dockerfile, docker-compose.yml for emulator setup.

##### README Insights
- Uses Go 1.21+, Docker, Firebase emulators for development, environment variables to override config.
- Highlights Cobra for CLI framework, Firebase for backend, Docker for container runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["Cobra CLI Commands\n(cmd/)"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        Main["Main (main.go)"]:::application
        ConfigReader["Config Reader\n(internal/config/)"]:::application
        Auth["Auth Module\n(internal/auth/auth.go)"]:::application
        ProblemService["Problem Service\n(internal/problem/service.go)"]:::application
        SubmissionLogic["Submission Logic\n(internal/problem/submission.go)"]:::application
        ModelsProblem["Problem Model\n(internal/models/problem.go)"]:::application
        ModelsSubmission["Submission Model\n(internal/models/submission.go)"]:::application
        ModelsRanking["Ranking Model\n(internal/models/ranking.go)"]:::application
        Utils["Utils Helpers\n(internal/utils/language.go)"]:::application
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        FirebaseClient["Firebase Client\n(internal/firebase/)"]:::infrastructure
        GithubClient["GitHub Client\n(internal/github/client.go)"]:::infrastructure
        DockerClient["Docker Client\n(internal/docker/client.go)"]:::infrastructure
    end

    %% External Systems
    subgraph "External Systems"
        Firestore["Firebase Firestore\n(Database)"]:::external
        GitHubAPI["GitHub API"]:::external
        LocalFS["Local FS\n(~/.elitecode/config.json)"]:::external
        Emulator["Firebase Emulator\n(Docker)"]:::external
    end

    %% Data Flows
    User["User"]:::external -->|uses| CLI
    CLI -->|invokes| ProblemService
    CLI -->|auth commands| Auth
    CLI -->|loads config| ConfigReader
    CLI -->|uses utils| Utils

    ProblemService -->|uses| SubmissionLogic
    ProblemService -->|reads models| ModelsProblem
    SubmissionLogic -->|reads models| ModelsSubmission
    SubmissionLogic -->|reads models| ModelsRanking
    SubmissionLogic -->|uses| FirebaseClient
    SubmissionLogic -->|uses| GithubClient

    Auth -->|auth data| FirebaseClient

    ConfigReader -->|provides config| CLI
    ConfigReader -->|provides config| FirebaseClient
    ConfigReader -->|provides config| GithubClient
    ConfigReader -->|provides config| DockerClient
    ConfigReader -->|writes config| LocalFS

    Main -->|wires| ConfigReader
    Main -->|wires| Auth
    Main -->|wires| FirebaseClient
    Main -->|wires| GithubClient
    Main -->|wires| DockerClient
    Main -->|executes| CLI

    FirebaseClient -->|reads/writes| Firestore
    GithubClient -->|calls| GitHubAPI
    DockerClient -->|manages| Emulator

    %% Click Events
    click CLI "https://github.com/ishaannene/elitecode-brew/tree/main/cmd/"
    click Main "https://github.com/ishaannene/elitecode-brew/blob/main/main.go"
    click Auth "https://github.com/ishaannene/elitecode-brew/blob/main/internal/auth/auth.go"
    click ConfigReader "https://github.com/ishaannene/elitecode-brew/tree/main/internal/config/"
    click FirebaseClient "https://github.com/ishaannene/elitecode-brew/blob/main/internal/firebase/client.go"
    click GithubClient "https://github.com/ishaannene/elitecode-brew/blob/main/internal/github/client.go"
    click DockerClient "https://github.com/ishaannene/elitecode-brew/blob/main/internal/docker/client.go"
    click ProblemService "https://github.com/ishaannene/elitecode-brew/blob/main/internal/problem/service.go"
    click SubmissionLogic "https://github.com/ishaannene/elitecode-brew/blob/main/internal/problem/submission.go"
    click ModelsProblem "https://github.com/ishaannene/elitecode-brew/blob/main/internal/models/problem.go"
    click ModelsSubmission "https://github.com/ishaannene/elitecode-brew/blob/main/internal/models/submission.go"
    click ModelsRanking "https://github.com/ishaannene/elitecode-brew/blob/main/internal/models/ranking.go"
    click Utils "https://github.com/ishaannene/elitecode-brew/blob/main/internal/utils/language.go"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#004085
    classDef application fill:#d4edda,stroke:#155724
    classDef infrastructure fill:#fff3cd,stroke:#856404
    classDef external fill:#f8d7da,stroke:#721c24
```
