-
Notifications
You must be signed in to change notification settings - Fork 0
Project Structure
Michael Pisman edited this page Aug 7, 2025
·
1 revision
├── app/
│ ├── actions/ # Business logic
│ │ ├── account.py
│ │ ├── authentication.py
│ │ ├── group.py
│ │ ├── members.py
│ │ ├── permissions.py
│ │ ├── policy.py
│ │ ├── poll.py
│ │ ├── superuser.py
│ │ └── workspace.py
│ ├── api/ # HTTP route handlers
│ │ ├── polls.py
│ │ ├── streams.py
│ │ └── websocket.py
│ ├── exceptions/ # Custom exceptions
│ │ ├── account.py
│ │ ├── authentication.py
│ │ ├── group.py
│ │ ├── policy.py
│ │ ├── poll.py
│ │ ├── resource.py
│ │ └── workspace.py
│ ├── models/ # Data models
│ │ ├── polls.py
│ │ └── questions.py
│ ├── schemas/ # Request/response schemas
│ │ ├── polls.py
│ │ ├── questions.py
│ │ └── websocket.py
│ └── utils/ # Utility functions
│ ├── actions.py
│ ├── api_versioning.py
│ ├── api.py
│ ├── auth.py
│ ├── cli_args.py
│ ├── colored_dbg.py
│ ├── events.py
│ ├── mongo.py
│ └── streams.py
├── docker-compose.yml
├── Dockerfile
├── main.py # Application entry point
├── pyproject.toml # Project configuration
├── requirements.txt # Python dependencies
└── uv.lock # Dependency lock file
Contains the main FastAPI application instance. Responsible for:
- Starting the server
- Loading configuration
- Registering routes and middleware
- Database initialization
Configuration management using Pydantic Settings:
- Environment variable loading
- Default values
- Configuration validation
FastAPI dependency injection functions:
- Authentication dependencies
- Database session management
- Request validation
Database document definitions using Beanie ODM:
- User/Account models
- Workspace models
- Group models
- Poll models
- Policy models
Command-line interface using argparse:
- Server startup commands
- Configuration setup
- OpenAPI schema generation
Contains business logic and data processing:
- Purpose: Implement core functionality separate from HTTP concerns
- Pattern: Each action is a pure function that takes input and returns output
- Benefits: Testable, reusable, and framework-agnostic
HTTP route handlers and request/response processing:
- Purpose: Handle HTTP requests and delegate to actions
- Responsibilities: Request validation, response formatting, error handling
- Integration: Uses FastAPI decorators and depends on actions layer
Database document definitions:
- Purpose: Define data structure and relationships
- Technology: Beanie ODM (built on MongoDB)
- Features: Validation, relationships, indexes
Request and response data validation:
- Purpose: Define API contracts using Pydantic models
- Benefits: Automatic validation, serialization, and documentation
- Types: Input schemas, output schemas, update schemas
Shared utilities and helper functions:
- Authentication: JWT handling, OAuth strategies
- Database: Connection management, query helpers
- CLI: Command-line argument parsing
- Debugging: Colored console output
-
Database Models (
models/) - Define your data structure -
Schemas (
schemas/) - Define API contracts -
Actions (
actions/) - Implement business logic -
Routes (
api/) - Create HTTP endpoints -
Tests (
tests/) - Write comprehensive tests
- Snake_case for file and function names
- PascalCase for class names
- UPPER_CASE for constants
- Descriptive names that indicate purpose
# Standard library imports
import os
from typing import List
# Third-party imports
from fastapi import FastAPI, Depends
from pydantic import BaseModel
# Local imports
from app.dependencies import get_current_user
from app.actions.workspace import create_workspace
from app.schemas.workspace import WorkspaceCreate