A web API exposing a neural network to detect duplicate entities in knowledge graphs. It uses API key authentication and rate limits requests based on client tiers (FREEMIUM, PREMIUM)
Establish a project structure under a src directory, containing both the FastAPI application and the machine learning (ML) logic. This structure will support separation of concerns, modularity, and scalability, aligning with best practices for organizing code in complex API-based and ML-driven projects. The src folder should include subdirectories for the API logic, machine learning model, and core services.
User Stories
As an Architect, I want to centralize all source code under a src directory to streamline navigation, improve organization, and separate it from configuration and auxiliary files.
As a Data Scientist/Engineer, I want the project structure to support modularized ML logic, making it easier to develop, test, and maintain the machine learning components independently of the API.
Details
Objective: Set up a src directory to house the FastAPI application and ML logic, ensuring the organization is clean and logical for both backend and ML development.
Requirements:
[ ] Create a src directory at the root of the project.
[ ] Within src, create the following structured subdirectories and files:
src/app/: FastAPI application logic, including endpoints, configuration, and utilities
Associated task: #4
src/ml/: ML-related logic, including model loading, inference, and preprocessing functions.
Associated task: #6
Required Directory and File Structure
project_root/
├── src/ # Main source directory
│ ├── app/ # FastAPI application
│ │ ├── main.py # Entry point for FastAPI application
│ │ ├── config.py # Configuration settings
│ │ ├── api/ # API routes and dependencies
│ │ ├── schemas/ # Pydantic schemas for input/output validation
│ │ └── utils/ # Utility functions, including custom logging
│ │
│ ├── ml/ # ML logic and model handling
│ │ ├── model_loader.py # Model loading and inference functions
│ │ ├── preprocessing.py # Data preprocessing and feature engineering functions
│ │ └── models/ # Directory for storing ML models, if applicable
│
├── tests/ # Tests for the application
│ ├── integration/ # Integration tests for API endpoints
│
├── docker-compose.yml # Orchestrator for the application
├── .env.example # Example environment variables for developers
├── requirements.txt # Project dependencies
└── README.md # Overview and setup instructions
Examples and Notes
README.md: Should include updated instructions explaining the purpose of the src folder, along with setup steps for both the API and ML components.
requirements.txt: Include the required dependencies for both the FastAPI and ML aspects. Example initial dependencies:
Path Management: Ensure relative paths are handled consistently to avoid issues when accessing files across src/app, src/ml, and src/services.
Module Independence: Organize code so that the ML and API components remain modular, supporting future changes or integration with different ML models.
Description
Establish a project structure under a
src
directory, containing both the FastAPI application and the machine learning (ML) logic. This structure will support separation of concerns, modularity, and scalability, aligning with best practices for organizing code in complex API-based and ML-driven projects. Thesrc
folder should include subdirectories for the API logic, machine learning model, and core services.User Stories
src
directory to streamline navigation, improve organization, and separate it from configuration and auxiliary files.Details
src
directory to house the FastAPI application and ML logic, ensuring the organization is clean and logical for both backend and ML development.src
directory at the root of the project.src
, create the following structured subdirectories and files:Required Directory and File Structure
Examples and Notes
src
folder, along with setup steps for both the API and ML components.Edge Cases
src/app
,src/ml
, andsrc/services
.