# ypoonia/tryai architecture

> Architecture diagram of the GitHub repository ypoonia/tryai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ypoonia/tryai
- Repository: https://github.com/ypoonia/tryai

## Overview

##### Project type and purpose
- This is a Python-based backend service called “Store Monitoring System.”
- It exposes REST endpoints, processes data both synchronously and asynchronously (Celery), performs CRUD against a database, runs computing algorithms, and generates reports.

##### File structure
Top-level view:
- app/
- controllers/     ← HTTP request handlers invoking business logic
- core/            ← configuration (e.g., FastAPI settings, Celery config)
- database/        ← CRUD methods, DB session management
- models/          ← ORM classes for database tables
- schemas/         ← Pydantic request/response models
- routes/          ← FastAPI routers binding endpoints to controllers
- services/        ← domain logic (e.g., compute_Algo, report_service)
- tasks/           ← Celery task definitions for background jobs
- utils/           ← helper modules (e.g., URL resolver)
- celery_app.py    ← Celery app factory
- main_rcs.py      ← FastAPI app initialization & router mounting
- reports.json       ← static or seed data for reports
- requirements.txt   ← dependencies (FastAPI, SQLAlchemy, Celery, etc.)

##### README for additional insights
- Project is called “Store Monitoring System.”
- There’s an existing Excalidraw deck and Google Doc describing workflows.
- Features likely include data ingestion, real-time monitoring, scheduled reports, background processing.

a. Main components:
1. Client / Consumer (Web UI or external service)
2. API Layer (FastAPI in main_rcs.py + routes + controllers)
3. Business Logic Layer (services package)
4. Database (SQL database accessed via database/crud.py + models)
5. Task Queue & Worker (Celery broker, celery_app.py + tasks)
6. External/Internal Utilities (url_resolver, static reports.json)

b. Relationships & Interactions:
- Client → HTTP → FastAPI Routes → Controllers
- Controllers ↔ Schemas (validate input/output)
- Controllers → Services → CRUD (sync operations for reads/writes)
- Controllers → Celery Tasks (for long-running report jobs)
- Celery Worker → Services (compute_Algo, report_service) → Database updates & report storage
- Database → Controllers (fetching compiled monitoring data)

c. Architectural patterns & principles:
- Layered architecture (Presentation, Controllers, Services, Data Access)
- Separation of sync vs. async paths (FastAPI vs. Celery)
- Dependency injection via config in app/core/config.py
- Use of Pydantic schemas for strong typing and validation
- Modular folder structure for testability and maintainability

d. Key technologies & frameworks:
- FastAPI (HTTP server, routing)
- Pydantic (schemas)
- SQLAlchemy or similar ORM (models + CRUD)
- Celery (task queue) + broker (e.g., Redis/RabbitMQ)
- Python compute libraries (e.g., NumPy in compute_Algo)
- External docs / reporting tools (Google Docs, Excalidraw referenced)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Subgraphs
    subgraph "Client"
        Client["Client\n(Web UI / External)"]:::external
    end

    subgraph "Configuration & Utilities" 
        Config["Configuration\n(app/core/config.py)"]:::config
        Utils["URL Resolver\n(app/utils/url_resolver.py)"]:::config
    end

    subgraph "API Layer"
        FastAPIApp["FastAPI App\n(main_rcs.py)"]:::sync
        Routes["Routers\n(reports_rcs.py)"]:::sync
        Controllers["Controllers\n(report_controller.py)"]:::sync
        Schemas["Pydantic Schemas\n(report.py)"]:::sync
    end

    subgraph "Business Logic"
        ServicesCompute["Compute Algorithms\n(compute_Algo.py)"]:::sync
        ServicesReport["Report Service\n(report_service.py)"]:::sync
    end

    subgraph "Data Access Layer"
        Crud["Database CRUD\n(crud.py)"]:::sync
        ModelsBase["ORM Base\n(base.py)"]:::db
        ModelsReport["ORM Report\n(report.py)"]:::db
        DB["Database"]:::db
        StaticReports["Static Reports\n(reports.json)"]:::db
    end

    subgraph "Async Processing"
        CeleryApp["Celery App Factory\n(celery_app.py)"]:::async
        Broker["Broker\n(Redis/RabbitMQ)"]:::external
        Tasks["Celery Tasks\n(report_tasks.py)"]:::async
        Worker["Celery Worker"]:::async
    end

    %% Connections - Sync Path (Blue)
    Client -->|"HTTP Request"| FastAPIApp
    FastAPIApp -->|"mount routes"| Routes
    Routes -->|"invoke"| Controllers
    Controllers -->|"validate"| Schemas
    Controllers -->|"call"| ServicesCompute
    Controllers -->|"call"| ServicesReport
    ServicesCompute -->|"CRUD ops"| Crud
    ServicesReport -->|"CRUD ops"| Crud
    Crud -->|"uses"| ModelsBase
    Crud -->|"uses"| ModelsReport
    ModelsBase --> DB
    ModelsReport --> DB
    StaticReports --> DB

    %% Connections - Async Path (Orange)
    Controllers -->|"enqueue task"| Tasks
    Tasks --> Broker
    Broker --> Worker
    Worker -->|"execute tasks"| CeleryApp
    CeleryApp -->|"imports"| Tasks
    Worker -->|"call"| ServicesCompute
    Worker -->|"call"| ServicesReport
    Worker -->|"CRUD ops"| Crud

    %% Config & Utils usage
    Config --> FastAPIApp
    Config --> CeleryApp
    Utils --> Controllers
    Utils --> ServicesCompute

    %% Click Events
    click FastAPIApp "https://github.com/ypoonia/tryai/blob/main/app/main_rcs.py"
    click Routes "https://github.com/ypoonia/tryai/blob/main/app/routes/reports_rcs.py"
    click Controllers "https://github.com/ypoonia/tryai/blob/main/app/controllers/report_controller.py"
    click Schemas "https://github.com/ypoonia/tryai/blob/main/app/schemas/report.py"
    click ServicesCompute "https://github.com/ypoonia/tryai/blob/main/app/services/compute_Algo.py"
    click ServicesReport "https://github.com/ypoonia/tryai/blob/main/app/services/report_service.py"
    click Crud "https://github.com/ypoonia/tryai/blob/main/app/database/crud.py"
    click ModelsBase "https://github.com/ypoonia/tryai/blob/main/app/models/base.py"
    click ModelsReport "https://github.com/ypoonia/tryai/blob/main/app/models/report.py"
    click CeleryApp "https://github.com/ypoonia/tryai/blob/main/app/celery_app.py"
    click Tasks "https://github.com/ypoonia/tryai/blob/main/app/tasks/report_tasks.py"
    click Config "https://github.com/ypoonia/tryai/blob/main/app/core/config.py"
    click Utils "https://github.com/ypoonia/tryai/blob/main/app/utils/url_resolver.py"
    click StaticReports "https://github.com/ypoonia/tryai/blob/main/reports.json"

    %% Styles
    classDef sync fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef async fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef db fill:#E8F5E9,stroke:#388E3C,color:#000
    classDef config fill:#ECEFF1,stroke:#607D8B,color:#000
    classDef external fill:#CFD8DC,stroke:#455A64,color:#000
```
