Ir para o conteúdo

Development Guide

Referenced Files in This Document - README.md - requirements.txt - setup.py - alembic.ini - alembic/env.py - apps/service/main.py - apps/service/app.py - apps/service/deps.py - apps/shared/db.py - apps/dashboard/package.json - apps/dashboard/vite.config.ts - apps/dashboard/tsconfig.json - build.py - build-v2.py - release.py - index.py - apps/service/routes/auth.py - apps/service/routes/config.py - apps/service/routes/decisions.py - apps/service/routes/history.py - apps/service/routes/jellyfin.py - apps/service/routes/logs.py - apps/service/routes/push.py - apps/service/routes/status.py - apps/service/routes/tools.py - apps/service/routes/users.py - apps/service/core/pipeline.py - apps/service/core/matcher.py - apps/service/core/organizer.py - apps/service/core/scan.py - apps/service/core/types.py - apps/shared/models/init.py - apps/shared/schemas/init.py - apps/dashboard/src/App.tsx - apps/dashboard/src/main.tsx - apps/dashboard/src/pages/Home.tsx - apps/dashboard/src/pages/Login.tsx - apps/dashboard/src/components/Layout.tsx - apps/dashboard/src/hooks/usePush.ts - apps/dashboard/src/i18n/en-US.ts - apps/dashboard/src/i18n/pt-BR.ts

Table of Contents

  1. Introduction
  2. Project Structure
  3. Core Components
  4. Architecture Overview
  5. Detailed Component Analysis
  6. Dependency Analysis
  7. Performance Considerations
  8. Troubleshooting Guide
  9. Conclusion
  10. Appendices

Introduction

This guide explains how to set up a local development environment, build and run both backend and frontend components, test the application, follow code style guidelines, and contribute via pull requests. It also covers debugging techniques for Python and React, continuous integration considerations, and deployment pipelines.

Project Structure

The repository is a multi-component project: - Backend service (FastAPI-based) under apps/service with shared models and schemas under apps/shared. - Frontend dashboard (React + Vite + TypeScript) under apps/dashboard. - Database migrations managed by Alembic. - Build scripts at the repository root for packaging and release.

graph TB
subgraph "Backend"
SMain["apps/service/main.py"]
SApp["apps/service/app.py"]
SDeps["apps/service/deps.py"]
SDB["apps/shared/db.py"]
SModels["apps/shared/models/*"]
SSchemas["apps/shared/schemas/*"]
SRoutes["apps/service/routes/*"]
SCores["apps/service/core/*"]
end
subgraph "Frontend"
FMain["apps/dashboard/src/main.tsx"]
FApp["apps/dashboard/src/App.tsx"]
FPages["apps/dashboard/src/pages/*"]
FComp["apps/dashboard/src/components/*"]
FHooks["apps/dashboard/src/hooks/*"]
FI18N["apps/dashboard/src/i18n/*"]
FConf["apps/dashboard/vite.config.ts"]
FPkg["apps/dashboard/package.json"]
end
subgraph "Database"
AEnv["alembic/env.py"]
AIni["alembic.ini"]
end
subgraph "Build & Entry"
BPy["build.py"]
BV2["build-v2.py"]
RPy["release.py"]
Ipy["index.py"]
end
FMain --> FApp
FApp --> FPages
FApp --> FComp
FApp --> FHooks
FApp --> FI18N
FApp --> FConf
FApp --> FPkg
SMain --> SApp
SApp --> SDeps
SDeps --> SDB
SApp --> SRoutes
SRoutes --> SCores
SRoutes --> SModels
SRoutes --> SSchemas
SDB --> AEnv
AEnv --> AIni
BPy --> SMain
BV2 --> SMain
RPy --> BPy
Ipy --> SMain

Diagram sources - apps/service/main.py - apps/service/app.py - apps/service/deps.py - apps/shared/db.py - alembic/env.py - alembic.ini - apps/dashboard/src/main.tsx - apps/dashboard/src/App.tsx - apps/dashboard/vite.config.ts - apps/dashboard/package.json - build.py - build-v2.py - release.py - index.py

Section sources - README.md - requirements.txt - setup.py - alembic.ini - alembic/env.py - apps/service/main.py - apps/service/app.py - apps/service/deps.py - apps/shared/db.py - apps/dashboard/package.json - apps/dashboard/vite.config.ts - apps/dashboard/tsconfig.json - build.py - build-v2.py - release.py - index.py

