This documentation is part of the "Projects with Books" initiative at zenOSmosis.
The source code for this project is available on GitHub.
Development Guide
Loading…
Development Guide
Relevant source files
Purpose and Scope
This guide provides an overview of development practices, code organization, and workflows for contributing to the rust-sec-fetcher project. It covers environment setup, code organization principles, development workflows, and common development tasks.
For detailed information about specific development topics, see:
- Testing strategies and test fixtures: Testing Strategy
- Continuous integration and automated testing: CI/CD Pipeline
- Docker container configuration: Docker Deployment
Development Environment Setup
Prerequisites
The project requires the following tools installed:
| Tool | Purpose | Version Requirement |
|---|---|---|
| Rust | Core application development | 1.87+ |
| Python | ML pipeline and preprocessing | 3.8+ |
| Docker | Integration testing and services | Latest stable |
| Git LFS | Large file support for test assets | Latest stable |
| MySQL | Database for US GAAP storage | 5.7+ or 8.0+ |
Rust Development Setup
-
Clone the repository and navigate to the root directory.
-
Build the Rust application:
-
Run tests to verify setup:
The Rust workspace is configured with necessary dependencies. Key development dependencies include:
mockitofor HTTP mocking in tests.tempfilefor temporary file/directory creation in tests.tokiotest macros for async test support.
Python Development Setup
-
Create a virtual environment:
-
Install dependencies using
uv: -
Verify installation by running integration tests (requires Docker):
Sources: python/narrative_stack/us_gaap_store_integration_test.sh:1-39
Configuration Setup
The application requires a configuration file at ~/.config/sec-fetcher/config.toml or a custom path. Minimum configuration:
For non-interactive testing, use AppConfig directly in test code as shown in tests/config_manager_tests.rs:36-57
Sources: tests/config_manager_tests.rs:36-57 tests/sec_client_tests.rs:8-20
Code Organization and Architecture
Repository Structure
Sources: src/network/sec_client.rs:1-181 tests/config_manager_tests.rs:1-95 tests/sec_client_tests.rs:1-159 python/narrative_stack/us_gaap_store_integration_test.sh:1-39
Module Dependency Flow
The dependency flow follows a layered architecture:
- Configuration Layer :
ConfigManagerloads settings from TOML files and credentials. - Network Layer :
SecClientwraps HTTP client with caching and throttling middleware. - Data Fetching Layer : Network module functions fetch raw data from SEC APIs via
Urlvariants src/enums/url_enum.rs:5-116 - Transformation Layer : Transformers normalize raw data into standardized concepts.
- Model Layer : Data structures represent domain entities.
Sources: src/network/sec_client.rs:1-181 tests/config_manager_tests.rs:1-95 src/enums/url_enum.rs:5-116
Development Workflow
Standard Development Cycle
Sources: python/narrative_stack/us_gaap_store_integration_test.sh:1-39
Running Tests Locally
Rust Unit Tests
Run all Rust tests with cargo:
Run specific test modules:
Test Structure Mapping:
| Test File | Tests Component | Key Test Functions |
|---|---|---|
tests/config_manager_tests.rs | ConfigManager | test_load_custom_config, test_load_non_existent_config |
tests/sec_client_tests.rs | SecClient | test_user_agent, test_fetch_json_without_retry_success |
Sources: tests/config_manager_tests.rs:1-95 tests/sec_client_tests.rs:1-159
Python Integration Tests
Integration tests require Docker services. Run via the provided shell script:
This script performs the following steps as defined in python/narrative_stack/us_gaap_store_integration_test.sh:1-39:
- Activates Python virtual environment.
- Installs dependencies with
uv. - Starts Docker Compose services.
- Waits for MySQL availability.
- Creates
us_gaap_testdatabase and loads schema. - Runs pytest integration tests.
- Tears down containers on exit.
Sources: python/narrative_stack/us_gaap_store_integration_test.sh:1-39
Writing Tests
Unit Test Pattern (Rust)
The codebase uses mockito for HTTP mocking:
Sources: tests/sec_client_tests.rs:35-62
Test Fixture Pattern
The codebase uses temporary directories for file-based tests via tempfile::tempdir() as shown in tests/config_manager_tests.rs:8-17
Sources: tests/config_manager_tests.rs:8-17
Common Development Tasks
Adding a New SEC Data Endpoint
To add support for a new SEC data endpoint:
- Add URL enum variant in
src/enums/url_enum.rssrc/enums/url_enum.rs:5-116 - Update
Url::value()to return the formatted URL string src/enums/url_enum.rs:121-165 - Create fetch function in
src/network/using the newUrlvariant. - Define data models in
src/models/for the response structure.
Sources: src/enums/url_enum.rs:5-165
Modifying HTTP Client Behavior
The SecClient is configured in src/network/sec_client.rs:21-89 Key configuration points:
| Configuration | Location | Purpose |
|---|---|---|
CachePolicy | src/network/sec_client.rs:45-50 | Controls cache TTL and behavior |
ThrottlePolicy | src/network/sec_client.rs:53-59 | Controls rate limiting and retries |
| User-Agent | src/network/sec_client.rs:91-108 | Constructs SEC-compliant User-Agent header |
Sources: src/network/sec_client.rs:21-108
Code Quality Standards
CI/CD and Maintenance
The project uses GitHub Actions for automated quality checks:
- Linting :
rust-lint.ymlruns clippy and rustfmt. - Testing :
rust-tests.ymlruns the test suite. - Documentation :
build-docs.ymlgenerates documentation weekly build-docs.yml:1-81 - Dependency Updates : Dependabot is configured for weekly Cargo updates dependabot.yml:1-10
Sources: .github/workflows/build-docs.yml:1-81 .github/dependabot.yml:1-10
Dismiss
Refresh this wiki
Enter email to refresh