How dector/lampa works
Project type and purpose
• Lampa is a Go-based command-line tool (open-source utility) for Android developers.
• Its primary purpose is to scan an Android/Gradle project’s third-party dependencies, produce JSON and HTML reports for a single build, and generate comparative HTML diffs between two releases.
File structure
• Top-level directories:
• cmd/cli – entrypoints and subcommands (collect, compare, doctor)
• internal – reusable application logic (Android locator, Git integration, parsers, report generation, templates, spinner/UI helper, utilities)
• pkg – protocol definitions and bundle-parsing logic (Gradle bundles, Protobuf schemas)
• docs, samples – usage docs and example reports
• Configuration/build files: go.mod, Taskfile.yml, .tool-versions
• CI/CD: GitHub workflows for build, test, release, renovate, snapshot, triage
Key insights from the README
• Three main CLI commands:
• collect: scan local project, emit JSON or HTML report
• compare: take two JSON snapshots, emit diff HTML
• doctor: diagnose environment issues
• Runtime external dependencies: Java (for invoking Gradle)
• Template-driven HTML generator (using Tailwind & Alpine in internal/assets)
Main components and their interactions
a. Components
1) CLI Layer (cmd/cli)
• Argument parsing (cobra or custom)
• Dispatch to subcommands: collect, compare, doctor
2) Project Locator & Loader (internal/android, internal/git)
• Locate Android project root, verify Git repo, fetch VCS metadata if needed
3) Build Metadata Extractor (pkg/gradle, pkg/bundles)
• Invoke Gradle (via Java) to produce dependency bundle metadata
• Parse AOSP Protobuf schemas to unify bundle model
4) Core Parsers (internal/parsers.go)
• Transform raw bundle data into the tool’s internal models
5) Report Generator (internal/report)
• Produce JSON report (models → JSON writer)
• Produce diff report (two JSON models → diffreport)
6) Template Engine (internal/templates + internal/assets)
• HTML templates for single and comparative views
• JS/CSS assets (Tailwind, Alpine) embedded via internal/assets.go
7) Output & Logging (internal/out, internal/spinner)
• Spinner/progress UI on stdout
• Log messages, write output files to disk
b. Relationships & Data Flow
• User invokes lampa <command> → CLI Layer parses args →
• For collect: call Project Locator → Build Metadata Extractor → Core Parsers → Report Generator → Template Engine (if HTML) → write files via Output module.
• For compare: load two JSON models from disk → Report Generator.diffreport → Template Engine → write diff HTML.
• doctor: run environment checks via Android Locator, Git, Java/Gradle detection → report to user.
c. Architectural patterns & principles
• Modular package structure (clear separation of cmd vs. internal vs. pkg)
• Single-responsibility packages: parsing, templating, reporting
• Template-driven UI layer for HTML, decoupled from core logic
• Embedding static assets in Go for single-binary distribution
d. Key technologies/frameworks
• Go standard library + cobra-style CLI
• Gradle invocation (via exec Java)
• Protobuf (AOSP schemas) for bundle definitions
• Go’s text/template or html/template for HTML generation
• Tailwind CSS & Alpine.js for HTML assets