Metadata-Version: 2.4
Name: file-analyzer
Version: 1.0.0
Summary: Repository intelligence platform: turns a source tree into a queryable SQLite/PostgreSQL database of code, schemas, data, archives, binaries and docs -- without executing it -- plus a live background monitor, an MCP agent-enrichment tier, and a document-intelligence engine.
Author: Rohan Pratap Reddy Ravula
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or Derivative
                  Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work, excluding
                  those notices that do not pertain to any part of the Derivative
                  Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and do
                  not modify the License. You may add Your own attribution notices
                  within Derivative Works that You distribute, alongside or as an
                  addendum to the NOTICE text from the Work, provided that such
                  additional attribution notices cannot be construed as modifying
                  the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright 2026 Rohan Pratap Reddy Ravula
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/RohanPratapReddy/file-analyzer
Project-URL: Repository, https://github.com/RohanPratapReddy/file-analyzer
Keywords: static-analysis,code-intelligence,repository,sqlite,mcp,ai-agent,repository-monitor,incremental-analysis,document-intelligence
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Provides-Extra: agent
Requires-Dist: mcp[cli]<2,>=1.2; extra == "agent"
Provides-Extra: monitor-postgres
Requires-Dist: psycopg[binary]>=3.1; extra == "monitor-postgres"
Provides-Extra: monitor-mysql
Requires-Dist: PyMySQL>=1.1; extra == "monitor-mysql"
Provides-Extra: parse
Requires-Dist: pdfplumber; extra == "parse"
Requires-Dist: pdfminer.six; extra == "parse"
Requires-Dist: pikepdf; extra == "parse"
Requires-Dist: python-docx; extra == "parse"
Requires-Dist: oletools; extra == "parse"
Provides-Extra: ocr
Requires-Dist: scikit-image; extra == "ocr"
Requires-Dist: pytesseract; extra == "ocr"
Provides-Extra: pii
Requires-Dist: phonenumbers; extra == "pii"
Requires-Dist: python-stdnum; extra == "pii"
Requires-Dist: presidio-analyzer; extra == "pii"
Requires-Dist: spacy; extra == "pii"
Requires-Dist: textstat; extra == "pii"
Provides-Extra: eval
Requires-Dist: jiwer; extra == "eval"
Requires-Dist: sacrebleu; extra == "eval"
Requires-Dist: nltk; extra == "eval"
Requires-Dist: lxml; extra == "eval"
Requires-Dist: zss; extra == "eval"
Requires-Dist: scikit-learn; extra == "eval"
Requires-Dist: jsonschema; extra == "eval"
Requires-Dist: tiktoken; extra == "eval"
Requires-Dist: ragas; extra == "eval"
Requires-Dist: deepeval; extra == "eval"
Provides-Extra: document
Requires-Dist: file-analyzer[eval,ocr,parse,pii]; extra == "document"
Dynamic: license-file

# file-analyzer

**Point it at a repository, get back a queryable database of everything in it.**

`file-analyzer` is a **repository intelligence platform**. Its core walks a source
tree — code, schemas, data files, archives, binaries, configs, docs — **without ever
executing it**, and emits a single **SQLite** (or **PostgreSQL**) database describing
what it found: files and folders, per-language symbols (classes, functions, imports
and the links between them), database schemas (tables, columns, keys, constraints,
triggers), data-artifact profiles (datasets, columns, tensors, correlations), and
more. A layer of ready-made **analysis views** (`v_*`) sits on top so you can answer
questions with plain `SELECT`s, and two independent **concurrent readers** (Go and
Java) demonstrate strictly read-only access to those views.

On top of that static core it adds **live and agentic layers**:

- a **background monitor** that watches a repository and re-analyzes changed files
  incrementally across a Go/Python worker pool, with a FIFO diff DB and a durable
  change log ([docs/monitor.md](docs/monitor.md));
- an optional **MCP agent tier** that enriches each file (summaries, quality /
  security findings, symbol docs) alongside the deterministic metrics;
- a **document-intelligence engine** (DocumentParser) combining static metrics with
  a dynamic agent/code loop and a full evaluation stack
  ([docs/document-engine-agents.md](docs/document-engine-agents.md));
