How scholarly-insight/scholarly-insight-backend works
Main Components
• Backend Application: Represented by the FastAPI server (backend/app/main.py), which orchestrates the API endpoints.
• API Endpoints Layer: Located in backend/app/api/v1/endpoints. These routes handle incoming HTTP requests – for example, endpoints for authentication and user management.
• Core Services:
• Configuration (backend/app/core/config.py) – managing global settings.
• Database Connection (backend/app/core/database.py) – providing connectivity to PostgreSQL.
• Firebase Integration (backend/app/core/firebase.py) – handling Firebase authentication.
• Models & Schemas:
• Models (backend/app/models) – SQLAlchemy models that define the database schema.
• Schemas (backend/app/schemas) – Pydantic models that validate and serialize API request/response data.
• Business Logic / Services: (backend/app/services) – encapsulating the core business logic such as authentication and user management.
• Database and Migrations:
• PostgreSQL – as the primary data store.
• Alembic Migration Scripts (in backend/alembic and its subdirectories) – managing schema changes.
Relationships and Interactions
• The FastAPI Application (main.py) loads and configures the routing layers from the API directory.
• API endpoints call services (from backend/app/services) that use models (from backend/app/models) to query the PostgreSQL database.
• The database connection, configured in core/database.py, ensures a consistent and reliable link between the API and PostgreSQL.
• Firebase integration (via core/firebase.py) introduces external authentication into API endpoints. For example, “get_current_user” (from app/api/deps.py) is used to inject Firebase-authenticated users into protected routes.
• The configuration module (core/config.py) pulls necessary environmental variables as defined in the .env file.
Architectural Patterns & Important Design Principles
• Separation of Concerns: Distinct directories for API endpoints, core configurations, models, schemas, services, and migration files ensure modularity.
• Dependency Injection: Noticeable in how route handlers use dependencies (e.g., get_current_user) to enforce authentication.
• Database Migration Workflow: Using Alembic (with alembic.ini and the alembic directory) indicates a design that anticipates schema evolution, which is important for production-readiness.