# tgosts/grnaproject architecture

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

- Interactive diagram: https://gitdiagram.com/tgosts/grnaproject
- Repository: https://github.com/tgosts/grnaproject

## Overview

##### Project Type and Purpose
- This is a standalone Java demo application (“Jogo demonstrativo com RNA”) combining a simple 2D game engine (package `src.Jogo`) with an in-house neural network library (package `src.neuralNetwork`).
- The game (player, enemies, shooting) leverages the neural network for AI decision-making or training scenarios, using external data files (`src/data`).

##### High-Level Architecture
The system naturally splits into four logical layers/modules:
a) Game Engine Module (`src/Jogo`)
b) Neural Network Module (`src/neuralNetwork`)
c) Data Module (`src/data`)
d) Utility/Configuration Module (`src/util`)

##### Main Components & Responsibilities
- Game Engine
- Classes: `Ambiente`, `Jogador`, `Inimigo`, `Tiro`, plus `teste` as an entry point.
- Responsibilities: game loop, rendering (if any), input handling, entity management.
- Interaction: At each tick, gathers state vectors, forwards them to the Neural Network Module for action decisions.
- Neural Network
- Classes: `Rede` (network), `Camada` (layer), `Neuronio`, `Backpropagation`, `Funcao`, `FuncaoAtivacao`.
- Responsibilities: model definition, forward propagation (inference), backpropagation (training), activation functions.
- Interaction:
– **Training**: reads data from Data Module via `Properties` config (paths to `dataInTreino.txt`), performs weight updates.
– **Inference**: receives real-time game state, outputs control signals for game entities.
- Data Module
- Files: `dataIn.txt`, `dataInTreino.txt` (both in `src/data` and mirrored in `bin/data`).
- Responsibilities: store raw feature vectors for training and testing.
- Interaction: consumed by Neural Network during initialization/training.
- Utility Module
- Class: `Properties` – centralizes configuration (e.g., learning rate, epoch count, file paths).
- Responsibilities: load `.properties` or custom config, pass parameters to Neural Network and Game Engine.

##### Relationships & Data Flows
- At startup, `teste.java` (or a main wrapper) loads configuration via `util.Properties`.
- `neuralNetwork.Rede` is instantiated with settings from `Properties`, optionally pre-trained or freshly initialized.
- If training mode is enabled, `Backpropagation` reads `dataInTreino.txt` → adjusts weights in `Rede`.
- Game loop (`Ambiente`) queries `Rede` with current sensor readings → obtains outputs for `Jogador` or `Inimigo` actions.
- Results propagate back to `Ambiente`, which updates game state.

##### Architectural Patterns & Design Principles
- Layered Architecture: clear separation between Presentation/Game Logic, Business Logic/AI, and Data Access.
- Single Responsibility: each package/class has a narrowly defined role (e.g., `FuncaoAtivacao` only implements activation functions).
- Dependency Injection via `Properties`: decouple hard-coded paths and parameters.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Utility Module
    subgraph "Utility Module" 
        Properties["Properties"]:::util
    end

    %% Data Module
    subgraph "Data Module" 
        dataIn["dataIn.txt"]:::data
        dataTrain["dataInTreino.txt"]:::data
    end

    %% Neural Network Module
    subgraph "Neural Network Module"
        Rede["Rede"]:::nn
        Camada["Camada"]:::nn
        Neuronio["Neuronio"]:::nn
        Backpropagation["Backpropagation"]:::nn
        FuncaoAtivacao["FuncaoAtivacao"]:::nn
        Funcao["Funcao"]:::nn
    end

    %% Game Engine Module
    subgraph "Game Engine Module"
        teste["teste"]:::game
        Ambiente["Ambiente"]:::game
        Jogador["Jogador"]:::game
        Inimigo["Inimigo"]:::game
        Tiro["Tiro"]:::game
    end

    %% Build Output
    subgraph "Build Artifacts"
        binJogo["bin/Jogo"]:::build
        binNN["bin/neuralNetwork"]:::build
        binData["bin/data"]:::data
        binUtil["bin/util"]:::build
    end

    %% Interactions
    Properties -->|"config params"| Rede
    Properties -->|"config params"| teste
    dataIn -->|"training data"| Backpropagation
    dataTrain -->|"training data"| Backpropagation
    Backpropagation -->|"weight updates"| Rede
    teste -->|"starts"| Ambiente
    Ambiente -->|"feature vector"| Rede
    Rede -->|"control signals"| Ambiente
    Ambiente -->|"updates entities"| Jogador
    Ambiente -->|"updates entities"| Inimigo
    Ambiente -->|"updates entities"| Tiro

    %% Build Process
    Properties --> binUtil
    Rede --> binNN
    Camada --> binNN
    Neuronio --> binNN
    Backpropagation --> binNN
    FuncaoAtivacao --> binNN
    Funcao --> binNN
    Ambiente --> binJogo
    Jogador --> binJogo
    Inimigo --> binJogo
    Tiro --> binJogo
    teste --> binJogo
    dataIn --> binData
    dataTrain --> binData

    %% Click Events
    click Properties "https://github.com/tgosts/grnaproject/blob/master/src/util/Properties.java"
    click dataIn "https://github.com/tgosts/grnaproject/blob/master/src/data/dataIn.txt"
    click dataTrain "https://github.com/tgosts/grnaproject/blob/master/src/data/dataInTreino.txt"
    click teste "https://github.com/tgosts/grnaproject/blob/master/src/Jogo/teste.java"
    click Ambiente "https://github.com/tgosts/grnaproject/blob/master/src/Jogo/Ambiente.java"
    click Jogador "https://github.com/tgosts/grnaproject/blob/master/src/Jogo/Jogador.java"
    click Inimigo "https://github.com/tgosts/grnaproject/blob/master/src/Jogo/Inimigo.java"
    click Tiro "https://github.com/tgosts/grnaproject/blob/master/src/Jogo/Tiro.java"
    click Rede "https://github.com/tgosts/grnaproject/blob/master/src/neuralNetwork/Rede.java"
    click Camada "https://github.com/tgosts/grnaproject/blob/master/src/neuralNetwork/Camada.java"
    click Neuronio "https://github.com/tgosts/grnaproject/blob/master/src/neuralNetwork/Neuronio.java"
    click Backpropagation "https://github.com/tgosts/grnaproject/blob/master/src/neuralNetwork/Backpropagation.java"
    click FuncaoAtivacao "https://github.com/tgosts/grnaproject/blob/master/src/neuralNetwork/FuncaoAtivacao.java"
    click Funcao "https://github.com/tgosts/grnaproject/blob/master/src/neuralNetwork/Funcao.java"
    click binJogo "https://github.com/tgosts/grnaproject/tree/master/bin/Jogo/"
    click binNN "https://github.com/tgosts/grnaproject/tree/master/bin/neuralNetwork/"
    click binData "https://github.com/tgosts/grnaproject/tree/master/bin/data/"
    click binUtil "https://github.com/tgosts/grnaproject/tree/master/bin/util/"

    %% Styles
    classDef util fill:#cccccc,stroke:#333,stroke-width:1px
    classDef data fill:#ffff99,stroke:#333,stroke-width:1px
    classDef nn fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef game fill:#99ccff,stroke:#333,stroke-width:1px
    classDef build fill:#e0ccff,stroke:#333,stroke-width:1px
```
