# laakmus/shooting-log architecture

> Architecture diagram of the GitHub repository laakmus/shooting-log, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/laakmus/shooting-log
- Repository: https://github.com/laakmus/shooting-log

## Overview

shooting-log is a REST API for recording firearms, training sessions, and ammunition use, then reporting fired-round totals and costs. A client reaches the registered FastAPI routes: weapon and training routes perform CRUD, while training-entry creation validates a weapon and uses domain logic to derive round counts. Statistics and weapon-detail routes call database queries for aggregates. Routers use Pydantic schemas and SQLAlchemy sessions; models define the persisted entities. README documents the capabilities, while the sampled source clarifies their wiring.

Main entry points: [`src/database.py`](https://github.com/laakmus/shooting-log/blob/main/src/database.py) (Session and engine), [`src/routers/weapons.py`](https://github.com/laakmus/shooting-log/blob/main/src/routers/weapons.py) (Weapon routes), [`src/routers/training.py`](https://github.com/laakmus/shooting-log/blob/main/src/routers/training.py) (Training routes), [`src/main.py`](https://github.com/laakmus/shooting-log/blob/main/src/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app["FastAPI app<br/>[main.py]"]
  node_weapon_routes["Weapon routes<br/>[weapons.py]"]
  node_training_routes["Training routes<br/>[training.py]"]
  node_stats_routes["Statistics route<br/>[stats.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
end

subgraph group_domain["Domain Logic"]
  node_rounds["Round calculation<br/>[services.py]"]
end

subgraph group_persistence["Persistence and Queries"]
  node_queries["Aggregate queries<br/>[queries.py]"]
  node_database["Session and engine<br/>[database.py]"]
  node_config["Application settings<br/>[config.py]"]
  node_models["ORM entities<br/>[models.py]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_app
node_app -->|"dispatches"| node_weapon_routes
node_app -->|"dispatches"| node_training_routes
node_app -->|"dispatches"| node_stats_routes
node_weapon_routes -->|"validates and shapes"| node_schemas
node_training_routes -->|"validates and shapes"| node_schemas
node_stats_routes -->|"shapes response"| node_schemas
node_training_routes -->|"calculates rounds"| node_rounds
node_weapon_routes -->|"counts rounds"| node_queries
node_stats_routes -->|"loads cost totals"| node_queries
node_weapon_routes -->|"uses session"| node_database
node_training_routes -->|"uses session"| node_database
node_stats_routes -->|"uses session"| node_database
node_queries -->|"executes queries"| node_database
node_database -->|"loads connection settings"| node_config
node_models -->|"uses declarative base"| node_database
node_weapon_routes -->|"reads and writes"| node_models
node_training_routes -->|"reads and writes"| node_models
node_queries -->|"aggregates entities"| node_models
node_database -->|"connects"| node_postgres

click node_app "https://github.com/laakmus/shooting-log/blob/main/src/main.py"
click node_weapon_routes "https://github.com/laakmus/shooting-log/blob/main/src/routers/weapons.py"
click node_training_routes "https://github.com/laakmus/shooting-log/blob/main/src/routers/training.py"
click node_stats_routes "https://github.com/laakmus/shooting-log/blob/main/src/routers/stats.py"
click node_schemas "https://github.com/laakmus/shooting-log/blob/main/src/schemas.py"
click node_rounds "https://github.com/laakmus/shooting-log/blob/main/src/services.py"
click node_queries "https://github.com/laakmus/shooting-log/blob/main/src/queries.py"
click node_database "https://github.com/laakmus/shooting-log/blob/main/src/database.py"
click node_config "https://github.com/laakmus/shooting-log/blob/main/src/config.py"
click node_models "https://github.com/laakmus/shooting-log/blob/main/src/models.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_app,node_weapon_routes,node_training_routes,node_stats_routes,node_schemas,node_client toneBlue
class node_rounds,node_postgres toneAmber
class node_queries,node_database,node_config,node_models toneMint
```

## Components

### HTTP API

- [FastAPI app](https://github.com/laakmus/shooting-log/blob/main/src/main.py): `src/main.py`
- [Weapon routes](https://github.com/laakmus/shooting-log/blob/main/src/routers/weapons.py): `src/routers/weapons.py`
- [Training routes](https://github.com/laakmus/shooting-log/blob/main/src/routers/training.py): `src/routers/training.py`
- [Statistics route](https://github.com/laakmus/shooting-log/blob/main/src/routers/stats.py): `src/routers/stats.py`
- [Request and response schemas](https://github.com/laakmus/shooting-log/blob/main/src/schemas.py): `src/schemas.py`

### Domain Logic

- [Round calculation](https://github.com/laakmus/shooting-log/blob/main/src/services.py): `src/services.py`

### Persistence and Queries

- [Aggregate queries](https://github.com/laakmus/shooting-log/blob/main/src/queries.py): `src/queries.py`
- [Session and engine](https://github.com/laakmus/shooting-log/blob/main/src/database.py): `src/database.py`
- [Application settings](https://github.com/laakmus/shooting-log/blob/main/src/config.py): `src/config.py`
- [ORM entities](https://github.com/laakmus/shooting-log/blob/main/src/models.py): `src/models.py`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → FastAPI app: sends requests
- FastAPI app → Weapon routes: dispatches
- FastAPI app → Training routes: dispatches
- FastAPI app → Statistics route: dispatches
- Weapon routes → Request and response schemas: validates and shapes
- Training routes → Request and response schemas: validates and shapes
- Statistics route → Request and response schemas: shapes response
- Training routes → Round calculation: calculates rounds
- Weapon routes → Aggregate queries: counts rounds
- Statistics route → Aggregate queries: loads cost totals
- Weapon routes → Session and engine: uses session
- Training routes → Session and engine: uses session
- Statistics route → Session and engine: uses session
- Aggregate queries → Session and engine: executes queries
- Session and engine → Application settings: loads connection settings
- ORM entities → Session and engine: uses declarative base
- Weapon routes → ORM entities: reads and writes
- Training routes → ORM entities: reads and writes
- Aggregate queries → ORM entities: aggregates entities
- Session and engine → PostgreSQL: connects