- a **unified database** that merges every per-source layer into one queryable `.db`
  + `.sql`.

It never executes the code it analyzes, never modifies the source tree, never stores
raw file payloads, and degrades honestly — when a format can only be partially
understood, it records what it could determine and marks the rest, rather than
fabricating results.

> **🔒 IP-safe by design.** It stores **metadata, structure and statistics — never
> file payloads**, and never dumps verbatim strings out of binaries. The little
> free text it does keep (header fields, config/DB values, sample cells, document
> previews, monitor diffs) is scrubbed of **secrets and PII** at a single choke
> point (`file_analyzer.core.guardrails`) before storage. It is a defensive tool,
> not a secret-harvesting or copyright-lifting one. See the acceptable-use policy:
> **[ACCEPTABLE_USE.md](ACCEPTABLE_USE.md)** (`python -m file_analyzer.main --acceptable-use`).

> **⚠️ Runs in a container or VM only.** The CLI entrypoints (`file-analyzer` /
> `python -m file_analyzer.main` and the monitor `file-analyzer-monitor` / `python -m file_analyzer`)
> **refuse to run directly on bare-metal host hardware** — they start only inside a
> container (Docker/Podman/containerd/LXC/Kubernetes) or a virtual machine, exiting
> with code **3** otherwise. Use the Docker workflow below (recommended), or set
> `FILE_ANALYZER_ALLOW_BARE_METAL=1` to opt out on an already-isolated box. The MCP
> server is unaffected. Full details: **[docs/runtime-containment.md](docs/runtime-containment.md)**.

## What it produces

Running the engine over a repository yields two artifacts (both carry the `v_*`
views):

- `repository.db` — a binary SQLite database, opened in place, read-only.
- `repository_schema.sql` — a portable text dump (SQLite or PostgreSQL dialect).

## Quick start

The engine must run inside a container or VM (see the note above). The one-line
Docker recipe below satisfies that automatically. To run the Python CLI directly,
do it inside a VM/container, or export `FILE_ANALYZER_ALLOW_BARE_METAL=1` first:

```bash
pip install -r requirements.txt

# Analyze a repository (the source must be a git repo, or pass --no-git).
python -m file_analyzer.main /path/to/repo --out ./artifacts

# Postgres-loadable dump instead of SQLite:
python -m file_analyzer.main /path/to/repo --out ./artifacts --dialect postgresql

# All flags (works on any host — --help is exempt from the containment guard):
python -m file_analyzer.main --help
```

Flags: `--out`, `--db`, `--sql`, `--dialect {sqlite,postgresql}`, `--temp`
(staging dir; defaults under `--out`, so a read-only source still analyzes),
`--workers`, `--no-archives`, `--no-git`, `--keep-temp`, `--quiet` (stdout carries
only the final JSON — for pipes/agents). Prints a JSON summary on success.

### Install as a command

`pip`/`pipx`-install to get a `file-analyzer` command invocable from any directory
(no `python -m`, no specific cwd):

```bash
pipx install .            # or: pip install .
file-analyzer /path/to/repo --out ./artifacts --quiet
file-analyzer-mcp         # start the MCP server (extras: pip install ".[agent]")
```

### Or one-line Docker (no local Python)

The Dockerfile's `engine` stage runs the analyzer over a repo mounted at
`/workspace` and writes artifacts to `/artifacts`:

```bash
docker build --target engine -t file-analyzer .
docker run --rm -v "$PWD:/workspace:ro" -v "$PWD/artifacts:/artifacts" \
  file-analyzer /workspace --out /artifacts --quiet
```

Then query the result:

```bash
sqlite3 ./artifacts/repository.db "SELECT * FROM v_extension_distribution;"
```

## Use with AI agents (MCP)

