Skip to content

Commit 41c30d8

Browse files
Merge pull request #6 from OffendingCommit/refactor/modular-code-structure
refactor: implement modular architecture for improved maintainability
2 parents 973da4a + 7584575 commit 41c30d8

File tree

18 files changed

+1354
-186
lines changed

18 files changed

+1354
-186
lines changed

app.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 FREE_SPACE_TEXT, HEADER_TEXT
12+
from src.core.game_logic import (
13+
bingo_patterns,
14+
board,
15+
board_iteration,
16+
clicked_tiles,
17+
generate_board,
18+
is_game_closed,
19+
today_seed,
20+
)
21+
from src.ui.routes import init_routes
22+
from src.utils.file_operations import read_phrases_file
23+
24+
# Set up logging
25+
logging.basicConfig(
26+
level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s"
27+
)
28+
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+
47+
if __name__ in {"__main__", "__mp_main__"}:
48+
# Run the NiceGUI app
49+
init_app()
50+
ui.run(port=8080, title=f"{HEADER_TEXT}", dark=False)

main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# DEPRECATED: This file is kept for backward compatibility with tests
2+
# New development should use the modular structure in src/ with app.py as the entry point
3+
4+
import warnings
5+
6+
warnings.warn(
7+
"main.py is deprecated. Use the modular structure in src/ with app.py as the entry point",
8+
DeprecationWarning,
9+
stacklevel=2,
10+
)
11+
112
import asyncio
213
import datetime
314
import logging

src/__init__.py

Whitespace-only changes.

src/config/__init__.py

Whitespace-only changes.

src/config/constants.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 = (
34+
"relative p-2 rounded-xl shadow-8 w-full h-full flex items-center justify-center"
35+
)
36+
COLUMN_CLASSES = "flex flex-col items-center justify-center gap-0 w-full"
37+
GRID_CONTAINER_CLASS = "w-full aspect-square p-4"
38+
GRID_CLASSES = "gap-2 h-full grid-rows-5"
39+
ROW_CLASSES = "w-full"
40+
LABEL_SMALL_CLASSES = "fit-text-small text-center select-none"
41+
LABEL_CLASSES = "fit-text text-center select-none"

src/core/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)