Core Components

  • Backend API server: FastAPI application entrypoint and dependency injection setup.
  • Shared layer: Pydantic schemas and SQLAlchemy models used across routes and core logic.
  • Core business modules: pipeline orchestration, matching, organization, scanning, and type definitions.
  • Routes: REST endpoints for authentication, configuration, decisions, history, Jellyfin integration, logs, push notifications, status, tools, and users.
  • Frontend dashboard: React app with Vite, TypeScript, i18n, hooks, and page components.
  • Database: Alembic-managed migrations and database connection configuration.
  • Build and release: Packaging scripts and top-level entry points.

Key responsibilities: - apps/service/main.py: Application startup and configuration. - apps/service/app.py: FastAPI app instance and middleware setup. - apps/service/deps.py: Dependency providers (e.g., DB sessions). - apps/shared/db.py: Database engine/session configuration. - alembic/env.py: Migration runner configuration. - apps/dashboard/src/main.tsx and App.tsx: Frontend bootstrap and routing. - vite.config.ts and package.json: Frontend build and dev server settings.

Section sources - apps/service/main.py - apps/service/app.py - apps/service/deps.py - apps/shared/db.py - alembic/env.py - apps/dashboard/src/main.tsx - apps/dashboard/src/App.tsx - apps/dashboard/vite.config.ts - apps/dashboard/package.json

Architecture Overview

High-level runtime architecture: - The frontend serves static assets and communicates with the backend over HTTP. - The backend exposes REST APIs and uses shared schemas/models for validation and persistence. - Database migrations are executed via Alembic. - Build scripts package the application for distribution.

sequenceDiagram
participant Dev as "Developer"
participant FE as "Dashboard (Vite)"
participant BE as "FastAPI Service"
participant DB as "Database"
participant AM as "Alembic"
Dev->>AM : "Run migrations"
AM->>DB : "Apply schema changes"
Dev->>FE : "Start dev server"
FE->>BE : "HTTP requests (REST)"
BE->>DB : "Query/Update via session"
BE-->>FE : "JSON responses"
FE-->>Dev : "UI updates"

Diagram sources - apps/service/main.py - apps/service/app.py - apps/shared/db.py - alembic/env.py - apps/dashboard/vite.config.ts - apps/dashboard/src/main.tsx

Detailed Component Analysis

Backend Service

Responsibilities: - Initialize FastAPI app and configure dependencies. - Register route modules. - Provide shared services (database sessions, config).

classDiagram
class ServiceMain {
+startup()
+shutdown()
}
class ServiceApp {
+app
+middleware()
}
class Deps {
+get_db_session()
}
class SharedDB {
+engine
+session_factory
}
class Routes {
+auth
+config
+decisions
+history
+jellyfin
+logs
+push
+status
+tools
+users
}
class Core {
+pipeline
+matcher
+organizer
+scan
+types
}
ServiceMain --> ServiceApp : "creates"
ServiceApp --> Deps : "uses"
Deps --> SharedDB : "configures"
ServiceApp --> Routes : "includes routers"
Routes --> Core : "calls"

Diagram sources - apps/service/main.py - apps/service/app.py - apps/service/deps.py - apps/shared/db.py - apps/service/routes/auth.py - apps/service/routes/config.py - apps/service/routes/decisions.py - apps/service/routes/history.py - apps/service/routes/jellyfin.py - apps/service/routes/logs.py - apps/service/routes/push.py - apps/service/routes/status.py - apps/service/routes/tools.py - apps/service/routes/users.py - apps/service/core/pipeline.py - apps/service/core/matcher.py - apps/service/core/organizer.py - apps/service/core/scan.py - apps/service/core/types.py

Section sources - apps/service/main.py - apps/service/app.py - apps/service/deps.py - apps/shared/db.py - apps/service/routes/auth.py - apps/service/routes/config.py - apps/service/routes/decisions.py - apps/service/routes/history.py - apps/service/routes/jellyfin.py - apps/service/routes/logs.py - apps/service/routes/push.py - apps/service/routes/status.py - apps/service/routes/tools.py - apps/service/routes/users.py - apps/service/core/pipeline.py - apps/service/core/matcher.py - apps/service/core/organizer.py - apps/service/core/scan.py - apps/service/core/types.py

