# toddwschneider/sec-13f-filings architecture

> Architecture diagram of the GitHub repository toddwschneider/sec-13f-filings, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/toddwschneider/sec-13f-filings
- Repository: https://github.com/toddwschneider/sec-13f-filings

## Overview

1. This is a Rails 6-style monolith built around a single domain: SEC Form 13F filings. The app has two major responsibilities: ingesting raw filing data from the SEC, then serving a public site that lets users browse, compare, and aggregate the processed holdings.

2. The external data boundary is the SEC EDGAR system. `app/lib/sec_client.rb` is the integration point, and the app explicitly requires a `SEC_USER_AGENT` environment variable because SEC requests need an identifying user agent. The SEC is the only material upstream service.

3. Persistence is centered on PostgreSQL. The core tables are `thirteen_fs` for one row per filing, `holdings` for individual info-table rows, and `aggregate_holdings` for a denormalized/aggregated version used to make queries faster. Supporting tables and views provide canonical names, filer metadata, CUSIP history, and symbol mappings.

4. The ingestion pipeline is split into discovery and processing. `ThirteenF.import_filings!` creates placeholder filing records for a quarter, then each filing’s `process!` step downloads the primary XML and info-table XML, stores the raw documents on the filing record, and expands them into holdings rows. This is the main dataflow from SEC XML into normalized relational data.

5. There are two import entry points for ops and development. `app/lib/minimal_db_seeder.rb` seeds a small useful subset of managers and quarters, while `lib/tasks/import_filings.rake` provides broader import tasks, including an “import all quarters” path. The README also describes calling the import/process methods directly from the Rails console.

6. Background processing is handled with Delayed Job, not an external queue service. The schema includes a `delayed_jobs` table, and the repo has `Procfile`, `Procfile.clockandworker`, `clock.rb`, and a `bin/delayed_job` entry to keep imports moving. The “clock” process schedules new work; workers execute filing processing jobs.

7. The public application layer is organized by resource-oriented controllers: `HomeController` for the landing page, `ThirteenFsController` for filing and holdings views, and `ManagersController` for manager-centric pages. There is no authentication layer, which matters architecturally because the site can rely on public caching and does not need session-based access control.

8. A separate data-serving boundary exists for tables and search UI. `DataController` and `app/lib/data_table_formatter.rb` work together to feed DataTables-style AJAX responses, likely for server-side sorting/filtering/pagination. This keeps heavy tabular views fast without rendering all rows in HTML.

9. The presentation layer is standard Rails views with a strong client-side table stack. Pages live under `app/views/thirteen_fs`, `app/views/managers`, and `app/views/home`. Front-end assets are built with Webpacker, Tailwind CSS, and DataTables, with some custom JavaScript for autocomplete and table behavior.

10. The domain model is explicitly split between raw filings and derived analytics. `ThirteenF` and `Holding` represent the original report structure, while `AggregateHolding` and the view-backed lookup models support higher-level browsing such as “all holders of a CUSIP” or “manager history for a security.” That separation is important for diagramming because most user-facing pages read from derived data, not from raw XML.

11. Database views are part of the architecture, not just a convenience. The repo includes SQL definitions in `db/views/` for canonicalizing filers and CUSIPs. These views support stable naming across messy SEC data and help power the browse/search experience.

12. The app’s runtime/deployment shape is Heroku-like. `Procfile` supports separate web, worker, and clock processes; Rails uses Puma; assets are compiled with Webpack; and the app is designed to run with PostgreSQL plus Node/Yarn in development. There is also an Action Cable scaffold, but it is not a core subsystem in the current architecture.

13. Operationally, the data model is append-heavy and processing-intensive. The system expects large quarterly batches, SEC rate limits, and long-running backfills, so ingestion is asynchronous and incremental. That design choice is central: the app is optimized more like a data pipeline plus read-optimized public site than like a typical CRUD application.

