How toddwschneider/sec-13f-filings works
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: thirteen_fs_controller.rb 13F views · thirteen_f.rb 13F filings · puma.rb Web process · managers_controller.rb Managers
Components 23
Ingestion
SEC filing discovery, download, and expansion into holdings.
- SEC client · Integration point for SEC EDGAR requests.
app/lib/sec_client.rb - 13F filings · Filing records, import orchestration, and raw document storage.
app/models/thirteen_f.rb - Holdings · Normalized info-table rows expanded from filings.
app/models/holding.rb - Import tasks · Operational entry points for quarter imports and backfills.
lib/tasks/import_filings.rake - Mini seeder · 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 · Landing page controller.
app/controllers/home_controller.rb - 13F views · Filing, holdings, comparison, and manager pages.
app/controllers/thirteen_fs_controller.rb - Data API · AJAX data endpoint for tabular browsing.
app/controllers/data_controller.rb - Managers · Manager-centric browsing pages.
app/controllers/managers_controller.rb - Table formatter · Formats server-side DataTables responses.
app/lib/data_table_formatter.rb - Home views · Landing page and about content.
app/views/home/index.html.erb - Filing views · Browse, compare, and holdings pages.
app/views/thirteen_fs/newest_filings.html.erb - Manager views · Manager index and related pages.
app/views/managers/index.html.erb
Data model
Core relational tables, derived views, and lookup models.
- thirteen_fs · One row per filing.
db/schema.rb - holdings · Individual holdings rows from info tables.
db/schema.rb - aggregate_holdings · Pre-aggregated holdings for faster queries.
db/schema.rb - Filer view · Canonical filer naming and metadata.
db/views/thirteen_f_filers_v01.sql - CUSIP view · Canonical company/CUSIP lookup layer.
db/views/company_cusip_lookups_v02.sql - Symbol map · CUSIP to symbol mapping support.
app/models/cusip_symbol_mapping.rb
Runtime
Process model for web, worker, and clock execution.
- Delayed job · Asynchronous processing of filing imports.
app/jobs/application_job.rb - Clock process · Schedules new import work for workers.
clock.rb - Web process · Puma-served public application process.
config/puma.rb
Frontend
Client-side table behavior and styling pipeline.
- Web assets · Webpacker, Tailwind, DataTables, and custom JS.
app/javascript/packs/application.js
Connections 23
- 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.