`file-analyzer` ships an [MCP](https://modelcontextprotocol.io) server so agents
(Claude Code/Desktop, opencode, Cursor, Cline, Windsurf, …) can drive the engine.
The intended loop is **analyze once, then ask questions with SQL** over the `v_*`
views — the agent writes ordinary `SELECT`s instead of parsing walls of text.

```bash
pip install -r requirements-agent.txt      # the MCP SDK
python -m mcp_server                        # stdio transport (or: file-analyzer-mcp)

# register with Claude Code (other agents take the same command in their config):
claude mcp add file-analyzer -- python -m mcp_server
```

Tools: `analyze_repository`, `query`, `list_views`, `read_views`,
`describe_schema`, `run_component`, `list_components`. `query` is read-only
(`mode=ro` + `PRAGMA query_only`, single `SELECT`/`WITH` only); `read_views`
bulk-reads many `v_*` views at once, splitting them across the native Go and Java
readers concurrently (with a concurrent pure-Python fallback).

Not using MCP? The CLI is agent-friendly too: pass **`--quiet`** so stdout carries
only the final JSON (progress goes to stderr), and see **[`AGENTS.md`](AGENTS.md)**
for the driving guide and **[`tools.json`](tools.json)** for function-calling
(Grok/DeepSeek/OpenAI-style) tool definitions.

## Using the pipeline as a library

Import the public classes from the `file_analyzer` package (run from the repo root so `file_analyzer`
is importable):

```python
from file_analyzer import (RepositoryAnalyzer, PolyglotCodeAnalyzer, ImportLinkageAnalyzer,
                 SchemaAnalyzer, DataAnalyzer, RepositoryDatabaseGenerator,
                 AnalysisEngine)

engine = AnalysisEngine()
summary = engine.run("/path/to/repo", out_dir="./artifacts")
```

### Package layout

| package                | role                                                                      |
|------------------------|---------------------------------------------------------------------------|
| `file_analyzer/core/`            | orchestration glue — `analysis_engine`, `repository_analyzer`, `import_linkage`, `db_generator` (re-exported at the package top level). |
| `file_analyzer/prog_lang/`       | per-language source analyzers (classes, functions, imports, symbols).     |
| `file_analyzer/schema/`          | SQL DDL / IDL schema analyzers → `schema_*` tables.                        |
| `file_analyzer/data/`            | data-artifact profiler (metadata / stats / sampling only) → `data_*` tables. |
| `file_analyzer/database/`        | database-file analyzers (merges schema + data for DB formats).            |
| `file_analyzer/archive/`         | archive traversal (nested, bounded depth).                                |
| `file_analyzer/binary/`          | machine-code and binary-format analyzers.                                 |
| `file_analyzer/config/`, `file_analyzer/text/`, `file_analyzer/markup/`, `file_analyzer/document/`, `file_analyzer/script/`, `file_analyzer/shell/`, `file_analyzer/misc/` | format-family analyzers for the long tail of file types. |
| `file_analyzer/convert/`         | opaque → renderable format conversion helpers.                            |
| `file_analyzer/router/`          | pure-Python routing / staging that dispatches files to analyzers.         |
| `file_analyzer/views/`           | the views + reads layer (single source of truth — see below).             |
| `file_analyzer/tables/` | canonical reference tables — the extension catalog (`file_extensions.json`) and the IANA timezone tables (`iana_local_timezones.json`, `iana_global_timezones.json`). |

## The views layer (`file_analyzer/views`)

The analysis views are defined **once**, in Python, and installed into every
database the engine produces (and mirrored into the `.sql` dump). The Go and Java
readers embed no query SQL — they **discover** the installed `VIEW` objects from
the database catalog. Add or change a view in
[`file_analyzer/views/catalog.py`](file_analyzer/views/catalog.py) and every reader, plus the
Postgres/Docker backend, picks it up with no code changes.

| module        | role                                                                       |
|---------------|----------------------------------------------------------------------------|
| `catalog.py`  | the view catalog: `VIEW_CATALOG` of `ViewDef(name, tables, select)`; DB object names are `v_<name>`. |
| `builder.py`  | turns the catalog into real objects: `install_views_sqlite(db)`, `append_views_to_sql_dump(sql)`, `views_ddl(dialect)`, `write_sql_artifacts(dir)`. |
| `reader.py`   | Python reads over the installed views: `list_views`, `read_view`, `read_all_views`. |
| `native_reader.py` | concurrent bulk reads: `read_views_native` splits the views across the Go (`go/`) and Java (`java/`) readers and runs them at the same wall-clock time; `read_views_python` is the toolchain-free concurrent fallback. |
| `__main__.py` | CLI (`python -m file_analyzer.views …`).                                             |
| `sql/`        | generated artifacts: `views.sqlite.sql`, `views.pgsql.sql`, `catalog.json`. |
| `go/`, `java/` | native concurrent view readers (`-json` mode) that `native_reader.py` builds on demand. |
| `go/`, `java/`| the Go + Java reader programs (below).                                     |

A view is created only when **all of its base tables are present**, so a database
lacking the `schema_*` / `data_*` families simply never gets (and never errors on)
those views. This gives readers a clean contract: *a view exists in the DB ⟺ its
base tables exist*, so they can enumerate `type='view'` and `SELECT *` with zero
skip-logic. Installation is **additive, idempotent, and the only write**: it creates
read-only `VIEW` objects over existing tables and never touches table data.

```bash
python -m file_analyzer.views install   repository.db
python -m file_analyzer.views dump      repository_schema.sql
python -m file_analyzer.views list      repository.db
python -m file_analyzer.views read      repository.db --view v_extension_distribution
python -m file_analyzer.views artifacts file_analyzer/views/sql       # (re)generate sql/ artifacts
```

### View catalog — 33 views over the `v_` prefix

- **core (10):** `file_inventory`, `extension_distribution`, `folder_tree_depth`,
  `import_internal_vs_external`, `import_edges`, `top_classes_by_methods`,
  `functions_defined_vs_imported`, `symbols_by_kind`, `introspection_by_language`,
  `tensor_members_by_kind`.
- **schema (12):** `schema_databases_by_engine`, `schema_tables_by_engine`,
  `schema_tables_by_kind`, `schema_top_column_types`, `schema_keys_by_type`,
  `schema_foreign_key_edges`, `schema_constraints_by_type`,
  `schema_triggers_by_timing`, `schema_methods_by_language`,
  `schema_types_by_category`, `schema_top_indexed_tables`,
  `schema_entities_per_file`.
- **data (11):** `data_datasets_by_modality`, `data_datasets_by_category`,
  `data_datasets_by_format`, `data_analysis_status`, `data_largest_tabular`,
  `data_columns_by_inferred_type`, `data_top_correlations`,
  `data_tensors_by_dtype`, `data_largest_tensors`, `data_properties_by_group`,
  `data_entities_per_file`.

## The concurrent readers (Go + Java)

Two independent programs — one **Go**, one **Java** — open the artifact and read
every discovered view across a pool of workers, concurrently and **strictly
read-only**. They are functionally equivalent: same discovered views, same read-only
guarantees, same CLI flags.

### Read-only guarantees

Zero writes, zero changes, zero commits by the workers. Enforced in layers:

1. **Open mode** — the database is opened `mode=ro` (`SQLITE_OPEN_READONLY`).
2. **Engine pragma** — every pooled connection sets `PRAGMA query_only = true`.
3. **Start-up canary** — before any worker starts, the program attempts a write
   (`CREATE TABLE __readonly_canary__`) and *requires it to fail*. If the write
   ever succeeds, the program aborts. You'll see `read-only : verified (write
   canary rejected)` on success.
4. **Query-only code paths** — workers only ever call the read API (`db.Query*` in
   Go, `Statement.executeQuery` in Java). No `Exec`/`executeUpdate`, no
   transactions, no commits.

Each reader accepts either the `.db`/`.sqlite` (opened in place, read-only) or the
`.sql` dump (loaded **once** into a private temp snapshot the workers then read;
the original file is never modified and the temp file is deleted on exit).

### CLI (identical for both readers)

| flag        | default        | meaning                                            |
|-------------|----------------|----------------------------------------------------|
| `-source`   | `repository.db`| path to the `.db` or `.sql` produced by the engine |
| `-workers`  | CPU count      | number of concurrent workers (goroutines / threads)|
| `-repeat`   | `1`            | replay the whole view set N times for sustained load|
| `-verbose`  | off            | print every result body (default: once per view)   |

### Go

Pure-Go SQLite driver (`modernc.org/sqlite`) — no cgo / no gcc needed.

```bash
cd file_analyzer/views/go
go mod tidy          # fetches modernc.org/sqlite
go build -o repo-reader .
# repository.db lives four levels up (repo root), from file_analyzer/views/go:
./repo-reader -source ../../../repository.db -workers 6 -repeat 2
./repo-reader -source ../../../repository_schema.sql -workers 4
```

### Java (JDK 17+)

Needs the SQLite JDBC driver (`org.xerial:sqlite-jdbc`) and its runtime dependency
`org.slf4j:slf4j-api` — both jars ship alongside the source in `file_analyzer/views/java`.

```bash
cd file_analyzer/views/java
javac -cp "sqlite-jdbc-3.45.3.0.jar" RepositoryReader.java
# Windows classpath separator is ';', Unix is ':'
java -cp ".;sqlite-jdbc-3.45.3.0.jar;slf4j-api-2.0.13.jar" RepositoryReader -source ../../../repository.db -workers 6 -repeat 2   # Windows
java -cp ".:sqlite-jdbc-3.45.3.0.jar:slf4j-api-2.0.13.jar" RepositoryReader -source ../../../repository.db -workers 6 -repeat 2   # Unix
```

> sqlite-jdbc 3.45.x prints a one-line `SLF4J: No providers were found` notice and
> defaults to a no-op logger — harmless. Add `slf4j-nop` to silence it.

## Docker — Postgres backend + frontend + views

`docker-compose.yml` (the default compose file, so no `-f` needed) brings up
Postgres, a one-shot `loader`, and pgAdmin, loading every artifact the engine
produced (see the compose file header for usage).

An **optional containerized engine** (compose `engine` profile, Dockerfile `engine`
stage) *produces* those artifacts by running `python -m file_analyzer.main` against a mounted
source repository — so the whole flow can run in containers:

```bash
# 1. produce artifacts from a source repo into ./artifacts
SOURCE_DIR=/path/to/repo ARTIFACTS_DIR=./artifacts \
  docker compose --profile engine run --build engine