Main entry points: [`app/controllers/thirteen_fs_controller.rb`](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/thirteen_fs_controller.rb) (13F views), [`app/models/thirteen_f.rb`](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/thirteen_f.rb) (13F filings), [`config/puma.rb`](https://github.com/toddwschneider/sec-13f-filings/blob/main/config/puma.rb) (Web process), [`app/controllers/managers_controller.rb`](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/managers_controller.rb) (Managers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_ingestion["Ingestion"]
  node_sec_client["SEC client<br/>external API<br/>[sec_client.rb]"]
  node_thirteen_f_model["13F filings<br/>domain model<br/>[thirteen_f.rb]"]
  node_holding_model["Holdings<br/>domain model<br/>[holding.rb]"]
  node_import_tasks["Import tasks<br/>rake tasks"]
  node_minimal_seeder["Mini seeder<br/>seed helper"]
end

subgraph group_group_public["Public site"]
  node_home_controller["Home<br/>controller<br/>[home_controller.rb]"]
  node_filings_controller["13F views<br/>controller"]
  node_data_controller["Data API<br/>controller<br/>[data_controller.rb]"]
  node_managers_controller["Managers<br/>controller"]
  node_data_formatter["Table formatter<br/>presentation helper"]
  node_home_views["Home views<br/>templates<br/>[index.html.erb]"]
  node_filing_views["Filing views<br/>templates"]
  node_manager_views["Manager views<br/>templates<br/>[index.html.erb]"]
end

subgraph group_group_data["Data model"]
  node_thirteen_f_row[("thirteen_fs<br/>table<br/>[schema.rb]")]
  node_holding_rows[("holdings<br/>table<br/>[schema.rb]")]
  node_aggregate_rows[("aggregate_holdings<br/>denormalized table<br/>[schema.rb]")]
  node_filer_view["Filer view<br/>database view"]
  node_cusip_view["CUSIP view<br/>database view"]
  node_symbol_map["Symbol map<br/>lookup model"]
end

subgraph group_group_runtime["Runtime"]
  node_job_worker["Delayed job<br/>background jobs<br/>[application_job.rb]"]
  node_clock_proc["Clock process<br/>scheduler<br/>[clock.rb]"]
  node_web_proc["Web process<br/>rails app<br/>[puma.rb]"]
end

subgraph group_group_frontend["Frontend"]
  node_frontend_stack["Web assets<br/>client assets<br/>[application.js]"]
end

node_sec_client -->|"downloads filings"| node_thirteen_f_model
node_thirteen_f_model -->|"expands to"| node_holding_model
node_import_tasks -->|"imports quarters"| node_thirteen_f_model
node_minimal_seeder -->|"seeds records"| node_thirteen_f_model
node_clock_proc -->|"schedules"| node_job_worker
node_job_worker -->|"runs process!"| node_thirteen_f_model
node_web_proc -->|"serves"| node_home_controller
node_web_proc -->|"serves"| node_filings_controller
node_web_proc -->|"serves"| node_managers_controller
node_web_proc -->|"serves"| node_data_controller
node_data_controller -->|"formats"| node_data_formatter
node_filings_controller -->|"reads"| node_thirteen_f_row
node_filings_controller -->|"reads"| node_holding_rows
node_filings_controller -->|"reads"| node_aggregate_rows
node_managers_controller -->|"reads"| node_filer_view
node_thirteen_f_row -->|"enriched by"| node_filer_view
node_holding_rows -->|"enriched by"| node_cusip_view
node_aggregate_rows -->|"enriched by"| node_symbol_map
node_home_controller -->|"renders"| node_home_views
node_filings_controller -->|"renders"| node_filing_views
node_managers_controller -->|"renders"| node_manager_views
node_filing_views -->|"uses"| node_frontend_stack
node_data_formatter -->|"supports"| node_frontend_stack

click node_sec_client "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/lib/sec_client.rb"
click node_thirteen_f_model "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/thirteen_f.rb"
click node_holding_model "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/holding.rb"
click node_import_tasks "https://github.com/toddwschneider/sec-13f-filings/blob/main/lib/tasks/import_filings.rake"
click node_minimal_seeder "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/lib/minimal_db_seeder.rb"
click node_job_worker "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/jobs/application_job.rb"
click node_clock_proc "https://github.com/toddwschneider/sec-13f-filings/blob/main/clock.rb"
click node_web_proc "https://github.com/toddwschneider/sec-13f-filings/blob/main/config/puma.rb"
click node_home_controller "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/home_controller.rb"
click node_filings_controller "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/thirteen_fs_controller.rb"
click node_data_controller "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/data_controller.rb"
click node_managers_controller "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/managers_controller.rb"
click node_data_formatter "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/lib/data_table_formatter.rb"
click node_thirteen_f_row "https://github.com/toddwschneider/sec-13f-filings/blob/main/db/schema.rb"
click node_holding_rows "https://github.com/toddwschneider/sec-13f-filings/blob/main/db/schema.rb"
click node_aggregate_rows "https://github.com/toddwschneider/sec-13f-filings/blob/main/db/schema.rb"
click node_filer_view "https://github.com/toddwschneider/sec-13f-filings/blob/main/db/views/thirteen_f_filers_v01.sql"
click node_cusip_view "https://github.com/toddwschneider/sec-13f-filings/blob/main/db/views/company_cusip_lookups_v02.sql"
click node_symbol_map "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/cusip_symbol_mapping.rb"
click node_home_views "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/views/home/index.html.erb"
click node_filing_views "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/views/thirteen_fs/newest_filings.html.erb"
click node_manager_views "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/views/managers/index.html.erb"
click node_frontend_stack "https://github.com/toddwschneider/sec-13f-filings/blob/main/app/javascript/packs/application.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sec_client,node_thirteen_f_model,node_holding_model,node_import_tasks,node_minimal_seeder toneBlue
class node_home_controller,node_filings_controller,node_data_controller,node_managers_controller,node_data_formatter,node_home_views,node_filing_views,node_manager_views toneAmber
class node_thirteen_f_row,node_holding_rows,node_aggregate_rows,node_filer_view,node_cusip_view,node_symbol_map toneMint
class node_job_worker,node_clock_proc,node_web_proc toneRose
class node_frontend_stack toneIndigo
```

## Components

### Ingestion

SEC filing discovery, download, and expansion into holdings.

- [SEC client](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/lib/sec_client.rb): external API · Integration point for SEC EDGAR requests. · `app/lib/sec_client.rb`
- [13F filings](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/thirteen_f.rb): domain model · Filing records, import orchestration, and raw document storage. · `app/models/thirteen_f.rb`
- [Holdings](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/holding.rb): domain model · Normalized info-table rows expanded from filings. · `app/models/holding.rb`
- [Import tasks](https://github.com/toddwschneider/sec-13f-filings/blob/main/lib/tasks/import_filings.rake): rake tasks · Operational entry points for quarter imports and backfills. · `lib/tasks/import_filings.rake`
- [Mini seeder](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/lib/minimal_db_seeder.rb): seed helper · Seeds a small useful subset for development or ops. · `app/lib/minimal_db_seeder.rb`

### Public site

Read-only browsing and comparison pages for filings and holdings.

- [Home](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/home_controller.rb): controller · Landing page controller. · `app/controllers/home_controller.rb`
- [13F views](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/thirteen_fs_controller.rb): controller · Filing, holdings, comparison, and manager pages. · `app/controllers/thirteen_fs_controller.rb`
- [Data API](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/data_controller.rb): controller · AJAX data endpoint for tabular browsing. · `app/controllers/data_controller.rb`
- [Managers](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/controllers/managers_controller.rb): controller · Manager-centric browsing pages. · `app/controllers/managers_controller.rb`
- [Table formatter](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/lib/data_table_formatter.rb): presentation helper · Formats server-side DataTables responses. · `app/lib/data_table_formatter.rb`
- [Home views](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/views/home/index.html.erb): templates · Landing page and about content. · `app/views/home/index.html.erb`
- [Filing views](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/views/thirteen_fs/newest_filings.html.erb): templates · Browse, compare, and holdings pages. · `app/views/thirteen_fs/newest_filings.html.erb`
- [Manager views](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/views/managers/index.html.erb): templates · Manager index and related pages. · `app/views/managers/index.html.erb`

### Data model

Core relational tables, derived views, and lookup models.

- [thirteen_fs](https://github.com/toddwschneider/sec-13f-filings/blob/main/db/schema.rb): table · One row per filing. · `db/schema.rb`
- [holdings](https://github.com/toddwschneider/sec-13f-filings/blob/main/db/schema.rb): table · Individual holdings rows from info tables. · `db/schema.rb`
- [aggregate_holdings](https://github.com/toddwschneider/sec-13f-filings/blob/main/db/schema.rb): denormalized table · Pre-aggregated holdings for faster queries. · `db/schema.rb`
- [Filer view](https://github.com/toddwschneider/sec-13f-filings/blob/main/db/views/thirteen_f_filers_v01.sql): database view · Canonical filer naming and metadata. · `db/views/thirteen_f_filers_v01.sql`
- [CUSIP view](https://github.com/toddwschneider/sec-13f-filings/blob/main/db/views/company_cusip_lookups_v02.sql): database view · Canonical company/CUSIP lookup layer. · `db/views/company_cusip_lookups_v02.sql`
- [Symbol map](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/models/cusip_symbol_mapping.rb): lookup model · CUSIP to symbol mapping support. · `app/models/cusip_symbol_mapping.rb`

### Runtime

Process model for web, worker, and clock execution.

- [Delayed job](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/jobs/application_job.rb): background jobs · Asynchronous processing of filing imports. · `app/jobs/application_job.rb`
- [Clock process](https://github.com/toddwschneider/sec-13f-filings/blob/main/clock.rb): scheduler · Schedules new import work for workers. · `clock.rb`
- [Web process](https://github.com/toddwschneider/sec-13f-filings/blob/main/config/puma.rb): rails app · Puma-served public application process. · `config/puma.rb`

### Frontend

Client-side table behavior and styling pipeline.

- [Web assets](https://github.com/toddwschneider/sec-13f-filings/blob/main/app/javascript/packs/application.js): client assets · Webpacker, Tailwind, DataTables, and custom JS. · `app/javascript/packs/application.js`

## Connections

- SEC client → 13F filings: downloads filings · Fetches SEC XML and filing metadata for processing.
- 13F filings → Holdings: expands to · Processes info-table XML into normalized holdings rows.
- Import tasks → 13F filings: imports quarters · Creates placeholder filings and kicks off processing.
- Mini seeder → 13F filings: seeds records · Loads a small subset of managers and quarters.
- Clock process → Delayed job: schedules · Adds new processing work over time.
- Delayed job → 13F filings: runs process! · Executes filing download and expansion jobs.
- Web process → Home: serves · Runs the public Rails application.
- Web process → 13F views: serves · Handles public filing and holdings pages.
- Web process → Managers: serves · Handles manager browsing pages.
- Web process → Data API: serves · Exposes table-oriented AJAX endpoints.
- Data API → Table formatter: formats · Builds DataTables-compatible responses.
- 13F views → thirteen_fs: reads · Browses filings and derived holding views.
- 13F views → holdings: reads · Shows detailed and aggregated holdings.
- 13F views → aggregate_holdings: reads · Uses denormalized aggregates for fast browsing.
- Managers → Filer view: reads · Uses canonical filer metadata.
- thirteen_fs → Filer view: enriched by · Relies on canonical filer normalization.
- holdings → CUSIP view: enriched by · Joins to canonical company/CUSIP names.
- aggregate_holdings → Symbol map: enriched by · Supports security-level browsing and lookup.
- Home → Home views: renders · Landing page presentation.
- 13F views → Filing views: renders · Filing and holdings presentation.
- Managers → Manager views: renders · Manager presentation.
- Filing views → Web assets: uses · Tables, autocomplete, and styling behaviors.
- Table formatter → Web assets: supports · Feeds client-side data tables.
