Diodes are one important building block of a keyboard as they ensure the proper working of the keyboard matrix and prevent ghosting.
Diodes are the one-way valves of electronics. They let electricity flow in one direction only.
In keyboard building, the main role of diodes used in the keyboard matrix is to prevent ghosting. They ensure multi-key rollover (theoretically NKRO, but mostly 6KRO) when keys are pressed simultaneously.
Just like most other electronic components, diodes come in a multitude of types, sizes and footprints.
In keyboard building, for some reason, you can almost exclusively meet 1N4148 diodes.
Probably a lot more types would work for keyboards just fine, but 1N4148s are dirt cheap (about $1 for 200 pcs).
Diode direction is crucial. It is usually indicated with a black ring (THM) or a white strip (SMD) on the diode.
All diodes have to point in the same direction for your keyboard to work as intended.
On the picture above, electricity can flow from right to left but not in the other direction.
While soldering your matrix or designing a PCB, you can choose either direction until you are consistent since this paremeter can be set in your firmware.
E.g. in QMK you can edit your config.h file:
/* DIODE DIRECTION [COL2ROW or ROW2COL] */
#define DIODE_DIRECTION ROW2COL
Can't you just skip diodes?
You CAN skip diodes in really small boards, when you have less keys than I/O pins on your controller. In this case you can wire up each switch to a dedicated pin of the controller and forget about diodes and ghosting.
This means you can wire up a macropad or even a numpad without diodes - until the number of keys doesn't exceed the 18-23 pins.
However, it's unlikely you can get away with skipping diodes on any decent board for typing. Well, except maybe 40% separate splits (without extras), since they feature two controllers, one for each half, thus, have twice the I/O pins.
Other than the diodes used in your matrix LEDs used for underglow, backlighting or as status LEDs are diodes too. We just don't exploit their on-way valve characteristic in this case.
More about LEDs in this LED strip underglow guide.