# 2. bring up Postgres + loader to ingest ./artifacts
ARTIFACTS_DIR=./artifacts docker compose up --build
```

The `engine` service runs `python -m file_analyzer.main` and accepts **any** of its
arguments. Pass them as one `ENGINE_ARGS` string (shell-split and appended to the
entrypoint), or inline after the service name:

```bash
# via ENGINE_ARGS (overrides the default command):
SOURCE_DIR=/path/to/repo \
  ENGINE_ARGS="/workspace --out /artifacts --dialect postgresql --no-git --workers 8" \
  docker compose --profile engine run --build engine

# or inline (replaces the command for that run):
docker compose --profile engine run --build engine \
  /workspace --out /artifacts --dialect postgresql

# see every flag:
docker compose --profile engine run --build engine --help
```

The views are wired in two ways:

- **`.sql` dumps** (postgresql dialect) already contain the appended
  `CREATE OR REPLACE VIEW` statements, so `psql` creates them on load.
- **`.db` artifacts** go through `pgloader`, which copies *tables only*; the loader
  then applies [`file_analyzer/views/sql/views.pgsql.sql`](file_analyzer/views/sql/views.pgsql.sql)
  (bind-mounted in) to (re)create the views per database. Views over absent tables
  are skipped, matching the SQLite-side contract.

An **optional containerized Go reader** (compose `reader` profile) runs the same
view-reading worker against a mounted artifact:

```bash
docker compose --profile reader run --build reader
# point at another artifact / tune workers:
docker compose --profile reader run --build reader -source /artifacts/some_archive.db -workers 8
```

## License

Licensed under the Apache License, Version 2.0 — see [LICENSE](LICENSE). The
bundled `sqlite-jdbc` (Apache-2.0) and `slf4j-api` (MIT) jars under
`file_analyzer/views/java/` are redistributed under their own licenses; see [NOTICE](NOTICE)
for attribution.
