@@ -74,10 +74,11 @@ This README provides a quick reference for LLMs and developers, but the full doc
74
74
- 🏬 Easy redis caching
75
75
- 👜 Easy client-side caching
76
76
- 🚦 ARQ integration for task queue
77
- - ⚙️ Efficient and robust queries with <a href =" https://github.com/igorbenav /fastcrud " >fastcrud</a >
78
- - ⎘ Out of the box offset and cursor pagination support with <a href =" https://github.com/igorbenav /fastcrud " >fastcrud</a >
77
+ - ⚙️ Efficient and robust queries with <a href =" https://github.com/benavlabs /fastcrud " >fastcrud</a >
78
+ - ⎘ Out of the box offset and cursor pagination support with <a href =" https://github.com/benavlabs /fastcrud " >fastcrud</a >
79
79
- 🛑 Rate Limiter dependency
80
80
- 👮 FastAPI docs behind authentication and hidden based on the environment
81
+ - 🔧 Modern and light admin interface powered by [ CRUDAdmin] ( https://github.com/benavlabs/crudadmin )
81
82
- 🚚 Easy running with docker compose
82
83
- ⚖️ NGINX Reverse Proxy and Load Balancing
83
84
@@ -114,9 +115,10 @@ This README provides a quick reference for LLMs and developers, but the full doc
114
115
1 . [ ARQ Job Queues] ( #510-arq-job-queues )
115
116
1 . [ Rate Limiting] ( #511-rate-limiting )
116
117
1 . [ JWT Authentication] ( #512-jwt-authentication )
117
- 1 . [ Running] ( #513-running )
118
- 1 . [ Create Application] ( #514-create-application )
119
- 2 . [ Opting Out of Services] ( #515-opting-out-of-services )
118
+ 1 . [ Admin Panel] ( #513-admin-panel )
119
+ 1 . [ Running] ( #514-running )
120
+ 1 . [ Create Application] ( #515-create-application )
121
+ 2 . [ Opting Out of Services] ( #516-opting-out-of-services )
120
122
1 . [ Running in Production] ( #6-running-in-production )
121
123
1 . [ Uvicorn Workers with Gunicorn] ( #61-uvicorn-workers-with-gunicorn )
122
124
1 . [ Running With NGINX] ( #62-running-with-nginx )
@@ -239,6 +241,37 @@ ADMIN_USERNAME="your_username"
239
241
ADMIN_PASSWORD="your_password"
240
242
```
241
243
244
+ For the CRUDAdmin panel:
245
+
246
+ ```
247
+ # ------------- crud admin -------------
248
+ CRUD_ADMIN_ENABLED=true # default=true, set to false to disable admin panel
249
+ CRUD_ADMIN_MOUNT_PATH="/admin" # default="/admin", path where admin panel will be mounted
250
+
251
+ # ------------- crud admin security -------------
252
+ CRUD_ADMIN_MAX_SESSIONS=10 # default=10, maximum concurrent sessions per user
253
+ CRUD_ADMIN_SESSION_TIMEOUT=1440 # default=1440 (24 hours), session timeout in minutes
254
+ SESSION_SECURE_COOKIES=true # default=true, use secure cookies
255
+
256
+ # ------------- crud admin tracking -------------
257
+ CRUD_ADMIN_TRACK_EVENTS=true # default=true, track admin events
258
+ CRUD_ADMIN_TRACK_SESSIONS=true # default=true, track admin sessions in database
259
+
260
+ # ------------- crud admin redis (optional for production) -------------
261
+ CRUD_ADMIN_REDIS_ENABLED=false # default=false, use Redis for session storage
262
+ CRUD_ADMIN_REDIS_HOST="localhost" # default="localhost", Redis host for admin sessions
263
+ CRUD_ADMIN_REDIS_PORT=6379 # default=6379, Redis port for admin sessions
264
+ CRUD_ADMIN_REDIS_DB=0 # default=0, Redis database for admin sessions
265
+ CRUD_ADMIN_REDIS_PASSWORD="" # optional, Redis password for admin sessions
266
+ CRUD_ADMIN_REDIS_SSL=false # default=false, use SSL for Redis connection
267
+ ```
268
+
269
+ ** Session Backend Options:**
270
+ - ** Memory** (default): Development-friendly, sessions reset on restart
271
+ - ** Redis** (production): High performance, scalable, persistent sessions
272
+ - ** Database** : Audit-friendly with admin visibility
273
+ - ** Hybrid** : Redis performance + database audit trail
274
+
242
275
For redis caching:
243
276
244
277
```
@@ -1546,7 +1579,116 @@ What you should do with the client is:
1546
1579
1547
1580
This authentication setup in the provides a robust, secure, and user-friendly way to handle user sessions in your API applications.
1548
1581
1549
- ### 5.13 Running
1582
+ ### 5.13 Admin Panel
1583
+
1584
+ > 📖 ** [ See admin panel guide in our docs] ( https://benavlabs.github.io/FastAPI-boilerplate/user-guide/admin-panel/ ) **
1585
+
1586
+ The boilerplate includes a powerful web-based admin interface built with [ CRUDAdmin] ( https://github.com/benavlabs/crudadmin ) that provides a comprehensive database management system.
1587
+
1588
+ > ** About CRUDAdmin** : CRUDAdmin is a modern admin interface generator for FastAPI applications. Learn more at:
1589
+ > - ** 📚 Documentation** : [ benavlabs.github.io/crudadmin] ( https://benavlabs.github.io/crudadmin/ )
1590
+ > - ** 💻 GitHub** : [ github.com/benavlabs/crudadmin] ( https://github.com/benavlabs/crudadmin )
1591
+
1592
+ #### 5.13.1 Features
1593
+
1594
+ The admin panel includes:
1595
+
1596
+ - ** User Management** : Create, view, update users with password hashing
1597
+ - ** Tier Management** : Manage user tiers and permissions
1598
+ - ** Post Management** : Full CRUD operations for posts
1599
+ - ** Authentication** : Secure login system with session management
1600
+ - ** Security** : IP restrictions, session timeouts, and secure cookies
1601
+ - ** Redis Integration** : Optional Redis support for session storage
1602
+ - ** Event Tracking** : Track admin actions and sessions
1603
+
1604
+ #### 5.13.2 Access
1605
+
1606
+ Once your application is running, you can access the admin panel at:
1607
+
1608
+ ```
1609
+ http://localhost:8000/admin
1610
+ ```
1611
+
1612
+ Use the admin credentials you defined in your ` .env ` file:
1613
+ - Username: ` ADMIN_USERNAME `
1614
+ - Password: ` ADMIN_PASSWORD `
1615
+
1616
+ #### 5.13.3 Configuration
1617
+
1618
+ The admin panel is highly configurable through environment variables:
1619
+
1620
+ - ** Basic Settings** : Enable/disable, mount path
1621
+ - ** Security** : Session limits, timeouts, IP restrictions
1622
+ - ** Tracking** : Event and session tracking
1623
+ - ** Redis** : Optional Redis session storage
1624
+
1625
+ See the [ environment variables section] ( #31-environment-variables-env ) for complete configuration options.
1626
+
1627
+ #### 5.13.4 Customization
1628
+
1629
+ ** Adding New Models**
1630
+
1631
+ To add new models to the admin panel, edit ` src/app/admin/views.py ` :
1632
+
1633
+ ``` python
1634
+ from your_app.models import YourModel
1635
+ from your_app.schemas import YourCreateSchema, YourUpdateSchema
1636
+
1637
+ def register_admin_views (admin : CRUDAdmin) -> None :
1638
+ # ... existing models ...
1639
+
1640
+ admin.add_view(
1641
+ model = YourModel,
1642
+ create_schema = YourCreateSchema,
1643
+ update_schema = YourUpdateSchema,
1644
+ allowed_actions = {" view" , " create" , " update" , " delete" }
1645
+ )
1646
+ ```
1647
+
1648
+ ** Advanced Configuration**
1649
+
1650
+ For more complex model configurations:
1651
+
1652
+ ``` python
1653
+ # Handle models with problematic fields (e.g., TSVector)
1654
+ admin.add_view(
1655
+ model = Article,
1656
+ create_schema = ArticleCreate,
1657
+ update_schema = ArticleUpdate,
1658
+ select_schema = ArticleSelect, # Exclude problematic fields from read operations
1659
+ allowed_actions = {" view" , " create" , " update" , " delete" }
1660
+ )
1661
+
1662
+ # Password field handling
1663
+ admin.add_view(
1664
+ model = User,
1665
+ create_schema = UserCreateWithPassword,
1666
+ update_schema = UserUpdateWithPassword,
1667
+ password_transformer = password_transformer, # Handles password hashing
1668
+ allowed_actions = {" view" , " create" , " update" }
1669
+ )
1670
+
1671
+ # Read-only models
1672
+ admin.add_view(
1673
+ model = AuditLog,
1674
+ create_schema = AuditLogSchema,
1675
+ update_schema = AuditLogSchema,
1676
+ allowed_actions = {" view" } # Only viewing allowed
1677
+ )
1678
+ ```
1679
+
1680
+ ** Session Backend Configuration**
1681
+
1682
+ For production environments, consider using Redis for better performance:
1683
+
1684
+ ``` python
1685
+ # Enable Redis sessions in your environment
1686
+ CRUD_ADMIN_REDIS_ENABLED = true
1687
+ CRUD_ADMIN_REDIS_HOST = localhost
1688
+ CRUD_ADMIN_REDIS_PORT = 6379
1689
+ ```
1690
+
1691
+ ### 5.14 Running
1550
1692
1551
1693
If you are using docker compose, just running the following command should ensure everything is working:
1552
1694
@@ -1566,7 +1708,7 @@ And for the worker:
1566
1708
``` sh
1567
1709
uv run arq src.app.core.worker.settings.WorkerSettings
1568
1710
```
1569
- ### 5.14 Create Application
1711
+ ### 5.15 Create Application
1570
1712
1571
1713
If you want to stop tables from being created every time you run the api, you should disable this here:
1572
1714
@@ -1589,7 +1731,7 @@ A few examples:
1589
1731
- Add client-side cache middleware
1590
1732
- Add Startup and Shutdown event handlers for cache, queue and rate limit
1591
1733
1592
- ### 5.15 Opting Out of Services
1734
+ ### 5.16 Opting Out of Services
1593
1735
1594
1736
To opt out of services (like ` Redis ` , ` Queue ` , ` Rate Limiter ` ), head to the ` Settings ` class in ` src/app/core/config ` :
1595
1737
@@ -1617,6 +1759,7 @@ class Settings(
1617
1759
RedisQueueSettings ,
1618
1760
RedisRateLimiterSettings ,
1619
1761
DefaultRateLimitSettings ,
1762
+ CRUDAdminSettings ,
1620
1763
EnvironmentSettings ,
1621
1764
):
1622
1765
pass
0 commit comments