Folder Structure
This project is a backend application structured for modularity, scalability, and maintainability. Below is a comprehensive breakdown of the folder structure and the purpose of each component in the codebase.
Entry Point
server.py
- Serves as the main entry point of the application.
- Initializes the FastAPI/Flask app instance.
- Loads environment configurations.
- Declares global middleware and application-wide settings.
- Registers routes and APIs.
API & Routing
Routers
Handles routing logic for API endpoints and authentication.
auth0.py: Contains helper functions for handling Auth0-related operations.authorization_util.py: Manages authentication workflows and validation logic.common_apis.py: Hosts the core API endpoint definitions consumed by the frontend or other services.
Services
The services/ folder contains business logic functions used in API endpoints.
order_service.py: Order processing and management.price_service.py: Pricing logic and rules.sales_service.py: Sales-related operations.share_service.py: Logic for data sharing between entities.
Note: There is a duplicate
services/folder under a different root, used for domain-specific service logic. See the Detailed Service Logic section.
Automation
automation/
Scripts and utilities for automated workflows.
MSME/: Handles data processing for Micro, Small, and Medium Enterprises.GST/: Automates tasks related to Goods and Services Tax.struck_off_checks/: Contains logic to verify and process struck-off company data.
Database Migrations
db_migrations/
- Tracks and applies changes to the database schema.
- Helps ensure database consistency across environments.
Detailed Service Logic
services/
Domain-driven service layer handling core data operations.
info_service.py: Information-related service logic.order_service.py: Manages order-related logic.price_service.py: Pricing-related services.sales_service.py: Business logic related to sales.share_service.py: Handles logic for sharing and access control.
Models
models/
Database schema definitions and base model classes.
base.py: Shared base classes and SQLAlchemy setup.info_schema.py: Schema for informational data.order_schema.py: Order-related schema definitions.price_schema.py: Defines schema for pricing data.
Static Assets
static/
Images/: Contains static image assets used throughout the app.Templates/: Excel/XL file templates rendered directly via the UI or APIs.
Environment Configuration
.env
- Stores secret keys, database credentials, and other sensitive configurations.
- Should be kept private and excluded from version control.
Project Folder Structure
.
├── server.py # Application entry point: initializes app, middleware, and routes
├── Routers/ # API routing and authentication utilities
│ ├── auth0.py # Auth0 integration helpers
│ ├── authorization_util.py # Custom authentication utility functions
│ └── common_apis.py # Main API endpoint definitions
├── services/ # Top-level service functions used by API routes
│ ├── order_service.py # Functions for handling order operations
│ ├── price_service.py # Functions for price calculation and logic
│ ├── sales_service.py # Functions related to sales operations
│ └── share_service.py # Functions for data sharing logic
├── automation/ # Scripts and tools for data automation and processing
│ ├── MSME/ # Scripts related to MSME (Micro, Small & Medium Enterprises)
│ ├── GST/ # Scripts for GST (Goods and Services Tax) data
│ └── struck_off_checks/ # Scripts for handling struck-off company data
├── db_migrations/ # Database migration scripts to manage schema changes
├── services/ # Domain-specific service logic (overlaps with top-level services)
│ ├── info_service.py # Service logic for informational data
│ ├── order_service.py # Logic for order processing
│ ├── price_service.py # Logic related to pricing
│ ├── sales_service.py # Logic for sales data handling
│ └── share_service.py # Logic for sharing and data access
├── models/ # Database model definitions and schema structures
│ ├── base.py # Base classes for SQLAlchemy models
│ ├── info_schema.py # Schema definitions for information-related data
│ ├── order_schema.py # Schema for order data models
│ └── price_schema.py # Schema for price-related models
├── static/ # Static files used across the app
│ ├── Images/ # Image assets
│ └── Templates/ # Excel templates rendered in the application
└── .env # Environment variables and secret keys (keep private)
Tips
- Always keep your
.envfile secure and avoid pushing it to public repositories. - Follow single-responsibility principles in services to keep logic modular and testable.
- Regularly apply and review
db_migrations/scripts to ensure database consistency.