Skip to content

PedrodeAlmeidaFreitas/ForaProject

Repository files navigation

ForaProject - FinTech Company Fundable Amount Calculator

CI Status CD Status License

A .NET 8 application built with Clean Architecture principles to calculate fundable amounts for companies based on SEC EDGAR financial data.

πŸ“‹ Overview

This application imports company financial data from the SEC EDGAR API and calculates two types of fundable amounts based on specific business rules.

Business Rules

Data Requirements:

  • Company must have income data for all years between 2018 and 2022
  • Company must have positive income in both 2021 and 2022
  • If these conditions are not met, fundable amounts are $0

Standard Fundable Amount Calculation:

Using the highest income between 2018 and 2022:

  • If income β‰₯ $10B: 12.33% of income
  • If income < $10B: 21.51% of income

Special Fundable Amount Calculation:

Starts with the Standard Fundable Amount, then applies modifiers:

  • If company name starts with a vowel (A, E, I, O, U): +15% to standard amount
  • If 2022 income < 2021 income: -25% from standard amount

Example Calculations

Company A (High Income, starts with 'A', decreasing income):

  • Highest income 2018-2022: $15B
  • Standard: $15B Γ— 12.33% = $1,849,500,000
  • Special: $1,849,500,000 Γ— 1.15 (vowel) Γ— 0.75 (decrease) = $1,597,687,500

Company B (Low Income, starts with 'B', increasing income):

  • Highest income 2018-2022: $5B
  • Standard: $5B Γ— 21.51% = $1,075,500,000
  • Special: $1,075,500,000 (no modifiers) = $1,075,500,000

πŸ—οΈ Architecture

Built following Clean Architecture and Domain-Driven Design (DDD) principles:

β”œβ”€β”€ ForaProject.Domain          # Core business logic and entities
β”œβ”€β”€ ForaProject.Application     # Application services and use cases
β”œβ”€β”€ ForaProject.Infrastructure  # Data persistence and external services
└── ForaProject.API            # REST API controllers and HTTP layer

Design Patterns & Principles

  • βœ… SOLID Principles
  • βœ… DRY (Don't Repeat Yourself)
  • βœ… KISS (Keep It Simple, Stupid)
  • βœ… Repository Pattern
  • βœ… Unit of Work Pattern
  • βœ… Value Objects
  • βœ… Aggregates

πŸš€ Getting Started

Prerequisites

Option 1: Docker (Recommended)

Option 2: Local Development

Installation

🐳 Option 1: Using Docker (Recommended)

  1. Clone the repository

    git clone https://github.com/PedrodeAlmeidaFreitas/ForaProject.git
    cd ForaProject
  2. Set up environment variables

    # Quick setup with default values
    ./setup-env.sh
    
    # Or manually copy and edit
    cp .env.example .env
    # Edit .env and update SA_PASSWORD with a strong password
  3. Start the application with Docker Compose

    docker compose up --build

    This will:

    • Start SQL Server 2022 container on port 1433
    • Build and start the API container on port 5000
    • Create the database and run migrations automatically
    • Set up a bridge network between containers
    • Use environment variables from .env file
  4. Access the API

  5. Stop the application

    docker compose down
  6. Stop and remove volumes (clean slate)

    docker compose down -v

πŸ’» Option 2: Local Development

  1. Clone the repository

    git clone https://github.com/PedrodeAlmeidaFreitas/ForaProject.git
    cd ForaProject
  2. Update Connection String

    Edit src/ForaProject.API/appsettings.json:

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=localhost;Database=ForaProjectDb;Trusted_Connection=True;TrustServerCertificate=True;"
      }
    }
  3. Run Database Migrations

    dotnet ef database update --project src/ForaProject.Infrastructure --startup-project src/ForaProject.API
  4. Build the Solution

    dotnet build
  5. Run the API

    cd src/ForaProject.API
    dotnet run
  6. Access Swagger UI

    Open your browser and navigate to:

    https://localhost:5001/swagger
    

πŸ“š API Endpoints

Companies

  • GET /api/v1/companies - Get all companies
  • GET /api/v1/companies/cik/{cik} - Get company by CIK
  • GET /api/v1/companies/{id} - Get company by ID
  • POST /api/v1/companies - Create company manually
  • POST /api/v1/companies/import - Import from SEC EDGAR
  • POST /api/v1/companies/import/batch - Batch import
  • DELETE /api/v1/companies/{id} - Delete company

Fundable Amounts

  • GET /api/v1/fundableamounts - Get all fundable companies
  • GET /api/v1/fundableamounts/letter/{letter} - Filter by starting letter
  • POST /api/v1/fundableamounts/calculate/{cik} - Calculate for one company
  • POST /api/v1/fundableamounts/calculate/all - Calculate for all companies

πŸ§ͺ Example Usage

Import Apple Inc. (CIK: 320193)

curl -X POST https://localhost:5001/api/v1/companies/import \
  -H "Content-Type: application/json" \
  -d '{"cik": 320193}'

Sample CIKs to Test

  • Apple Inc.: 320193
  • Microsoft Corp: 789019
  • Alphabet Inc.: 1652044
  • Amazon.com Inc: 1018724
  • Meta Platforms Inc.: 1326801

