How codevalley/friday-api works
Main Components
• API / Presentation Layer:
– Represented by the “routers” directory (specifically routers/v1 for API versioning). These handle the incoming REST endpoints (e.g., ActivityRouter, AuthRouter, DocumentRouter, etc.) and interface directly with clients.
• Service / Business Logic Layer:
– Found under “services” (e.g., ActivityService, DocumentService, OpenAIService, RateLimiter, etc.). This layer orchestrates the operations and implements the API’s core business rules.
• Domain Layer:
– Located in the “domain” directory with core entities like activity, moment, note, document, task, timeline, topic, and user. This is your business model that encapsulates validation, rules, and business types.
• Data Access Layer:
– Implemented through the “repositories” and “orm” directories. Here, SQLAlchemy models (in orm/) and repository classes (in repositories/) manage database operations for MySQL.
• Infrastructure Layer:
– Includes subcomponents such as the “infrastructure/queue” (with workers like activity_worker, note_worker, task_worker, and run_worker), which are managed via Redis (see “configs/redis” and “infrastructure/storage” for different storage mechanisms like local, S3, and mock). This also covers external integrations (e.g., OpenAI service).
• Configuration and Utility Components:
– “configs” directory encapsulates various configurations (Database, Redis, OpenAPI, Logging, etc.).
– Utility modules (in “utils”) handle error processing, retry logic, logging, security, and validation.
• External Systems:
– MySQL for persistent data storage.
– Redis for queuing and caching.
– OpenAI (via services/OpenAIService) for external API integration.
– Deployment Tools – Dockerfiles, docker-compose, and devcontainer setups for environment management.
Relationships and Flow
• Service layer interacting with the domain layer, creating and enforcing business rules and validations.
• Connection from the domain/service layer to the data access layer (repositories calling the ORM) for database CRUD operations with MySQL.
• A side branch where the service layer enqueues tasks/activities (data processing, note enrichment, etc.) that are managed by the queue workers using Redis.
• Configuration components underpinning the entire structure (configs for environment, logging, and OpenAPI) that support multiple layers.
Architectural Patterns & Design Principles
• Layered/MVC-like Separation: Clearly separate API (routers), business logic (services), domain modeling, and data access layers.
• Asynchronous Task Handling: Emphasize the use of background workers and queue-based processing with Redis.
• Domain-Driven Design: The domain layer encapsulating key business logic and validation.
• Extensibility: Note the use of interfaces (e.g., in domain/ports) and well-organized configurations to allow easier future integration of additional services or storage solutions.