Frontend Dashboard

Responsibilities: - Bootstrap React app and configure routing. - Provide UI components, pages, hooks, and internationalization. - Configure Vite for development and production builds.

flowchart TD
Start(["Frontend Startup"]) --> LoadConfig["Load Vite Config"]
LoadConfig --> InstallDeps["Install Dependencies"]
InstallDeps --> RunDev["Run Dev Server"]
RunDev --> RenderApp["Render App Root"]
RenderApp --> RoutePages["Route to Pages"]
RoutePages --> FetchAPI["Call Backend APIs"]
FetchAPI --> UpdateUI["Update UI State"]
UpdateUI --> End(["User Interaction"])

Diagram sources - apps/dashboard/vite.config.ts - apps/dashboard/package.json - apps/dashboard/src/main.tsx - apps/dashboard/src/App.tsx - apps/dashboard/src/pages/Home.tsx - apps/dashboard/src/pages/Login.tsx - apps/dashboard/src/components/Layout.tsx - apps/dashboard/src/hooks/usePush.ts - apps/dashboard/src/i18n/en-US.ts - apps/dashboard/src/i18n/pt-BR.ts

Section sources - apps/dashboard/package.json - apps/dashboard/vite.config.ts - apps/dashboard/tsconfig.json - apps/dashboard/src/main.tsx - apps/dashboard/src/App.tsx - apps/dashboard/src/pages/Home.tsx - apps/dashboard/src/pages/Login.tsx - apps/dashboard/src/components/Layout.tsx - apps/dashboard/src/hooks/usePush.ts - apps/dashboard/src/i18n/en-US.ts - apps/dashboard/src/i18n/pt-BR.ts

Database and Migrations

  • Alembini configuration and migration runner.
  • Database engine and session factory setup.
  • Models and schemas define data contracts.
flowchart TD
Init(["Init DB Layer"]) --> CreateEngine["Create Engine"]
CreateEngine --> SessionFactory["Configure Session Factory"]
SessionFactory --> RunMigrations["Run Alembic Migrations"]
RunMigrations --> Ready["DB Ready"]

Diagram sources - alembic/env.py - alembic.ini - apps/shared/db.py - apps/shared/models/init.py - apps/shared/schemas/init.py

Section sources - alembic/env.py - alembic.ini - apps/shared/db.py - apps/shared/models/init.py - apps/shared/schemas/init.py

Dependency Analysis

External and internal dependencies: - Python packages defined in requirements.txt and setup.py. - Node.js workspace for the dashboard with its own package.json. - Alembic for migrations.

graph LR
Req["requirements.txt"] --> PyPkg["Python Packages"]
Setup["setup.py"] --> PyPkg
Pkg["apps/dashboard/package.json"] --> NPM["Node Modules"]
Vite["apps/dashboard/vite.config.ts"] --> NPM
Alembi["alembic.ini"] --> Alembic["Alembic"]
Env["alembic/env.py"] --> Alembic

Diagram sources - requirements.txt - setup.py - apps/dashboard/package.json - apps/dashboard/vite.config.ts - alembic.ini - alembic/env.py

Section sources - requirements.txt - setup.py - apps/dashboard/package.json - apps/dashboard/vite.config.ts - alembic.ini - alembic/env.py

Performance Considerations

  • Use connection pooling for database sessions and avoid long-running transactions in request handlers.
  • Cache frequently accessed read-only data where appropriate.
  • Minimize payload sizes by selecting only necessary fields in queries.
  • For the frontend, leverage Vite’s optimized builds and lazy-load heavy components.
  • Profile hot paths in core modules (e.g., matcher, organizer) using standard Python profiling tools.

[No sources needed since this section provides general guidance]

Troubleshooting Guide

Common issues and diagnostics: - Backend startup failures: verify environment variables, database connectivity, and Alembic migrations applied. - CORS or network errors between frontend and backend: ensure correct base URLs and ports in Vite config and browser dev tools. - Authentication problems: check route handlers and token handling. - Frontend build errors: inspect TypeScript and Vite configurations; clear node_modules if needed. - Logging: use backend logging to trace request flows and errors.

Section sources - apps/service/main.py - apps/service/app.py - apps/service/routes/auth.py - apps/dashboard/vite.config.ts - apps/dashboard/src/main.tsx

Conclusion

You now have a complete overview of the project structure, development workflow, testing strategy, code standards, contribution process, debugging techniques, CI considerations, and deployment pipelines. Follow the steps below to get started locally and contribute effectively.

[No sources needed since this section summarizes without analyzing specific files]

Appendices

Local Development Environment Setup

  • Python virtual environment:
  • Create and activate a virtual environment.
  • Install backend dependencies from requirements.txt.
  • Ensure Python version matches project constraints.
  • Node.js workspace:
  • Install Node.js compatible with the dashboard’s configuration.
  • Navigate to apps/dashboard and install dependencies using the provided package manager.
  • Database initialization:
  • Configure database URL in the shared database module.
  • Apply Alembic migrations before starting the backend.

Section sources - requirements.txt - setup.py - apps/dashboard/package.json - apps/shared/db.py - alembic/env.py - alembic.ini

Build Processes

  • Backend:
  • Development server: start the FastAPI service using the main entrypoint.
  • Production build: use the provided build scripts to package the backend.
  • Frontend:
  • Development server: run the Vite dev server from the dashboard directory.
  • Production build: use the dashboard’s build command configured in package.json.

Section sources - apps/service/main.py - apps/service/app.py - build.py - build-v2.py - apps/dashboard/package.json - apps/dashboard/vite.config.ts

Testing Strategy

  • Unit tests:
  • Write focused tests for core modules (e.g., matcher, organizer, types).
  • Mock external dependencies like databases and third-party APIs.
  • Integration tests:
  • Test route interactions with an in-memory or test database.
  • Validate request/response schemas and error handling.
  • End-to-end tests:
  • Simulate user flows through the frontend against a running backend.
  • Use headless browsers or API clients to validate critical paths.

Section sources - apps/service/core/matcher.py - apps/service/core/organizer.py - apps/service/core/types.py - apps/service/routes/decisions.py - apps/service/routes/history.py - apps/service/routes/status.py

Code Style Guidelines, Linting, and Formatting

  • Python:
  • Follow consistent naming conventions and import ordering.
  • Use type hints and docstrings for public interfaces.
  • Prefer small, focused functions and classes.
  • Frontend:
  • Use TypeScript strict mode and adhere to ESLint/Prettier rules if configured.
  • Keep components modular and reusable.
  • Maintain consistent styling and component composition patterns.

[No sources needed since this section provides general guidance]

Pull Request Workflow and Code Review

  • Branching:
  • Create feature branches from main for new work.
  • Keep commits atomic and descriptive.
  • Pull Requests:
  • Include a clear description of changes and rationale.
  • Link related issues and update documentation as needed.
  • Code Review:
  • Ensure tests pass and coverage is adequate.
  • Verify linting and formatting checks.
  • Request reviews from maintainers and address feedback promptly.

[No sources needed since this section provides general guidance]

Issue Reporting Guidelines

  • Provide environment details (OS, Python/Node versions).
  • Reproduction steps and expected vs actual behavior.
  • Logs and screenshots when applicable.
  • Minimal reproducible example if possible.

[No sources needed since this section provides general guidance]

Debugging Techniques

  • Backend (Python):
  • Use logging to trace request flows and exceptions.
  • Inspect database queries and session states.
  • Validate Pydantic schemas and route inputs.
  • Frontend (React/Vite):
  • Use browser dev tools to inspect network requests and console logs.
  • Check Vite dev server output for build/runtime errors.
  • Add breakpoints in TypeScript sources and step through execution.

Section sources - apps/service/main.py - apps/service/app.py - apps/dashboard/vite.config.ts - apps/dashboard/src/main.tsx

Continuous Integration and Deployment

  • CI:
  • Set up automated runs for linting, unit/integration tests, and builds.
  • Cache dependencies to speed up pipelines.
  • Deployment:
  • Use build scripts to package backend artifacts.
  • Serve frontend static assets via a web server or CDN.
  • Manage environment-specific configurations securely.

Section sources - build.py - build-v2.py - release.py - index.py

Contribution Guidelines

  • New features:
  • Open an issue to discuss scope and design.
  • Implement tests and update documentation.
  • Bug fixes:
  • Add regression tests to prevent recurrence.
  • Clearly describe the fix and affected areas.
  • Documentation improvements:
  • Keep guides up to date and link relevant source files.

[No sources needed since this section provides general guidance]