How temirlan-k/ollama-app works
Project type and purpose
• This is a backend-only web service implementing Clean Architecture in Python.
• Purpose: provide AI-powered analytics, request processing, and user services via HTTP (REST & GraphQL), backed by multiple data stores, caching, LLM provider integration, observability, and security.
File structure
• Four clean layers under src/:
• domain/ (entities, interfaces, exceptions)
• application/ (analytics_service, request_service, user_service)
• infra/ (db: PostgreSQL, MongoDB, Redis; llm_provider; prometheus; grafana; security; sentry)
• presentation/ (API entrypoints: REST v1, GraphQL; Pydantic schemas)
• bootstrap/ holds DI container, configuration, logging, and main.py as entry point.
• Top-level orchestrators: Dockerfile, docker-compose.yml, Makefile, Alembic migrations, requirements.txt.
• tests/ exercise domain and application layers with mocks and real DBs.
README for additional insights
• Confirms Clean Architecture: Domain → Application → Infrastructure → Presentation.
• Names key patterns: Dependency Injection (DIContainer), Repository, Unit of Work, Factory.
• Lists external dependencies: PostgreSQL, MongoDB, Redis, FastAPI, JWT, Ollama (LLM), Prometheus, Grafana, Sentry.
Main components and interactions
a. Components:
• Presentation Layer:
• REST API (FastAPI Controllers)
• GraphQL API (Resolvers & Schemas)
• Application Layer:
• AnalyticsService
• RequestService
• UserService
• Domain Layer:
• Entities (User, Request, Chat, LLMResponse, Analytics)
• Interfaces (AnalyticsPort, LLMP ort, …)
• Infrastructure Layer:
• PostgreSQL (UserRepo, RequestRepo, UoW)
• MongoDB (AnalyticsRepo)
• Redis Cache (CacheDecorator)
• LLM Provider (Ollama)
• Security (JWT handler, password hashing)
• Observability (Prometheus middleware/metrics, Grafana dashboards, Sentry)
• Bootstrap & Orchestration:
• DI Container wiring
• Configuration & Logging
• main.py → FastAPI app
b. Relationships & data flows:
• HTTP Request → Presentation (REST/GraphQL) → invokes ApplicationService
• ApplicationService uses Domain Interfaces and Entities
• DI Container injects concrete Infra implementations of Interfaces
• Repositories/UoW coordinate transactions with PostgreSQL/MongoDB/Redis
• LLMProvider calls external LLM model
• Prometheus middleware collects metrics, Grafana reads from Prometheus, Sentry captures errors
• Responses flow back to Presentation → HTTP Response
c. Architectural patterns & principles:
• Layered Clean Architecture with strict inward dependencies
• Dependency Injection: DIContainer creates/injects all dependencies
• Repository & Unit of Work for data access and transactional boundaries
• Factory pattern inside DI for complex object creation
• SOLID principles in service and domain code
d. Key technologies & frameworks:
• FastAPI (presentation)
• SQLAlchemy + Alembic (PostgreSQL UoW & migrations)
• Motor or PyMongo (MongoDB)
• Redis-py (Redis cache)
• Ollama client (LLMProvider)
• Prometheus client + Grafana (monitoring)
• dependency-injector (DI)
• PyJWT (JWT auth)
• Sentry SDK (error tracking)
Final checklist for the principal software engineer
• Layer and component is labeled with its filesystem path (e.g., src/presentation/api/rest/v1).
• External dependencies and how traffic/data flows in and out.
• DIContainer as the orchestration point.
• Observability services (Prometheus → Grafana, Sentry) and security (JWT) as side-cars or external nodes.