🧰 Technologies Used

  • .NET 8 - Framework
  • Entity Framework Core 8 - ORM
  • SQL Server 2022 - Database
  • Docker & Docker Compose - Containerization
  • AutoMapper - Object mapping
  • FluentValidation - Input validation
  • Swagger/OpenAPI - API documentation

🐳 Docker Configuration

Services

  • sqlserver: SQL Server 2022 Developer Edition

    • Port: 1433
    • Volume: sqlserver_data for data persistence
    • Health check enabled
  • api: ForaProject.API

    • Port: 5000 (HTTP)
    • Multi-stage build for optimized image size
    • Waits for SQL Server health check before starting

Environment Variables

The application uses a .env file for configuration. Available variables:

Variable Description Default
SA_PASSWORD SQL Server SA password YourStrong!Passw0rd123
MSSQL_PID SQL Server edition Developer
DB_SERVER Database server name sqlserver
DB_NAME Database name ForaProjectDb
DB_USER Database user sa
ASPNETCORE_ENVIRONMENT ASP.NET Core environment Development
ASPNETCORE_URLS API URLs http://+:80
API_PORT Host port for API 5000

Setup:

# Use setup script (recommended)
./setup-env.sh

# Or manually
cp .env.example .env
nano .env  # Update SA_PASSWORD and other values

Security: The .env file is ignored by git. Never commit it to version control!

Docker Commands

# Build and start all services
docker compose up --build

# Start services in detached mode
docker compose up -d

# View logs
docker compose logs -f

# Stop all services
docker compose down

# Stop and remove volumes
docker compose down -v

# Rebuild specific service
docker compose build api

πŸ“ Project Structure

ForaProject/
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ workflows/                 # GitHub Actions CI/CD pipelines
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE/           # Issue templates
β”‚   β”œβ”€β”€ CICD.md                   # CI/CD documentation
β”‚   β”œβ”€β”€ PIPELINE.md               # Pipeline overview
β”‚   └── PULL_REQUEST_TEMPLATE.md  # PR template
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ ForaProject.Domain/        # Business logic, entities, value objects
β”‚   β”œβ”€β”€ ForaProject.Application/   # Services, DTOs, validators
β”‚   β”œβ”€β”€ ForaProject.Infrastructure/# EF Core, repositories, migrations
β”‚   └── ForaProject.API/          # Controllers, middleware, filters
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ ForaProject.Domain.Tests/
β”‚   β”œβ”€β”€ ForaProject.Application.Tests/
β”‚   β”œβ”€β”€ ForaProject.API.Tests/
β”‚   └── ForaProject.IntegrationTests/
β”œβ”€β”€ docker-compose.yml            # Multi-container configuration
β”œβ”€β”€ Dockerfile                    # API container image
β”œβ”€β”€ coverlet.runsettings          # Code coverage settings
β”œβ”€β”€ validate-ci.sh                # Local CI validation script
β”œβ”€β”€ CHANGELOG.md                  # Version history
└── ForaProject.sln              # Solution file

πŸ”„ CI/CD Pipeline

This project uses GitHub Actions for automated CI/CD:

  • βœ… Continuous Integration: Automated builds, tests, and code coverage
  • 🐳 Docker Images: Multi-platform builds pushed to GitHub Container Registry
  • πŸ” Security Scanning: CodeQL analysis and dependency audits
  • πŸ“Š Code Coverage: 80% minimum threshold with automatic PR comments
  • πŸš€ Automated Deployments: Staging and production deployments

Quick Start

# Run all CI checks locally before pushing
./validate-ci.sh

# View detailed CI/CD documentation
cat .github/PIPELINE.md

Learn more:

🀝 Contributing

We welcome contributions! Please follow these steps:

1. Fork and Clone

git clone https://github.com/PedrodeAlmeidaFreitas/ForaProject.git
cd ForaProject

2. Create a Feature Branch

git checkout -b feat/your-feature-name

Use conventional commit prefixes: feat, fix, docs, test, refactor, perf, ci, chore

3. Make Your Changes

  • Follow Clean Architecture guidelines
  • Write tests for new functionality
  • Maintain or improve code coverage (80% minimum)
  • Follow SOLID principles and DDD patterns

4. Run Local Validation

./validate-ci.sh

This runs:

  • Build verification
  • All test suites
  • Code coverage check
  • Code formatting validation
  • Security audit

5. Commit with Conventional Format

git commit -m "feat(domain): add new entity for X"
git commit -m "fix(api): correct validation in Y controller"
git commit -m "docs(readme): update installation instructions"

6. Push and Create PR

git push origin feat/your-feature-name

Then create a Pull Request using the PR template

7. PR Review Process

  • βœ… All CI checks must pass
  • βœ… Code coverage threshold met (80%)
  • βœ… At least one approval required
  • βœ… Conventional commit format
  • βœ… No security vulnerabilities

Reporting Issues

Use the appropriate issue template:

Code of Conduct

  • Be respectful and inclusive
  • Follow the project's coding standards
  • Write clear commit messages and PR descriptions
  • Keep PRs focused and reasonably sized

οΏ½ Additional Documentation

οΏ½πŸ“„ License

MIT License

About

.NET 8 application with Clean Architecture, DDD, and comprehensive CI/CD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages