Skip to content

Commit d1c4c97

Browse files
refactor: implement modular architecture for improved maintainability
- Split monolithic main.py into logical modules - Created directory structure with src/ as the root - Organized code into config, core, ui, and utils packages - Updated basic test to work with new structure - Maintained existing functionality while improving code organization
1 parent 973da4a commit d1c4c97

File tree

17 files changed

+1134
-23
lines changed

17 files changed

+1134
-23
lines changed

app.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Main entry point for the Bingo application.
3+
"""
4+
5+
import logging
6+
import os
7+
8+
from fastapi.staticfiles import StaticFiles
9+
from nicegui import app, ui
10+
11+
from src.config.constants import (
12+
FREE_SPACE_TEXT,
13+
HEADER_TEXT
14+
)
15+
from src.core.game_logic import (
16+
board,
17+
board_iteration,
18+
bingo_patterns,
19+
clicked_tiles,
20+
generate_board,
21+
is_game_closed,
22+
today_seed
23+
)
24+
from src.ui.routes import init_routes
25+
from src.utils.file_operations import read_phrases_file
26+
27+
# Set up logging
28+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
29+
30+
# Initialize the application
31+
def init_app():
32+
"""Initialize the Bingo application."""
33+
34+
# Initialize game state
35+
phrases = read_phrases_file()
36+
generate_board(board_iteration, phrases)
37+
38+
# Initialize routes
39+
init_routes()
40+
41+
# Mount the static directory
42+
app.mount("/static", StaticFiles(directory="static"), name="static")
43+
44+
return app
45+
46+
if __name__ in {"__main__", "__mp_main__"}:
47+
# Run the NiceGUI app
48+
init_app()
49+
ui.run(port=8080, title=f"{HEADER_TEXT}", dark=False)

src/__init__.py

Whitespace-only changes.

src/config/__init__.py

Whitespace-only changes.

src/config/constants.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Configuration constants for the Bingo application.
3+
"""
4+
5+
# Header text and display settings
6+
HEADER_TEXT = "COMMIT !BINGO"
7+
HEADER_TEXT_COLOR = "#0CB2B3"
8+
CLOSED_HEADER_TEXT = "Bingo Is Closed"
9+
10+
# Free space settings
11+
FREE_SPACE_TEXT = "FREE MEAT"
12+
FREE_SPACE_TEXT_COLOR = "#FF7f33"
13+
14+
# Tile appearance settings
15+
TILE_CLICKED_BG_COLOR = "#100079"
16+
TILE_CLICKED_TEXT_COLOR = "#1BEFF5"
17+
TILE_UNCLICKED_BG_COLOR = "#1BEFF5"
18+
TILE_UNCLICKED_TEXT_COLOR = "#100079"
19+
20+
# Page backgrounds
21+
HOME_BG_COLOR = "#100079"
22+
STREAM_BG_COLOR = "#00FF00"
23+
24+
# Font settings
25+
HEADER_FONT_FAMILY = "'Super Carnival', sans-serif"
26+
BOARD_TILE_FONT = "Inter"
27+
BOARD_TILE_FONT_WEIGHT = "700"
28+
BOARD_TILE_FONT_STYLE = "normal"
29+
30+
# UI Class Constants
31+
BOARD_CONTAINER_CLASS = "flex justify-center items-center w-full"
32+
HEADER_CONTAINER_CLASS = "w-full"
33+
CARD_CLASSES = "relative p-2 rounded-xl shadow-8 w-full h-full flex items-center justify-center"
34+
COLUMN_CLASSES = "flex flex-col items-center justify-center gap-0 w-full"
35+
GRID_CONTAINER_CLASS = "w-full aspect-square p-4"
36+
GRID_CLASSES = "gap-2 h-full grid-rows-5"
37+
ROW_CLASSES = "w-full"
38+
LABEL_SMALL_CLASSES = "fit-text-small text-center select-none"
39+
LABEL_CLASSES = "fit-text text-center select-none"

src/core/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)