# allanamrtins/trabalho-final---es2 architecture

> Architecture diagram of the GitHub repository allanamrtins/trabalho-final---es2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/allanamrtins/trabalho-final---es2
- Repository: https://github.com/allanamrtins/trabalho-final---es2

## Overview

Afim Quest is a gamified learning platform for practicing affine functions, with teacher-managed activities and a FastAPI backend. Students authenticate, browse missions, submit answers for automatic correction and feedback, then review performance and gamification progress; teachers create and manage activities. The README documents a web interface, layered services and repositories, and SQLite persistence. Sampled source confirms the main API-to-service-to-domain/repository paths; other documented capabilities are included, but their unsampled implementation links are not asserted.

Main entry points: [`app/main.py`](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/main.py) (API entry), [`app/services/resposta_service.py`](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/resposta_service.py) (Answer and performance), [`app/services/atividade_service.py`](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/atividade_service.py) (Activity management), [`app/models.py`](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/models.py) (ORM entities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Users and interface"]
  node_web["Web interface<br/>[index.html]"]
end

subgraph group_api["HTTP API"]
  node_entry["API entry<br/>[main.py]"]
  node_auth_api["Authentication API<br/>[auth.py]"]
  node_activity_api["Activity API<br/>[atividades.py]"]
  node_function_api["Function API<br/>[funcoes.py]"]
  node_answer_api["Answer API<br/>[respostas.py]"]
  node_game_api["Gamification API<br/>[gamificacao.py]"]
end

subgraph group_application["Application and domain"]
  node_auth_access["Access control<br/>[deps.py]"]
  node_user_service["User accounts<br/>[usuario_service.py]"]
  node_activity_service["Activity management"]
  node_answer_service["Answer and performance"]
  node_game_service["Progress and ranking"]
  node_math_domain["Affine math<br/>[funcao_afim.py]"]
  node_game_domain["Gamification rules<br/>[gamificacao.py]"]
  node_schemas["API contracts<br/>[schemas.py]"]
  node_security["Token security<br/>[security.py]"]
end

subgraph group_persistence["Persistence"]
  node_activity_repo["Activity repository"]
  node_answer_repo["Response repository"]
  node_user_repo["User repository"]
  node_models["ORM entities<br/>[models.py]"]
  node_database[("SQLite database<br/>[database.py]")]
end

node_student(("Student"))
node_teacher(("Teacher"))

node_student -->|"uses"| node_web
node_teacher -->|"uses"| node_web
node_web -->|"sends HTTP/JSON"| node_entry
node_entry -->|"registers routes"| node_auth_api
node_entry -->|"registers routes"| node_activity_api
node_entry -->|"registers routes"| node_function_api
node_entry -->|"registers routes"| node_answer_api
node_entry -->|"registers routes"| node_game_api
node_auth_api -->|"delegates to"| node_user_service
node_activity_api -->|"delegates to"| node_activity_service
node_function_api -->|"uses"| node_math_domain
node_answer_api -->|"delegates to"| node_answer_service
node_game_api -->|"delegates to"| node_game_service
node_auth_access -->|"decodes tokens"| node_security
node_auth_access -->|"looks up user"| node_user_repo
node_activity_service -->|"uses"| node_activity_repo
node_activity_service -->|"calculates answers"| node_math_domain
node_answer_service -->|"loads activity"| node_activity_service
node_answer_service -->|"records and queries"| node_answer_repo
node_answer_service -->|"checks and advises"| node_math_domain
node_answer_service -->|"calculates XP"| node_game_domain
node_game_service -->|"reads results"| node_answer_repo
node_game_service -->|"computes progress"| node_game_domain
node_user_service -->|"uses"| node_user_repo
node_user_service -->|"uses"| node_security
node_activity_repo -->|"persists activities"| node_models
node_answer_repo -->|"queries responses"| node_models
node_user_repo -->|"queries users"| node_models
node_models -->|"maps entities"| node_database
node_entry -->|"creates tables"| node_database
node_activity_api -->|"validates payloads"| node_schemas
node_answer_api -->|"validates payloads"| node_schemas
node_game_api -->|"formats responses"| node_schemas

click node_web "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/static/index.html"
click node_entry "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/main.py"
click node_auth_api "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/auth.py"
click node_activity_api "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/atividades.py"
click node_function_api "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/funcoes.py"
click node_answer_api "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/respostas.py"
click node_game_api "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/gamificacao.py"
click node_auth_access "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/deps.py"
click node_user_service "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/usuario_service.py"
click node_activity_service "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/atividade_service.py"
click node_answer_service "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/resposta_service.py"
click node_game_service "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/gamificacao_service.py"
click node_math_domain "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/domain/funcao_afim.py"
click node_game_domain "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/domain/gamificacao.py"
click node_schemas "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/schemas.py"
click node_activity_repo "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/repositories/atividade_repository.py"
click node_answer_repo "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/repositories/resposta_repository.py"
click node_user_repo "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/repositories/usuario_repository.py"
click node_models "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/models.py"
click node_database "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/core/database.py"
click node_security "https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/core/security.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web toneBlue
class node_entry,node_auth_api,node_activity_api,node_function_api,node_answer_api,node_game_api toneAmber
class node_auth_access,node_user_service,node_activity_service,node_answer_service,node_game_service,node_math_domain,node_game_domain,node_schemas,node_security toneMint
class node_activity_repo,node_answer_repo,node_user_repo,node_models,node_database toneRose
class node_student,node_teacher toneIndigo
```

## Components

### Users and interface

- [Web interface](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/static/index.html): `app/static/index.html`

### HTTP API

- [API entry](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/main.py): `app/main.py`
- [Authentication API](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/auth.py): `app/api/auth.py`
- [Activity API](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/atividades.py): `app/api/atividades.py`
- [Function API](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/funcoes.py): `app/api/funcoes.py`
- [Answer API](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/respostas.py): `app/api/respostas.py`
- [Gamification API](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/gamificacao.py): `app/api/gamificacao.py`

### Application and domain

- [Access control](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/api/deps.py): `app/api/deps.py`
- [User accounts](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/usuario_service.py): `app/services/usuario_service.py`
- [Activity management](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/atividade_service.py): `app/services/atividade_service.py`
- [Answer and performance](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/resposta_service.py): `app/services/resposta_service.py`
- [Progress and ranking](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/services/gamificacao_service.py): `app/services/gamificacao_service.py`
- [Affine math](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/domain/funcao_afim.py): `app/domain/funcao_afim.py`
- [Gamification rules](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/domain/gamificacao.py): `app/domain/gamificacao.py`
- [API contracts](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/schemas.py): `app/schemas.py`
- [Token security](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/core/security.py): `app/core/security.py`

### Persistence

- [Activity repository](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/repositories/atividade_repository.py): `app/repositories/atividade_repository.py`
- [Response repository](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/repositories/resposta_repository.py): `app/repositories/resposta_repository.py`
- [User repository](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/repositories/usuario_repository.py): `app/repositories/usuario_repository.py`
- [ORM entities](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/models.py): `app/models.py`
- [SQLite database](https://github.com/allanamrtins/trabalho-final---es2/blob/main/app/core/database.py): `app/core/database.py`

### Other components

- **Student**
- **Teacher**

## Connections

- Student → Web interface: uses (evidence: `README.md`)
- Teacher → Web interface: uses (evidence: `README.md`)
- Web interface → API entry: sends HTTP/JSON (evidence: `README.md`)
- API entry → Authentication API: registers routes (evidence: `app/main.py`)
- API entry → Activity API: registers routes (evidence: `app/main.py`)
- API entry → Function API: registers routes (evidence: `app/main.py`)
- API entry → Answer API: registers routes (evidence: `app/main.py`)
- API entry → Gamification API: registers routes (evidence: `app/main.py`)
- Authentication API → User accounts: delegates to (evidence: `app/api/auth.py`)
- Activity API → Activity management: delegates to (evidence: `app/api/atividades.py`)
- Function API → Affine math: uses (evidence: `app/api/funcoes.py`)
- Answer API → Answer and performance: delegates to (evidence: `app/api/respostas.py`)
- Gamification API → Progress and ranking: delegates to (evidence: `app/api/gamificacao.py`)
- Access control → Token security: decodes tokens (evidence: `app/api/deps.py`)
- Access control → User repository: looks up user (evidence: `app/api/deps.py`)
- Activity management → Activity repository: uses (evidence: `app/services/atividade_service.py`)
- Activity management → Affine math: calculates answers (evidence: `app/services/atividade_service.py`)
- Answer and performance → Activity management: loads activity (evidence: `app/services/resposta_service.py`)
- Answer and performance → Response repository: records and queries (evidence: `app/services/resposta_service.py`)
- Answer and performance → Affine math: checks and advises (evidence: `app/services/resposta_service.py`)
- Answer and performance → Gamification rules: calculates XP (evidence: `app/services/resposta_service.py`)
- Progress and ranking → Response repository: reads results (evidence: `app/services/gamificacao_service.py`)
- Progress and ranking → Gamification rules: computes progress (evidence: `app/services/gamificacao_service.py`)
- User accounts → User repository: uses (evidence: `app/services/usuario_service.py`)
- User accounts → Token security: uses (evidence: `app/services/usuario_service.py`)
- Activity repository → ORM entities: persists activities (evidence: `README.md`)
- Response repository → ORM entities: queries responses (evidence: `app/repositories/resposta_repository.py`)
- User repository → ORM entities: queries users (evidence: `app/repositories/usuario_repository.py`)
- ORM entities → SQLite database: maps entities (evidence: `app/models.py`)
- API entry → SQLite database: creates tables (evidence: `app/main.py`)
- Activity API → API contracts: validates payloads (evidence: `README.md`)
- Answer API → API contracts: validates payloads (evidence: `README.md`)
- Gamification API → API contracts: formats responses (evidence: `README.md`)
