# wester35/yadro-test-task architecture

> Architecture diagram of the GitHub repository wester35/yadro-test-task, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wester35/yadro-test-task
- Repository: https://github.com/wester35/yadro-test-task

## Overview

##### Project type and purpose
- This is a full-stack Django web application packaged with Docker Compose.
- It provides a UI (HTML templates) to load user data from an external API into a PostgreSQL database, list users in a paginated table, and view individual or random user details.

##### File structure
- Top‐level “task/” directory contains:
– Docker-related files: Dockerfile, .dockerignore, docker-compose.yml
– manage.py, pytest.ini, requirements.txt
– Django project folder “task/task/” with settings, ASGI/WGI, URLs
– Two Django apps:
- api/ — models, views (REST endpoints?), load_users script, tests
- frontend/ — views, templates, URL routing, tables, tests
– templates/frontend/ — index.html, user_detail.html
- docker-compose.yml defines two services: “web” (Django container) and “db” (PostgreSQL).

##### README for additional insights
- The app listens on port 8008, auto-runs pytest on startup.
- Explains how to spin up Docker Compose, run migrations, create superusers.
- Describes three user‐facing pages (main list, individual user, random user).

a. Main components
– Browser (client)
– Docker Compose orchestrator
– “web” container:
- Django project (Monolithic container)
· URL router (task/urls.py)
· Frontend app (views → templates → HTTP responses)
· API app (management command load_users, models, internal REST/API endpoints)
· ORM models → PostgreSQL
· Signals (e.g., post_save hooks)
– “db” container (PostgreSQL)
– External User API (third-party service from which load_users fetches data)

b. Relationships & data flow
1. Browser issues HTTP requests → web container (port 8008).
2. Django URL router dispatches to:
- Frontend.views → templates for rendering HTML
- API.load_users (management command invoked by user action or CI)
3. Django ORM issues SQL queries → PostgreSQL container.
4. load_users script issues HTTPS calls → External User API → returns JSON → parsed → ORM → DB.
5. Tests (pytest) run inside web container against both apps.

c. Architectural patterns / design principles
- Layered MVC (models, views, templates)
- Monolith container with two logical modules (api and frontend)
- External-service integration (the user data API)
- Infrastructure as code (Dockerfile, docker-compose.yml)

d. Relevant technologies / frameworks
- Python 3.x, Django
- Docker, Docker Compose
- PostgreSQL
- pytest (testing)
- Django ORM, Django signals

##### Detail
– URL Dispatcher
– frontend/views.py → templates
– api/load_users.py & api/views.py
– models.py (shared by both apps)
– signals.py
- That docker-compose.yml wires “web” and “db” with a named Docker network.
- Commands triggered on startup (pytest, migrations).

## Diagram (Mermaid)

```mermaid
flowchart TB
    Browser["Browser"]:::client
    Browser -->|"HTTP (port 8008)"| WebContainer

    subgraph "Docker Compose Orchestrator"
        direction TB
        WebContainer["web container (Django)"]:::container
        DBContainer["db container (PostgreSQL)"]:::database
    end

    ExternalAPI["External User API"]:::external
    WebContainer -->|"HTTPS"| ExternalAPI
    WebContainer -->|"SQL (port 5432)"| DBContainer

    Tests["pytest suite"]:::test
    Tests -->|runs inside| WebContainer

    subgraph "web container"
        direction TB
        Manage["manage.py"]:::entry
        Urls["URL Dispatcher\n(task/task/urls.py)"]:::component

        subgraph "Django Apps"
            direction TB

            subgraph "Frontend App"
                direction TB
                FE_Views["frontend/views.py"]:::frontend
                FE_Urls["frontend/urls.py"]:::frontend
                FE_Tables["frontend/tables.py"]:::frontend
                FE_Models["frontend/models.py"]:::model
                Templates["Templates\nindex.html\nuser_detail.html"]:::template
            end

            subgraph "API App"
                direction TB
                LoadCmd["api/load_users.py"]:::api
                API_Views["api/views.py"]:::api
                API_Models["api/models.py"]:::model
                Signals["api/signals.py"]:::component
            end

        end
    end

    Urls -->|routes to| FE_Views
    Urls -->|routes to| API_Views
    FE_Views -->|renders| Templates
    FE_Views -->|uses| FE_Models
    API_Views -->|uses| API_Models
    LoadCmd -->|fetches data| ExternalAPI
    LoadCmd -->|populates| API_Models
    FE_Models -->|queries| DBContainer
    API_Models -->|queries| DBContainer
    Signals -->|post_save hooks| API_Models

    %% Click Events
    click WebContainer "https://github.com/wester35/yadro-test-task/blob/main/task/docker-compose.yml"
    click WebContainer "https://github.com/wester35/yadro-test-task/tree/main/task/Dockerfile"
    click WebContainer "https://github.com/wester35/yadro-test-task/blob/main/task/.dockerignore"
    click Manage "https://github.com/wester35/yadro-test-task/blob/main/task/manage.py"
    click Urls "https://github.com/wester35/yadro-test-task/blob/main/task/task/urls.py"
    click FE_Views "https://github.com/wester35/yadro-test-task/blob/main/task/frontend/views.py"
    click FE_Urls "https://github.com/wester35/yadro-test-task/blob/main/task/frontend/urls.py"
    click FE_Tables "https://github.com/wester35/yadro-test-task/blob/main/task/frontend/tables.py"
    click FE_Models "https://github.com/wester35/yadro-test-task/blob/main/task/frontend/models.py"
    click Templates "https://github.com/wester35/yadro-test-task/blob/main/task/templates/frontend/index.html"
    click Templates "https://github.com/wester35/yadro-test-task/blob/main/task/templates/frontend/user_detail.html"
    click LoadCmd "https://github.com/wester35/yadro-test-task/blob/main/task/api/load_users.py"
    click API_Views "https://github.com/wester35/yadro-test-task/blob/main/task/api/views.py"
    click API_Models "https://github.com/wester35/yadro-test-task/blob/main/task/api/models.py"
    click Signals "https://github.com/wester35/yadro-test-task/blob/main/task/api/signals.py"
    click Tests "https://github.com/wester35/yadro-test-task/blob/main/task/pytest.ini"
    click Tests "https://github.com/wester35/yadro-test-task/blob/main/task/api/tests.py"
    click Tests "https://github.com/wester35/yadro-test-task/blob/main/task/frontend/tests.py"
    click DBContainer "https://github.com/wester35/yadro-test-task/blob/main/task/requirements.txt"

    classDef client fill:#AEDFF7,stroke:#0366d6,color:#0366d6
    classDef container fill:#E2E8F0,stroke:#4A5568,color:#2D3748
    classDef database fill:#F7FAFC,stroke:#2D3748,stroke-width:2px
    classDef external fill:#FFF5E6,stroke:#D69E2E,color:#B7791F
    classDef entry fill:#C6F6D5,stroke:#2F855A,color:#276749
    classDef component fill:#E9D8FD,stroke:#6B46C1,color:#553C9A
    classDef frontend fill:#BEE3F8,stroke:#3182CE,color:#2B6CB0
    classDef api fill:#FED7D7,stroke:#C53030,color:#9B2C2C
    classDef model fill:#F0FFF4,stroke:#38A169,color:#2F855A
    classDef template fill:#FFF0F6,stroke:#D53F8C,color:#97266D
    classDef test fill:#FFF3BF,stroke:#D97706,color:#92400E
```
