How pl1000100/gitstats works
Project type and purpose
• From the README and file tree, this is a full‑stack web application called “Gitstats.”
• It consists of a static frontend (index.html) served via its own Docker container and a Go‑based backend API that fetches repository stats from GitHub and codetabs.
File structure
Top‑level:
• docker-compose.yml – orchestrates two services: frontend and backend
• frontend/
– Dockerfile, index.html
• backend/
– Dockerfile, main.go, go.mod, go.sum
– internal/github (handles GitHub API calls)
– internal/count_loc (processes code‐loc statistics via codetabs)
– utils (CORS, JSON helpers)
Supporting files:
• .gitignore
• README.md
• img/ (screenshots)
Extract architectural insights from the README
• There are three API endpoints under /api/v1:
1. GET /repositories/{user} → retrieves list of repos via GitHub API
2. GET /stats/{user}/{repo} → retrieves LOC stats via codetabs API
3. GET /stats/{user} → aggregates stats for all repos (rate‑limited)
• The backend relies on an environment variable GITHUB_ACCESS_TOKEN.
• The frontend is a single HTML page (likely with JS) that calls these endpoints.
Main components and their interactions
a. Frontend Service
• Hosts index.html and any client‑side JS/CSS.
• Sends HTTP requests to the backend API.
b. Backend Service
• Exposes REST endpoints (/api/v1/…).
• Routes requests into two internal modules:
– github package: calls GitHub API to list repositories
– count_loc package: calls codetabs API to gather LOC stats
• Uses utils/cors.go to allow cross‑origin requests from the frontend.
• Uses utils/json.go to serialize/deserialize JSON payloads.
c. External Services
• GitHub REST API (requires GITHUB_ACCESS_TOKEN)
• codetabs API (rate limited)
d. Orchestration
• docker-compose sets up two containers (frontend & backend) on the same Docker network.
• .env supplies the GitHub token to the backend container.
Architectural patterns and design principles
• Separation of concerns:
• Frontend UI vs. Backend API vs. External data providers.
• Within the backend: clearly divided packages for external integrations and utilities.
• Stateless microservice: no database, calls external APIs on demand.
• Single‑page or static‑serve model for the UI.
• Dependency injection via environment variables (.env) in Docker Compose.
Final checklist
• [ ] Each component clearly labeled
• [ ] Call out Docker Compose orchestration and .env dependency
• [ ] Note key internal packages and their responsibilities