# yenchenliu/workforce architecture

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

- Interactive diagram: https://gitdiagram.com/yenchenliu/workforce
- Repository: https://github.com/yenchenliu/workforce

## Overview

##### Project Type and Purpose
- This is a Django-based, RESTful workforce scheduling application (monolithic backend API).
- Its core responsibility is to expose an “assign-tasks” endpoint that uses linear programming to produce optimal worker-task assignments and return KPI data.

##### File Structure
Top-level directories/files:
- .github/workflows/ci.yml – CI pipeline definition
- manage.py – Django CLI entry point
- requirements.txt / requirements.in – Python dependencies
- mypy.ini – static-type check config
- seed_data/…json – initial data for positions, tasks, workers, assignments
- workforce/ – Django project settings, ASGI/WGI and URL routing
- assignments/ – Django app containing models, services, API, schemas, migrations, tests, and a custom management command

##### README for Additional Insights
- Confirms Python 3.12+, Django 5.0+
- Describes CLI commands (migrate, load_seed_data, runserver)
- Mentions built-in API docs at `/api/docs`
- Highlights the `assign-tasks` linear-programming service

a. Client Layer
- Web or API client (e.g. browser calling `/api/docs`, third-party scheduler clients)
b. API/Web Layer
- ASGI/WGSI server (e.g. Daphne or Gunicorn)
- Django URL router (workforce/urls.py)
- DRF (or Django generic views) endpoints in assignments/api.py
c. Business-Logic Layer
- Service module (`assignments/services.py`) implementing the linear programming solver
- Schemas or serializers (`assignments/schemas.py`) for input/output validation
d. Data-Access Layer
- Django ORM models (`assignments/models.py`)
- Migrations for schema evolution (`assignments/migrations/…`)
e. Persistence
- Relational database (PostgreSQL, MySQL, or SQLite in dev)
f. Initialization & DevOps
- Management command (`load_seed_data`) to populate seed_data/*.json into the database
- CI pipeline (.github/workflows/ci.yml) running tests and type checks
g. External Libraries/Services
- Linear-programming library (PuLP, OR-Tools or similar, listed in requirements.txt)
- Third-party dependencies (Django, DRF, database driver)

##### Relationships and Data Flows
- Client → HTTP → ASGI/WGSI server
- Server → URL router → View/API endpoint
- View → Schemas/Serializers (validate request)
- View → Services (invoke LP solver, business rules)
- Services → ORM (read/write assignments, tasks, worker capacities)
- ORM → Database (CRUD operations)
- Service returns results → Serializer → HTTP Response → Client

##### Architectural Patterns and Design Principles
- Layered architecture (Presentation → API → Services → Data Access → Persistence)
- Single-responsibility modules: separate modules for API, business logic, data models, schemas
- Use of Django’s management-command pattern for one-off tasks (seed data)
- Configuration-as-code (settings.py, CI YAML)
- Type safety and static analysis (mypy.ini)
- Test-driven development (assignments/tests.py + codecov integration)

2. Next row: Load balancer (optional) → ASGI Server (Gunicorn/Daphne)
3. Middle: Django core layers—URL router → API view → serializer → services → ORM
4. Bottom: Database, LP library
5. Side: Management commands and CI workflow

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        Client["API Clients\n(e.g. Browser,\nScheduler)"]:::external
    end

    Client -->|"HTTP Request"| ASGI
    Client -->|"HTTP Request"| WSGI

    ASGI["ASGI Server"]:::framework
    WSGI["WSGI Server"]:::framework
    ASGI -->|"calls"| URLRouter
    WSGI -->|"calls"| URLRouter

    ProjectSettings["Project Settings"]:::framework
    ASGI --> ProjectSettings
    WSGI --> ProjectSettings

    URLRouter["URL Router"]:::framework
    URLRouter -->|"routes to"| APIView

    APIView["assign-tasks API Endpoint"]:::custom
    APIView -->|"uses"| Serializer

    Serializer["Schemas/Serializers"]:::custom
    Serializer -->|"validates & passes"| Service

    Service["LP Solver Service"]:::custom
    Service -->|"reads/writes"| Models
    Service -->|"invokes"| LP

    Models["ORM Models"]:::custom
    Models -->|"db ops"| DB
    Models -->|"schema evolution"| Migrations

    DB["Relational Database\n(PostgreSQL)"]:::external
    LP["LP Library\n(PuLP/OR-Tools)"]:::external
    Migrations["Database Migrations"]:::custom

    subgraph "Maintenance & DevOps"
        ManagePy["manage.py"]:::framework
        SeedLoader["Seed Data Loader\n(Command)"]:::tool
        SeedData["Seed Data\n(JSON fixtures)"]:::tool
        CIPipeline["CI Pipeline"]:::tool
        TestSuite["Test Suite"]:::tool
        TypeCheck["Type Checking\n(mypy.ini)"]:::tool
        Dependencies["Dependencies\n(req.in & req.txt)"]:::tool
        AppConfig["App Registration"]:::custom

        ManagePy -->|"runs migrations"| Migrations
        ManagePy -->|"runs seed loader"| SeedLoader
        SeedLoader -->|"loads"| SeedData
        SeedLoader -->|"populates"| DB

        CIPipeline -->|"runs tests"| TestSuite
        CIPipeline -->|"runs type checks"| TypeCheck
        CIPipeline -->|"verifies deps"| Dependencies
    end

    click ASGI "https://github.com/yenchenliu/workforce/blob/main/workforce/asgi.py"
    click WSGI "https://github.com/yenchenliu/workforce/blob/main/workforce/wsgi.py"
    click URLRouter "https://github.com/yenchenliu/workforce/blob/main/workforce/urls.py"
    click ProjectSettings "https://github.com/yenchenliu/workforce/blob/main/workforce/settings.py"
    click ManagePy "https://github.com/yenchenliu/workforce/blob/main/manage.py"
    click APIView "https://github.com/yenchenliu/workforce/blob/main/assignments/api.py"
    click Service "https://github.com/yenchenliu/workforce/blob/main/assignments/services.py"
    click Serializer "https://github.com/yenchenliu/workforce/blob/main/assignments/schemas.py"
    click Models "https://github.com/yenchenliu/workforce/blob/main/assignments/models.py"
    click Migrations "https://github.com/yenchenliu/workforce/tree/main/assignments/migrations/"
    click SeedLoader "https://github.com/yenchenliu/workforce/blob/main/assignments/management/commands/load_seed_data.py"
    click SeedData "https://github.com/yenchenliu/workforce/tree/main/seed_data/"
    click CIPipeline "https://github.com/yenchenliu/workforce/blob/main/.github/workflows/ci.yml"
    click Dependencies "https://github.com/yenchenliu/workforce/blob/main/requirements.txt"
    click TypeCheck "https://github.com/yenchenliu/workforce/blob/main/mypy.ini"
    click AppConfig "https://github.com/yenchenliu/workforce/blob/main/assignments/apps.py"
    click TestSuite "https://github.com/yenchenliu/workforce/blob/main/assignments/tests.py"

    classDef framework fill:#cce5ff,stroke:#004085,color:#004085
    classDef custom fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef tool fill:#f8d7da,stroke:#721c24,color:#721c24,stroke-dasharray: 5 5
```
