Skip to content

File Structure

Seyi Pythonian edited this page Jul 25, 2024 · 1 revision

Structure Overview

This page provides a detailed overview of the project's file structure and the purpose of each module.

api
├── __init__.py
├── core
│   ├── __init__.py
│   ├── base
│   │   ├── __init__.py
│   │   └── services.py
│   ├── dependencies
│   │   └── __init__.py
│   └── responses.py
├── db
│   ├── __init__.py
│   └── database.py
├── utils
│   ├── __init__.py
│   ├── config.py
│   ├── dependencies.py
│   ├── dict.py
│   ├── exceptions.py
│   ├── json_response.py
│   ├── logging_config.py
│   ├── settings.py
│   └── sql.py
└── v1
    ├── __init__.py
    ├── models
    │   ├── __init__.py
    │   ├── base.py
    │   └── <module>.py
    ├── routes
    │   ├── __init__.py
    │   └── <module>.py
    ├── schemas
    │   ├── __init__.py
    │   └── <module>.py
    └── services
        ├── __init__.py
        └── <module>.py

Core

  • base/services.py: Contains base service classes and common utilities.
  • dependencies/: Contains dependency functions for request handling.
  • responses.py: Handles custom response formats and structures.

DB

  • database.py: Manages database connections and session handling.

Utils

  • config.py: Configuration settings for the project.
  • dependencies.py: Additional dependency functions.
  • dict.py: Utilities for dictionary operations.
  • exceptions.py: Custom exception classes.
  • json_response.py: Utilities for JSON responses.
  • logging_config.py: Configuration for logging.
  • settings.py: Project settings and environment variables.
  • sql.py: SQL utilities and helpers.

v1

  • models/: Defines the data models for the application.
    • base.py: Base model classes.
  • routes/: Defines the API routes.
  • schemas/: Defines the Pydantic schemas.
  • services/: Contains service classes that implement business logic.

Modules

This application follows a modular structure. A module is like an app that implements a particular feature. Each module contains models, routes, schemas, and services. This guide outlines the file structure and the required components for each module.

The file structure for each module follows this pattern:

api
└── v1
    ├── models
    │   ├── __init__.py
    │   └── <module>.py
    ├── routes
    │   ├── __init__.py
    │   └── <module>.py
    ├── schemas
    │   ├── __init__.py
    │   └── <module>.py
    └── services
        ├── __init__.py
        └── <module>.py

Steps to Add a New Module

1. Create a New Model

Location: api/v1/models/<module>.py

  • Define database models and ORM mappings.

2. Create a New Schema

Location: api/v1/schemas/<module>.py

  • Define Pydantic schemas for request and response validation.

3. Create a New Service

Location: api/v1/services/<module>.py

  • Define business logic and interactions with the database.

4. Create a New Router

Location: api/v1/routes/<module>.py

  • Define API endpoints and route handlers.

5. Register the Router

Location: api/v1/routes/__init__.py

  • Import and include the new router.
Clone this wiki locally