Design Templates – Am I structuring this correctly for a .net mvc web application based on onion architecture?

Text) (https://imgur.com/a/ikwByd8) (! (Enter the description of the image here) 1

I'm new to MVC. Most of my career, I have used web forms in Asp.net. Reading MVC was really confusing because from what I learned, in traditional MVC, the models were supposed to be business logic as well as the models / in-house domain objects. But when it comes to Microsoft's MVC, the model means that View Models and MVC is right in the UI / Presentation layer. Now, I'm trying to combine that with the Onion / Clean architecture. I use the Busines Logic layer and the Service layer interchangeably, but for the sake of simplicity for this application.

So my web application basically queries a few CSV files. These are the player data where we have the biographies of the tennis players and their match records and their head to head records. Besides the obvious display of data in the user interface layer inside the view, this data has to be displayed very differently from the way it is stored, let's assume that there is also business logic decisions that are processed at the service / business layer.

Assuming that the application will become much larger than its starting point, I decided to use the repository model and not go directly to the data source. The repository classes and the corresponding interfaces therefore reside in Data Access Layer. All of these are closely related to each other, so if we decide to switch from CSV files to SQL DB, much of this layer will have to be rewritten. It is, so to speak, an outer layer.

The innermost layer is the model / domain objects that make sense from a logical point of view and do not necessarily match 1 to 1 with how they are stored in the database nor how they are displayed in the view. The 3 layers DAL, BL, UI can directly access these model classes. However, these are in their own projects and these depend on nothing outside of this project. From what I understand, this is where ignoring the technology is important because we want to be able to change DAL without a single one without any modifications required for that particular layer.

DI is used both for the Business layer to be able to use DAL and for the UI layer to use the functionality of the Business layer. There are no such separate DTOs and instead domain model objects are used for this.

This is how I intend to configure it for scalability and SoC. Can someone please point out the disadvantages of this and if I understand things correctly?

database – Node.JS / MongoDB / Mongoose route structuring

Thinking of a route / controller structure here:

Say I have a Company, under which he can Locations, and each Location can have multiple Forms.

On the CompanyProfile is a short and simple form to create a new Location, but I want to have a whole page with a drag and drop interface to create / edit Forms

Would it be better to use a button on the Location profile to send a GET ask a route something like /locations/:locationId/forms/new so that i can access req.params.locationId know which one Location put it under?

Or is it better to have the button on the Location profile be a form with a hidden read-only entry that contains the current LocationID who POSTher /forms/new so i could have req.body.locationId know which one Location to add the Form at?

Anyway, what I would like to do is that the back-end creates a Form and add a list of default questions to it, then add it to Location via ID in an array property, save them both, then assign the new Form at req.session.currentForm and send it to a /forms/edit route, because I want users to be able to edit a Form at the same time they create it, and recycle the logic to the back to access the /edit road.

Let me know if I'm clear like mud / missing something obvious that would be easier

visual studio – Structuring a "big" Windows Forms project and a solution to something with several sub-projects

I intentionally inherited a VB.Net forms project based on .Net 3.5 latest edition with VS2012. I was able to open it and convert it to VS2017. I can compile it and run it and make some small adjustments. The code is written a bit more like a VBA project / module filled with random classes behind form files and 1000 line methods behind button actions.

No namespace is defined and I don't know how to try to rearrange the code without breaking it. (Because I already did it once.)

Whenever I create a new project in the solution, it creates subfolders and I have to add references to the existing project to the new one. It seems a little awkward and disorganized.

So far, I have started to extract the classes into their own files, but nothing more.

How best to separate code and forms so you can get separate exes for the forms that need it?
What should the underlying folder structure look like? Flat or secondary files?
How do I apply namespaces? (I know this may be a bit based on opinion, but I don't know where to start)

architecture – Structuring large, scalable projects

TLDR with bald

I want to create a library (I think that's the right term) for my own reinforcement learning environments (envs for short). Most envs would be based on self-implemented games created either in pure python, or in c ++ with python bindings. What would be the best way to structure this project in a way that is easy to expand, maintain and makes the most sense? I want to be able to reuse code, for example by using a general class for all of my board game implementations (for example, chess, go, gomoku). I plan to make it cross-platform with the help of CMake and I might even venture to package it as a Conda package.

Through my initial research, I found that this layout (and its variations) is popular and I decided to build on that.

My initial plan was to structure my library into projects, create a repository for each project and include one project in another as a git sub-module. To create the environment for the game
2048, the structure would be as follows (CMakeLists omitted):

(the vector env builds on env-2048, which builds on game-2048 that uses the generalist class)

general-board
├── external
│   └── Catch2/
├── include
│   └── general-board
│       └── file.h
├── src
│   └── file.cpp
└── tests
    └── tests.cpp

game-2048
├── app
│   └── manual_game.cpp
├── external
│   ├── Catch2
│   └── general-board
├── include
│   └── game-2048
│       └── file.h
├── src
│   └── file.cpp
└── tests
    └── tests.cpp

env-2048
├── external
│   ├── Catch2/
│   └── game-2048/
├── include
│   └── env-2048
│       └── file.h
├── src
│   └── file.cpp
└── tests
    └── tests.cpp 

env-vector <---- this would be on the top, bundling the envs together
├── external
│   ├── Catch2/
│   ├── env-2048/ 
│   ├── env-chess/ <---- another board game
│   └── env-go/ <---- another board game
├── include
│   └── env-vector
│       └── file.h
├── python
│   └── pybind11_magic_here
├── src
│   └── file.cpp
└── tests
    └── tests.cpp

After a few implementations, I wondered if the number of submodules and the redundancy were too large. With this structure, the project at the top would contain the project of the general council not times (where not is the number of games resting on a board), and catch2 would be included even more. Seems suspicious and prone to error.

My second idea was to create a big project and to include everything in a "flat" way and not in a "nested" way as before. It would look like this:

(line ending with "https://softwareengineering.stackexchange.com/" depicts a folder)
environments_all_in_one
│
├── external
│   └── Catch2/
├── include
│   └── environments_all_in_one
│       └── **not_even_sure_what_to_put_here**      
├── python
│   └── pybind11_magic_here
├── src
│   ├── env_vector
│   ├── envs
│   │   ├── env-2048/
│   │   ├── env-chess/
│   │   └── env-go/
│   ├── games
│   │   ├── game-2048/
│   │   ├── game-chess/
│   │   └── game-go/
│   └── general-board
│       ├── board_abc/
│       ├── board_array/
│       └── board_vector/
└── tests
    └── tests.cpp

This way, the code would not be present several times and this certainly contributes to transparency. However, as I have no experience, I have to ask:

Is there a better way to do this?

java – Structuring application in accordance with the single responsibility

I have class AircraftManager who keeps a list of Aircraft objects and a list of AircraftListener objects.

A DataSource (custom class, not related to SQL), the object retrieves information from an external source, the data sources decode the message and call the appropriate logic on the plane, namely setAltitude, setHeading . The program is designed to plot planes on a live map.

calling the setters on Aircraft should trigger the onAircraftUpdate(Aircraft aircraft, String fieldName, Object fieldValue) method on each saved AircraftListener in AircraftManager

This first requires the Aircraft to keep a reference from the AircraftManager to call methods on the event listeners as such:

public void setAltitude(int altitude) {
    if (this.altitude != altitude) {
        this.altitude = altitude;
        this.aircraftManager.getListeners().forEach((aircraftListener ->
                aircraftListener.onAircraftValueChanged(this, "altitude", longitude)));
    }
}

It also means that AircraftManager is responsible for keeping all AircraftListeners as well as Aircraft.

My question is to experienced developers on the question of whether this solution is satisfactory, the improvements / changes you would make. It should also be noted that a class will not want to add a listener to a single aircraft, but to all aircraft.

Thank you

c ++ – Structuring of game menus

I am working on a multiplayer RPG using only C ++ and SDL2. I have already created the main menu and a map editor, and I am preparing to make the game real. The main menu and map editor were easy to structure, as they had repetitive visuals and concepts – the map editing tools can be represented as an enumerated list, just like the games and settings saved – and so I was able to store them in structured vectors, then when I went to render everything and check the user actions, I could just browse the lists and hit each visible menu item. My code for these sections is small and neat; I am proud of it.

Now in the game, I realize that my HUD is made up of a rather random assortment of types of things the player can click on. There is one quick access area for items, another for spells, another for the map, another for NPC buddy orders, etc., and each of them has context menus totally unique associated with them. Then there is a menu for crafting, a menu for the NPC dialog, and several of the items have their own independent menus for interacting with them.

I'm trying to think of the right way to structure all of these lists. Storing them in vectors like I did with the menu and stuff seems to happen to me with a bulky and asymmetrical set of nested vectors, and it could be complicated to browse through. How do good programmers handle this stuff? Should I just create an independent section in the code for each menu in the game?

Thank you!

Is this way of structuring my project correct?

Last night I browsed the prestashop API and decided to try to do something basic. To create a Windows Form in VisualStudio in C # and I started to inform a little bit.
My doubt is this:
Is it correct to write all the code only in the Form.cs without using the function main () what do I have in Program.cs?

I mean, the program is functional but I had this doubt.

python – Creates a structuring element in the form of a line with a certain degree and length

In Matlab, there is a function that allows you to create a structuring in the form of a line.
SE = strel('line',len,deg) creates a linear structuring element symmetrical about the center of the neighborhood, of approximate length len and angle deg. For some morphological operations, I need to filter the horizontal, vertical and other line angles. Within Python CV2 a similar function does not exist. Therefore, I wanted to recreate this function in Python

My code:

import math
import numpy as np

# bresenham function is the accepted answer of SO's post https://stackoverflow.com/questions/23930274/list-of-coordinates-between-irregular-points-in-python
def bresenham(x0, y0, x1, y1):
   points = ()
   dx = abs(x1 - x0)
   dy = abs(y1 - y0)
   x, y = x0, y0
   sx = -1 if x0 > x1 else 1
   sy = -1 if y0 > y1 else 1
   if dx > dy:
      err = dx / 2.0
      while x != x1:
         points.append((x, y))
         err -= dy
         if err < 0:
            y += sy
            err += dx
         x += sx
   else:
      err = dy / 2.0
      while y != y1:
         points.append((x, y))
         err -= dx
         if err < 0:
            x += sx
            err += dy
         y += sy
   points.append((x, y))

   return points


def strel_line(length, degrees):
   if length >= 1:
      theta = degrees * np.pi / 180
      x = round((length - 1) / 2 * np.cos(theta))
      y = -round((length - 1) / 2 * np.sin(theta))
      points = bresenham(-x, -y, x, y)
      points_x = (point(0) for point in points)
      points_y = (point(1) for point in points)
      n_rows = int(2 * max((abs(point_y) for point_y in points_y)) + 1)
      n_columns = int(2 * max((abs(point_x) for point_x in points_x)) + 1)
      strel = np.zeros((n_rows, n_columns))
      rows = ((point_y + max((abs(point_y) for point_y in points_y)) for point_y in points_y))
      columns = ((point_x + max((abs(point_x) for point_x in points_x)) for point_x in points_x))
      idx = ()
      for x in zip(rows, columns):
         idx.append(np.ravel_multi_index((int(x(0)), int(x(1))), (n_rows, n_columns)))
      strel.reshape(-1)(idx) = 1

   return strel


if __name__=='__main__':
   strel = strel_line(15, 105)
   print(strel)
   print(strel.shape)

Exit:

((1. 0. 0. 0. 0.)
 (1. 0. 0. 0. 0.)
 (0. 1. 0. 0. 0.)
 (0. 1. 0. 0. 0.)
 (0. 1. 0. 0. 0.)
 (0. 1. 0. 0. 0.)
 (0. 0. 1. 0. 0.)
 (0. 0. 1. 0. 0.)
 (0. 0. 1. 0. 0.)
 (0. 0. 0. 1. 0.)
 (0. 0. 0. 1. 0.)
 (0. 0. 0. 1. 0.)
 (0. 0. 0. 1. 0.)
 (0. 0. 0. 0. 1.)
 (0. 0. 0. 0. 1.))

Do you see ways to write my job more effectively?

unit testing – Using CMake and Googletest: Structuring File Systems

This is the first time I leave Microsoft for Linux. As such, I no longer work in Visual Studio and I have to learn the basics of project development myself. I use Sublime Text as a publisher and CMake generate the make files.

I've been working on building a genetic optimization library for C ++ and I've managed to get it running. However, I had already run all of my "unit tests". (I mean unit tests in the least formal sense possible) in main.cpp.

I would like to start to open this project to the community and as such, I decided to use googletest formalize the approach of testing and quality assurance. I've included Data field, only one class in my library to keep things simple, in reality, there may be 30 to 40 classes.

My folder structure currently looks like this.

genetic-optimization
--- build
    --- bin
        --- ...
    --- CMakeFiles
        --- ...
    --- googletest-build
        --- ...
    --- googletest-download
        --- ...
    --- googletest-src
        --- ...
    --- lib
        --- ...
    --- tests
        --- CMakeFiles
        --- cmake_install.cmake
        --- CTestTestfile.cmake
        --- DataField-test
        --- Makefile
    --- cmake_install.cmake
    --- CMakeCache.txt
    --- CTestTestfile.cmake
    --- genetic-optomization-example
    --- Makefile
--- include
    --- DataField.h
--- libs
--- src
    --- generated-headers
        --- BuildConfig.h
    --- headers
    --- implementations
        --- DataField.cpp
    --- BuildConfig.h.in
    --- main.cpp
--- tests
    --- sample-data
        --- circle.csv
    --- CMakeLists.txt
    --- DataField-test.cpp
--- CMakeLists.txt
--- CMakeLists.txt.in

The relevant code elements are listed below.

  • genetics-optimization / CMakeLists.txt
cmake_minimum_required (VERSION 3.13.4)

# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download"
)

# Add googletest directly to our build. This adds the following targets:
# gtest, gtest_main, gmock and gmock_main
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
                 "${CMAKE_BINARY_DIR}/googletest-build"
)

# Define project
project (genetic-optomization)

set(TARGET_NAME_LIBRARY genetic-optomization-library)
set(TARGET_NAME_EXECUTABLE genetic-optomization-example)
set(PROJECT_SOURCE_DIR src)
set(PROJECT_LIBRARY_DIR include)

# The version number
set (Library_VERSION_MAJOR 1)
set (Library_VERSION_MINOR 0)

# Configure a header file to pass some of the CMake settings
# to the source code
configure_file (
    "${PROJECT_SOURCE_DIR}/BuildConfig.h.in"
    "../${PROJECT_SOURCE_DIR}/generated-headers/BuildConfig.h"
    )

#############################
# Library
#############################

# Add the executable
add_library(${TARGET_NAME_LIBRARY} STATIC
    "${PROJECT_SOURCE_DIR}/implementations/DataField.cpp" 
    )

# Include the directories
target_include_directories(${TARGET_NAME_LIBRARY} 
    PRIVATE "${PROJECT_SOURCE_DIR}/headers"
    PUBLIC "${PROJECT_LIBRARY_DIR}"
    )

target_compile_features(${TARGET_NAME_LIBRARY} PUBLIC cxx_std_17)

#############################
# Executable
#############################

# Add the executable
add_executable(${TARGET_NAME_EXECUTABLE} "${PROJECT_SOURCE_DIR}/main.cpp")

# Include the directories
target_include_directories(${TARGET_NAME_EXECUTABLE}   
    PRIVATE "${PROJECT_SOURCE_DIR}/generated-headers"
    PRIVATE "${PROJECT_SOURCE_DIR}/headers"
    )

target_link_libraries(${TARGET_NAME_EXECUTABLE} PRIVATE ${TARGET_NAME_LIBRARY})

target_compile_features(${TARGET_NAME_EXECUTABLE} PRIVATE cxx_std_17)

#############################
# Tests
#############################

enable_testing()

add_subdirectory(tests)
  • genetic optimization / CMakeLists.txt.in
cmake_minimum_required(VERSION 3.13.4)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
  GIT_REPOSITORY    https://github.com/google/googletest.git
  GIT_TAG           master
  SOURCE_DIR        "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
  BINARY_DIR        "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
  CONFIGURE_COMMAND ""
  BUILD_COMMAND     ""
  INSTALL_COMMAND   ""
  TEST_COMMAND      ""
)
  • genetics-optimization / tests / CMakeLists.txt
# First Simple Google Test

add_executable(DataField-test DataField-test.cpp)
target_link_libraries(DataField-test gtest gmock_main)

add_test(NAME simple_test COMMAND simple)

I have the following questions.

  1. I notice that many projects have recursive CMakeLists.txt files residing in each subdirectory. Is it preferable and if so, how could I change my code?
  2. Is it messy that google test is splashed all around the build directory, I think that's it. Should I add a subdirectory and will that affect the googletest name?
    • genetic optimization / CMakeLists.txt.in contains ${CMAKE_CURRENT_BINARY_DIR}. I'm new to CMake but I suppose there should be a set command somewhere for that?
  3. Anything you think I should change or that is generally bad practice.

Structuring a blog page with custom layout

My reading settings are currently driving message snippets to a custom blog page, and it works for now. But I want to restructure to look like this:

enter the description of the image here

I currently have the articles and read more links but they are full width. I want to make sure that they occupy about 60%, then the list of categories and the list of recent publications right, 30%. I obviously do not ask about the style, only about the structure.

I currently have it in my home.php file:


layout->add_class( 'content_class' ); ?> layout->add_style( 'content_style' ); ?>>