infomankit 0.3.23__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- infoman/__init__.py +1 -0
- infoman/cli/README.md +378 -0
- infoman/cli/__init__.py +7 -0
- infoman/cli/commands/__init__.py +3 -0
- infoman/cli/commands/init.py +312 -0
- infoman/cli/scaffold.py +634 -0
- infoman/cli/templates/Makefile.template +132 -0
- infoman/cli/templates/app/__init__.py.template +3 -0
- infoman/cli/templates/app/app.py.template +4 -0
- infoman/cli/templates/app/models_base.py.template +18 -0
- infoman/cli/templates/app/models_entity_init.py.template +11 -0
- infoman/cli/templates/app/models_schemas_init.py.template +11 -0
- infoman/cli/templates/app/repository_init.py.template +11 -0
- infoman/cli/templates/app/routers_init.py.template +15 -0
- infoman/cli/templates/app/services_init.py.template +11 -0
- infoman/cli/templates/app/static_index.html.template +39 -0
- infoman/cli/templates/app/static_main.js.template +31 -0
- infoman/cli/templates/app/static_style.css.template +111 -0
- infoman/cli/templates/app/utils_init.py.template +11 -0
- infoman/cli/templates/config/.env.dev.template +43 -0
- infoman/cli/templates/config/.env.prod.template +43 -0
- infoman/cli/templates/config/README.md.template +28 -0
- infoman/cli/templates/docker/.dockerignore.template +60 -0
- infoman/cli/templates/docker/Dockerfile.template +47 -0
- infoman/cli/templates/docker/README.md.template +240 -0
- infoman/cli/templates/docker/docker-compose.yml.template +81 -0
- infoman/cli/templates/docker/mysql_custom.cnf.template +42 -0
- infoman/cli/templates/docker/mysql_init.sql.template +15 -0
- infoman/cli/templates/project/.env.example.template +1 -0
- infoman/cli/templates/project/.gitignore.template +60 -0
- infoman/cli/templates/project/Makefile.template +38 -0
- infoman/cli/templates/project/README.md.template +137 -0
- infoman/cli/templates/project/deploy.sh.template +97 -0
- infoman/cli/templates/project/main.py.template +10 -0
- infoman/cli/templates/project/manage.sh.template +97 -0
- infoman/cli/templates/project/pyproject.toml.template +47 -0
- infoman/cli/templates/project/service.sh.template +203 -0
- infoman/config/__init__.py +25 -0
- infoman/config/base.py +67 -0
- infoman/config/db_cache.py +237 -0
- infoman/config/db_relation.py +181 -0
- infoman/config/db_vector.py +39 -0
- infoman/config/jwt.py +16 -0
- infoman/config/llm.py +16 -0
- infoman/config/log.py +627 -0
- infoman/config/mq.py +26 -0
- infoman/config/settings.py +65 -0
- infoman/llm/__init__.py +0 -0
- infoman/llm/llm.py +297 -0
- infoman/logger/__init__.py +57 -0
- infoman/logger/context.py +191 -0
- infoman/logger/core.py +358 -0
- infoman/logger/filters.py +157 -0
- infoman/logger/formatters.py +138 -0
- infoman/logger/handlers.py +276 -0
- infoman/logger/metrics.py +160 -0
- infoman/performance/README.md +583 -0
- infoman/performance/__init__.py +19 -0
- infoman/performance/cli.py +215 -0
- infoman/performance/config.py +166 -0
- infoman/performance/reporter.py +519 -0
- infoman/performance/runner.py +303 -0
- infoman/performance/standards.py +222 -0
- infoman/service/__init__.py +8 -0
- infoman/service/app.py +67 -0
- infoman/service/core/__init__.py +0 -0
- infoman/service/core/auth.py +105 -0
- infoman/service/core/lifespan.py +132 -0
- infoman/service/core/monitor.py +57 -0
- infoman/service/core/response.py +37 -0
- infoman/service/exception/__init__.py +7 -0
- infoman/service/exception/error.py +274 -0
- infoman/service/exception/exception.py +25 -0
- infoman/service/exception/handler.py +238 -0
- infoman/service/infrastructure/__init__.py +8 -0
- infoman/service/infrastructure/base.py +212 -0
- infoman/service/infrastructure/db_cache/__init__.py +8 -0
- infoman/service/infrastructure/db_cache/manager.py +194 -0
- infoman/service/infrastructure/db_relation/__init__.py +41 -0
- infoman/service/infrastructure/db_relation/manager.py +300 -0
- infoman/service/infrastructure/db_relation/manager_pro.py +408 -0
- infoman/service/infrastructure/db_relation/mysql.py +52 -0
- infoman/service/infrastructure/db_relation/pgsql.py +54 -0
- infoman/service/infrastructure/db_relation/sqllite.py +25 -0
- infoman/service/infrastructure/db_vector/__init__.py +40 -0
- infoman/service/infrastructure/db_vector/manager.py +201 -0
- infoman/service/infrastructure/db_vector/qdrant.py +322 -0
- infoman/service/infrastructure/mq/__init__.py +15 -0
- infoman/service/infrastructure/mq/manager.py +178 -0
- infoman/service/infrastructure/mq/nats/__init__.py +0 -0
- infoman/service/infrastructure/mq/nats/nats_client.py +57 -0
- infoman/service/infrastructure/mq/nats/nats_event_router.py +25 -0
- infoman/service/launch.py +284 -0
- infoman/service/middleware/__init__.py +7 -0
- infoman/service/middleware/base.py +41 -0
- infoman/service/middleware/logging.py +51 -0
- infoman/service/middleware/rate_limit.py +301 -0
- infoman/service/middleware/request_id.py +21 -0
- infoman/service/middleware/white_list.py +24 -0
- infoman/service/models/__init__.py +8 -0
- infoman/service/models/base.py +441 -0
- infoman/service/models/type/embed.py +70 -0
- infoman/service/routers/__init__.py +18 -0
- infoman/service/routers/health_router.py +311 -0
- infoman/service/routers/monitor_router.py +44 -0
- infoman/service/utils/__init__.py +8 -0
- infoman/service/utils/cache/__init__.py +0 -0
- infoman/service/utils/cache/cache.py +192 -0
- infoman/service/utils/module_loader.py +10 -0
- infoman/service/utils/parse.py +10 -0
- infoman/service/utils/resolver/__init__.py +8 -0
- infoman/service/utils/resolver/base.py +47 -0
- infoman/service/utils/resolver/resp.py +102 -0
- infoman/service/vector/__init__.py +20 -0
- infoman/service/vector/base.py +56 -0
- infoman/service/vector/qdrant.py +125 -0
- infoman/service/vector/service.py +67 -0
- infoman/utils/__init__.py +2 -0
- infoman/utils/decorators/__init__.py +8 -0
- infoman/utils/decorators/cache.py +137 -0
- infoman/utils/decorators/retry.py +99 -0
- infoman/utils/decorators/safe_execute.py +99 -0
- infoman/utils/decorators/timing.py +99 -0
- infoman/utils/encryption/__init__.py +8 -0
- infoman/utils/encryption/aes.py +66 -0
- infoman/utils/encryption/ecc.py +108 -0
- infoman/utils/encryption/rsa.py +112 -0
- infoman/utils/file/__init__.py +0 -0
- infoman/utils/file/handler.py +22 -0
- infoman/utils/hash/__init__.py +0 -0
- infoman/utils/hash/hash.py +61 -0
- infoman/utils/http/__init__.py +8 -0
- infoman/utils/http/client.py +62 -0
- infoman/utils/http/info.py +94 -0
- infoman/utils/http/result.py +19 -0
- infoman/utils/notification/__init__.py +8 -0
- infoman/utils/notification/feishu.py +35 -0
- infoman/utils/text/__init__.py +8 -0
- infoman/utils/text/extractor.py +111 -0
- infomankit-0.3.23.dist-info/METADATA +632 -0
- infomankit-0.3.23.dist-info/RECORD +143 -0
- infomankit-0.3.23.dist-info/WHEEL +4 -0
- infomankit-0.3.23.dist-info/entry_points.txt +5 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Docker Configuration
|
|
2
|
+
|
|
3
|
+
This directory contains Docker configuration files for {project_name}.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
- `Dockerfile` - Multi-stage Docker image definition
|
|
8
|
+
- `docker-compose.yml` - Docker Compose orchestration
|
|
9
|
+
- `.dockerignore` - Files to exclude from Docker build
|
|
10
|
+
- `mysql/conf.d/custom.cnf` - MySQL configuration
|
|
11
|
+
- `mysql/init/01-init.sql` - Database initialization script
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Configure Environment
|
|
16
|
+
|
|
17
|
+
Ensure `.env` file exists in project root with required variables:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Copy from config directory
|
|
21
|
+
cp config/.env.dev .env
|
|
22
|
+
|
|
23
|
+
# Or create minimal .env
|
|
24
|
+
cat > .env <<EOF
|
|
25
|
+
APP_ENV=dev
|
|
26
|
+
MYSQL_DB={project_name}_db
|
|
27
|
+
MYSQL_USER={project_name}_user
|
|
28
|
+
MYSQL_PASSWORD=your_password
|
|
29
|
+
MYSQL_ROOT_PASSWORD=root_password
|
|
30
|
+
EOF
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Build and Start Services
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Build images
|
|
37
|
+
docker-compose -f docker/docker-compose.yml build
|
|
38
|
+
|
|
39
|
+
# Start all services
|
|
40
|
+
docker-compose -f docker/docker-compose.yml up -d
|
|
41
|
+
|
|
42
|
+
# View logs
|
|
43
|
+
docker-compose -f docker/docker-compose.yml logs -f
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 3. Access Services
|
|
47
|
+
|
|
48
|
+
- Application: http://localhost:8000
|
|
49
|
+
- API Docs: http://localhost:8000/docs
|
|
50
|
+
- MySQL: localhost:3306
|
|
51
|
+
- Redis: localhost:6379
|
|
52
|
+
|
|
53
|
+
### 4. Stop Services
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Stop services
|
|
57
|
+
docker-compose -f docker/docker-compose.yml down
|
|
58
|
+
|
|
59
|
+
# Stop and remove volumes
|
|
60
|
+
docker-compose -f docker/docker-compose.yml down -v
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Services
|
|
64
|
+
|
|
65
|
+
### App Service
|
|
66
|
+
|
|
67
|
+
- FastAPI application
|
|
68
|
+
- Auto-reload enabled for development
|
|
69
|
+
- Health checks configured
|
|
70
|
+
- Depends on MySQL and Redis
|
|
71
|
+
|
|
72
|
+
### MySQL Service
|
|
73
|
+
|
|
74
|
+
- MySQL 8.0
|
|
75
|
+
- Persistent data volume
|
|
76
|
+
- Custom configuration in `mysql/conf.d/`
|
|
77
|
+
- Initialization scripts in `mysql/init/`
|
|
78
|
+
- Health checks configured
|
|
79
|
+
|
|
80
|
+
### Redis Service
|
|
81
|
+
|
|
82
|
+
- Redis 7 (Alpine Linux)
|
|
83
|
+
- Persistent data volume
|
|
84
|
+
- Optional password protection
|
|
85
|
+
- Health checks configured
|
|
86
|
+
|
|
87
|
+
## Development Workflow
|
|
88
|
+
|
|
89
|
+
### Run with auto-reload
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
docker-compose -f docker/docker-compose.yml up
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The `app/` directory is mounted as a volume, so code changes are reflected immediately.
|
|
96
|
+
|
|
97
|
+
### Execute commands in container
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Shell access
|
|
101
|
+
docker-compose -f docker/docker-compose.yml exec app bash
|
|
102
|
+
|
|
103
|
+
# Run tests
|
|
104
|
+
docker-compose -f docker/docker-compose.yml exec app pytest
|
|
105
|
+
|
|
106
|
+
# Database migrations
|
|
107
|
+
docker-compose -f docker/docker-compose.yml exec app alembic upgrade head
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### View logs
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# All services
|
|
114
|
+
docker-compose -f docker/docker-compose.yml logs -f
|
|
115
|
+
|
|
116
|
+
# Specific service
|
|
117
|
+
docker-compose -f docker/docker-compose.yml logs -f app
|
|
118
|
+
docker-compose -f docker/docker-compose.yml logs -f mysql
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## MySQL Configuration
|
|
122
|
+
|
|
123
|
+
### Custom Configuration
|
|
124
|
+
|
|
125
|
+
Edit `mysql/conf.d/custom.cnf` to customize MySQL settings:
|
|
126
|
+
- Character sets
|
|
127
|
+
- Buffer sizes
|
|
128
|
+
- Connection limits
|
|
129
|
+
- Logging options
|
|
130
|
+
|
|
131
|
+
### Initialization Scripts
|
|
132
|
+
|
|
133
|
+
Add `.sql` files to `mysql/init/` directory. They will run automatically on first container startup in alphabetical order.
|
|
134
|
+
|
|
135
|
+
### Connect to MySQL
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# From host
|
|
139
|
+
mysql -h localhost -P 3306 -u {project_name}_user -p
|
|
140
|
+
|
|
141
|
+
# From app container
|
|
142
|
+
docker-compose -f docker/docker-compose.yml exec app mysql -h mysql -u {project_name}_user -p
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Redis Configuration
|
|
146
|
+
|
|
147
|
+
Redis is configured with:
|
|
148
|
+
- AOF persistence enabled
|
|
149
|
+
- Optional password protection via `REDIS_PASSWORD` env var
|
|
150
|
+
|
|
151
|
+
Connect to Redis:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# From host
|
|
155
|
+
redis-cli -h localhost -p 6379
|
|
156
|
+
|
|
157
|
+
# From app container
|
|
158
|
+
docker-compose -f docker/docker-compose.yml exec app redis-cli -h redis
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Production Deployment
|
|
162
|
+
|
|
163
|
+
For production:
|
|
164
|
+
|
|
165
|
+
1. Use production `.env` file:
|
|
166
|
+
```bash
|
|
167
|
+
cp config/.env.prod .env
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
2. Update docker-compose.yml:
|
|
171
|
+
- Remove volume mounts for code
|
|
172
|
+
- Use specific image tags
|
|
173
|
+
- Configure resource limits
|
|
174
|
+
- Set up proper secrets management
|
|
175
|
+
|
|
176
|
+
3. Use Docker secrets or external secret management:
|
|
177
|
+
```yaml
|
|
178
|
+
secrets:
|
|
179
|
+
mysql_password:
|
|
180
|
+
external: true
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
4. Configure reverse proxy (nginx, traefik) for HTTPS
|
|
184
|
+
|
|
185
|
+
5. Set up monitoring and logging
|
|
186
|
+
|
|
187
|
+
## Troubleshooting
|
|
188
|
+
|
|
189
|
+
### Container won't start
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Check logs
|
|
193
|
+
docker-compose -f docker/docker-compose.yml logs
|
|
194
|
+
|
|
195
|
+
# Check container status
|
|
196
|
+
docker-compose -f docker/docker-compose.yml ps
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Database connection errors
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# Verify MySQL is healthy
|
|
203
|
+
docker-compose -f docker/docker-compose.yml exec mysql mysqladmin ping
|
|
204
|
+
|
|
205
|
+
# Check connection from app
|
|
206
|
+
docker-compose -f docker/docker-compose.yml exec app ping mysql
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Reset everything
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Stop and remove all containers, networks, and volumes
|
|
213
|
+
docker-compose -f docker/docker-compose.yml down -v
|
|
214
|
+
|
|
215
|
+
# Rebuild from scratch
|
|
216
|
+
docker-compose -f docker/docker-compose.yml build --no-cache
|
|
217
|
+
docker-compose -f docker/docker-compose.yml up -d
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Volume Management
|
|
221
|
+
|
|
222
|
+
### Backup database
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Backup
|
|
226
|
+
docker-compose -f docker/docker-compose.yml exec mysql mysqldump -u root -p{project_name}_db > backup.sql
|
|
227
|
+
|
|
228
|
+
# Restore
|
|
229
|
+
docker-compose -f docker/docker-compose.yml exec -T mysql mysql -u root -p {project_name}_db < backup.sql
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Inspect volumes
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# List volumes
|
|
236
|
+
docker volume ls
|
|
237
|
+
|
|
238
|
+
# Inspect specific volume
|
|
239
|
+
docker volume inspect docker_mysql_data
|
|
240
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
app:
|
|
5
|
+
build:
|
|
6
|
+
context: ..
|
|
7
|
+
dockerfile: docker/Dockerfile
|
|
8
|
+
container_name: {project_name}_app
|
|
9
|
+
ports:
|
|
10
|
+
- "8000:8000"
|
|
11
|
+
volumes:
|
|
12
|
+
- ../app:/app/app
|
|
13
|
+
- ../logs:/app/logs
|
|
14
|
+
environment:
|
|
15
|
+
- APP_ENV=${{APP_ENV:-dev}}
|
|
16
|
+
- MYSQL_HOST=mysql
|
|
17
|
+
- REDIS_HOST=redis
|
|
18
|
+
env_file:
|
|
19
|
+
- ../.env
|
|
20
|
+
depends_on:
|
|
21
|
+
mysql:
|
|
22
|
+
condition: service_healthy
|
|
23
|
+
redis:
|
|
24
|
+
condition: service_healthy
|
|
25
|
+
networks:
|
|
26
|
+
- app_network
|
|
27
|
+
restart: unless-stopped
|
|
28
|
+
healthcheck:
|
|
29
|
+
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
|
30
|
+
interval: 30s
|
|
31
|
+
timeout: 10s
|
|
32
|
+
retries: 3
|
|
33
|
+
start_period: 40s
|
|
34
|
+
|
|
35
|
+
mysql:
|
|
36
|
+
image: mysql:8.0
|
|
37
|
+
container_name: {project_name}_mysql
|
|
38
|
+
ports:
|
|
39
|
+
- "3306:3306"
|
|
40
|
+
environment:
|
|
41
|
+
MYSQL_ROOT_PASSWORD: ${{MYSQL_PASSWORD:-root_password}}
|
|
42
|
+
MYSQL_DATABASE: ${{MYSQL_DB:-{project_name}_db}}
|
|
43
|
+
MYSQL_USER: ${{MYSQL_USER:-{project_name}_user}}
|
|
44
|
+
MYSQL_PASSWORD: ${{MYSQL_PASSWORD:-user_password}}
|
|
45
|
+
volumes:
|
|
46
|
+
- mysql_data:/var/lib/mysql
|
|
47
|
+
- ./mysql/conf.d:/etc/mysql/conf.d
|
|
48
|
+
- ./mysql/init:/docker-entrypoint-initdb.d
|
|
49
|
+
networks:
|
|
50
|
+
- app_network
|
|
51
|
+
restart: unless-stopped
|
|
52
|
+
healthcheck:
|
|
53
|
+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${{MYSQL_PASSWORD:-root_password}}"]
|
|
54
|
+
interval: 10s
|
|
55
|
+
timeout: 5s
|
|
56
|
+
retries: 5
|
|
57
|
+
|
|
58
|
+
redis:
|
|
59
|
+
image: redis:7-alpine
|
|
60
|
+
container_name: {project_name}_redis
|
|
61
|
+
ports:
|
|
62
|
+
- "6379:6379"
|
|
63
|
+
command: redis-server --appendonly yes ${{REDIS_PASSWORD:+--requirepass}} ${{REDIS_PASSWORD}}
|
|
64
|
+
volumes:
|
|
65
|
+
- redis_data:/data
|
|
66
|
+
networks:
|
|
67
|
+
- app_network
|
|
68
|
+
restart: unless-stopped
|
|
69
|
+
healthcheck:
|
|
70
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
71
|
+
interval: 10s
|
|
72
|
+
timeout: 5s
|
|
73
|
+
retries: 5
|
|
74
|
+
|
|
75
|
+
networks:
|
|
76
|
+
app_network:
|
|
77
|
+
driver: bridge
|
|
78
|
+
|
|
79
|
+
volumes:
|
|
80
|
+
mysql_data:
|
|
81
|
+
redis_data:
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[mysqld]
|
|
2
|
+
# Character set
|
|
3
|
+
character-set-server=utf8mb4
|
|
4
|
+
collation-server=utf8mb4_unicode_ci
|
|
5
|
+
|
|
6
|
+
# Connection
|
|
7
|
+
max_connections=200
|
|
8
|
+
max_connect_errors=100
|
|
9
|
+
|
|
10
|
+
# Buffer sizes
|
|
11
|
+
innodb_buffer_pool_size=256M
|
|
12
|
+
innodb_log_file_size=64M
|
|
13
|
+
innodb_log_buffer_size=16M
|
|
14
|
+
|
|
15
|
+
# Performance
|
|
16
|
+
innodb_flush_log_at_trx_commit=2
|
|
17
|
+
innodb_flush_method=O_DIRECT
|
|
18
|
+
innodb_file_per_table=1
|
|
19
|
+
|
|
20
|
+
# Query cache (disabled in MySQL 8.0+)
|
|
21
|
+
# query_cache_type=0
|
|
22
|
+
# query_cache_size=0
|
|
23
|
+
|
|
24
|
+
# Slow query log
|
|
25
|
+
slow_query_log=1
|
|
26
|
+
slow_query_log_file=/var/log/mysql/slow-query.log
|
|
27
|
+
long_query_time=2
|
|
28
|
+
|
|
29
|
+
# General log (disable in production)
|
|
30
|
+
general_log=0
|
|
31
|
+
general_log_file=/var/log/mysql/general.log
|
|
32
|
+
|
|
33
|
+
# Binary log
|
|
34
|
+
log_bin=/var/log/mysql/mysql-bin.log
|
|
35
|
+
binlog_expire_logs_seconds=604800
|
|
36
|
+
max_binlog_size=100M
|
|
37
|
+
|
|
38
|
+
# Time zone
|
|
39
|
+
default-time-zone='+00:00'
|
|
40
|
+
|
|
41
|
+
[client]
|
|
42
|
+
default-character-set=utf8mb4
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Database initialization script for {project_name}
|
|
2
|
+
-- This script runs automatically when the MySQL container is first created
|
|
3
|
+
|
|
4
|
+
-- Ensure utf8mb4 character set
|
|
5
|
+
ALTER DATABASE {project_name}_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
6
|
+
|
|
7
|
+
-- Create example table (optional - remove if not needed)
|
|
8
|
+
-- CREATE TABLE IF NOT EXISTS example (
|
|
9
|
+
-- id INT AUTO_INCREMENT PRIMARY KEY,
|
|
10
|
+
-- name VARCHAR(255) NOT NULL,
|
|
11
|
+
-- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
12
|
+
-- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
13
|
+
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
14
|
+
|
|
15
|
+
-- Add any additional initialization SQL here
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ENV=dev
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual Environment
|
|
24
|
+
venv/
|
|
25
|
+
ENV/
|
|
26
|
+
env/
|
|
27
|
+
.venv
|
|
28
|
+
|
|
29
|
+
# IDE
|
|
30
|
+
.vscode/
|
|
31
|
+
.idea/
|
|
32
|
+
*.swp
|
|
33
|
+
*.swo
|
|
34
|
+
*~
|
|
35
|
+
|
|
36
|
+
# Environment
|
|
37
|
+
.env
|
|
38
|
+
.env.local
|
|
39
|
+
|
|
40
|
+
# Logs
|
|
41
|
+
logs/
|
|
42
|
+
*.log
|
|
43
|
+
|
|
44
|
+
# Database
|
|
45
|
+
*.db
|
|
46
|
+
*.sqlite
|
|
47
|
+
*.sqlite3
|
|
48
|
+
|
|
49
|
+
# Testing
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
.coverage
|
|
52
|
+
htmlcov/
|
|
53
|
+
.tox/
|
|
54
|
+
|
|
55
|
+
# OS
|
|
56
|
+
.DS_Store
|
|
57
|
+
Thumbs.db
|
|
58
|
+
|
|
59
|
+
# Docker
|
|
60
|
+
docker-compose.override.yml
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.PHONY: help dev test lint format clean
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "Available commands:"
|
|
5
|
+
@echo " make dev - Start development server"
|
|
6
|
+
@echo " make test - Run tests"
|
|
7
|
+
@echo " make lint - Run linter"
|
|
8
|
+
@echo " make format - Format code"
|
|
9
|
+
@echo " make clean - Clean temporary files"
|
|
10
|
+
|
|
11
|
+
dev:
|
|
12
|
+
@echo "Starting development server..."
|
|
13
|
+
infoman-serve run app.app:app --reload --host 0.0.0.0 --port 8000
|
|
14
|
+
|
|
15
|
+
test:
|
|
16
|
+
@echo "Running tests..."
|
|
17
|
+
pytest tests/ -v --cov=app
|
|
18
|
+
|
|
19
|
+
lint:
|
|
20
|
+
@echo "Running linter..."
|
|
21
|
+
ruff check .
|
|
22
|
+
mypy app/
|
|
23
|
+
|
|
24
|
+
format:
|
|
25
|
+
@echo "Formatting code..."
|
|
26
|
+
black .
|
|
27
|
+
ruff check --fix .
|
|
28
|
+
|
|
29
|
+
clean:
|
|
30
|
+
@echo "Cleaning temporary files..."
|
|
31
|
+
find . -type d -name "__pycache__" -exec rm -rf {{}} +
|
|
32
|
+
find . -type f -name "*.pyc" -delete
|
|
33
|
+
find . -type f -name "*.pyo" -delete
|
|
34
|
+
find . -type d -name "*.egg-info" -exec rm -rf {{}} +
|
|
35
|
+
find . -type d -name ".pytest_cache" -exec rm -rf {{}} +
|
|
36
|
+
find . -type d -name ".ruff_cache" -exec rm -rf {{}} +
|
|
37
|
+
find . -type d -name ".mypy_cache" -exec rm -rf {{}} +
|
|
38
|
+
rm -rf dist/ build/
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# {project_name}
|
|
2
|
+
|
|
3
|
+
FastAPI application built with [infomankit](https://github.com/ai-infoman/infoman-pykit).
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### 1. Setup Environment
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Copy environment config (or use the generated .env directly)
|
|
11
|
+
cp config/.env.dev .env
|
|
12
|
+
|
|
13
|
+
# Update database credentials and other settings in .env
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### 2. Install Dependencies
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install -e .
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 3. Run Application
|
|
23
|
+
|
|
24
|
+
#### Development Mode (Foreground)
|
|
25
|
+
```bash
|
|
26
|
+
# Using make (recommended for development)
|
|
27
|
+
make dev
|
|
28
|
+
|
|
29
|
+
# Or using main.py
|
|
30
|
+
python main.py
|
|
31
|
+
|
|
32
|
+
# Or using infoman-serve directly
|
|
33
|
+
infoman-serve --app app.app:application --reload
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Service Mode (Background)
|
|
37
|
+
```bash
|
|
38
|
+
# Start as background service
|
|
39
|
+
./service.sh start
|
|
40
|
+
|
|
41
|
+
# Check service status
|
|
42
|
+
./service.sh status
|
|
43
|
+
|
|
44
|
+
# View logs
|
|
45
|
+
./service.sh logs
|
|
46
|
+
|
|
47
|
+
# Stop service
|
|
48
|
+
./service.sh stop
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 4. Access API Documentation
|
|
52
|
+
|
|
53
|
+
- Swagger UI: http://localhost:8000/docs
|
|
54
|
+
- ReDoc: http://localhost:8000/redoc
|
|
55
|
+
|
|
56
|
+
## Project Structure
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
{project_name}/
|
|
60
|
+
├── app/ # Application code
|
|
61
|
+
│ ├── models/ # Database models
|
|
62
|
+
│ ├── routers/ # API routes
|
|
63
|
+
│ ├── services/ # Business logic
|
|
64
|
+
│ ├── repository/ # Data access layer
|
|
65
|
+
│ ├── utils/ # Utilities
|
|
66
|
+
│ ├── static/ # Static files
|
|
67
|
+
│ └── template/ # HTML templates
|
|
68
|
+
├── config/ # Configuration files
|
|
69
|
+
│ ├── .env.dev # Development config
|
|
70
|
+
│ └── .env.prod # Production config
|
|
71
|
+
├── doc/ # Documentation
|
|
72
|
+
├── logs/ # Application logs
|
|
73
|
+
├── main.py # Entry point
|
|
74
|
+
├── Makefile # Development commands
|
|
75
|
+
└── service.sh # Service management script
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
### Using Makefile (Development Tools)
|
|
81
|
+
|
|
82
|
+
For **development** and **one-time** commands:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
make help # Show all available commands
|
|
86
|
+
make dev # Run development server (foreground)
|
|
87
|
+
make test # Run tests
|
|
88
|
+
make lint # Run linter
|
|
89
|
+
make format # Format code
|
|
90
|
+
make clean # Clean temporary files
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Using service.sh (Service Management)
|
|
94
|
+
|
|
95
|
+
For **background service** management:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
./service.sh start # Start service in background
|
|
99
|
+
./service.sh stop # Stop service
|
|
100
|
+
./service.sh restart # Restart service
|
|
101
|
+
./service.sh status # Show service status
|
|
102
|
+
./service.sh logs # Follow application logs
|
|
103
|
+
./service.sh errors # Follow error logs
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**When to use each:**
|
|
107
|
+
- **Makefile**: Development, debugging, testing, code quality checks
|
|
108
|
+
- **service.sh**: Running service in background (testing, staging environments)
|
|
109
|
+
|
|
110
|
+
## Docker Support
|
|
111
|
+
|
|
112
|
+
Generate Docker configuration:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
infomankit docker
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This creates a `docker/` directory with:
|
|
119
|
+
- Dockerfile
|
|
120
|
+
- docker-compose.yml
|
|
121
|
+
- MySQL configuration
|
|
122
|
+
- Database initialization scripts
|
|
123
|
+
|
|
124
|
+
## Configuration
|
|
125
|
+
|
|
126
|
+
Edit `.env` file to configure:
|
|
127
|
+
- Database connection
|
|
128
|
+
- JWT settings
|
|
129
|
+
- CORS origins
|
|
130
|
+
- Redis connection
|
|
131
|
+
- Logging settings
|
|
132
|
+
|
|
133
|
+
See `config/README.md` for detailed documentation.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Color definitions
|
|
4
|
+
RED='\033[0;31m'
|
|
5
|
+
GREEN='\033[0;32m'
|
|
6
|
+
YELLOW='\033[1;33m'
|
|
7
|
+
BLUE='\033[0;34m'
|
|
8
|
+
NC='\033[0m' # No Color
|
|
9
|
+
|
|
10
|
+
# Print colored message
|
|
11
|
+
print_message() {{
|
|
12
|
+
local color=$1
|
|
13
|
+
local message=$2
|
|
14
|
+
echo -e "${{color}}${{message}}${{NC}}"
|
|
15
|
+
}}
|
|
16
|
+
|
|
17
|
+
# Print usage
|
|
18
|
+
print_usage() {{
|
|
19
|
+
echo "Usage: ./deploy.sh [command]"
|
|
20
|
+
echo ""
|
|
21
|
+
echo "Available commands:"
|
|
22
|
+
echo " dev - Start development server"
|
|
23
|
+
echo " test - Run tests"
|
|
24
|
+
echo " lint - Run linter"
|
|
25
|
+
echo " format - Format code"
|
|
26
|
+
echo " clean - Clean temporary files"
|
|
27
|
+
echo " help - Show this help message"
|
|
28
|
+
}}
|
|
29
|
+
|
|
30
|
+
# Development server
|
|
31
|
+
cmd_dev() {{
|
|
32
|
+
print_message "$BLUE" "Starting development server..."
|
|
33
|
+
infoman-serve run app.app:app --reload --host 0.0.0.0 --port 8000
|
|
34
|
+
}}
|
|
35
|
+
|
|
36
|
+
# Run tests
|
|
37
|
+
cmd_test() {{
|
|
38
|
+
print_message "$BLUE" "Running tests..."
|
|
39
|
+
pytest tests/ -v --cov=app
|
|
40
|
+
}}
|
|
41
|
+
|
|
42
|
+
# Run linter
|
|
43
|
+
cmd_lint() {{
|
|
44
|
+
print_message "$BLUE" "Running linter..."
|
|
45
|
+
ruff check .
|
|
46
|
+
mypy app/
|
|
47
|
+
}}
|
|
48
|
+
|
|
49
|
+
# Format code
|
|
50
|
+
cmd_format() {{
|
|
51
|
+
print_message "$BLUE" "Formatting code..."
|
|
52
|
+
black .
|
|
53
|
+
ruff check --fix .
|
|
54
|
+
print_message "$GREEN" "Code formatted successfully"
|
|
55
|
+
}}
|
|
56
|
+
|
|
57
|
+
# Clean temporary files
|
|
58
|
+
cmd_clean() {{
|
|
59
|
+
print_message "$BLUE" "Cleaning temporary files..."
|
|
60
|
+
find . -type d -name "__pycache__" -exec rm -rf {{}} + 2>/dev/null
|
|
61
|
+
find . -type f -name "*.pyc" -delete 2>/dev/null
|
|
62
|
+
find . -type f -name "*.pyo" -delete 2>/dev/null
|
|
63
|
+
find . -type d -name "*.egg-info" -exec rm -rf {{}} + 2>/dev/null
|
|
64
|
+
find . -type d -name ".pytest_cache" -exec rm -rf {{}} + 2>/dev/null
|
|
65
|
+
find . -type d -name ".ruff_cache" -exec rm -rf {{}} + 2>/dev/null
|
|
66
|
+
find . -type d -name ".mypy_cache" -exec rm -rf {{}} + 2>/dev/null
|
|
67
|
+
rm -rf dist/ build/ 2>/dev/null
|
|
68
|
+
print_message "$GREEN" "Cleanup completed"
|
|
69
|
+
}}
|
|
70
|
+
|
|
71
|
+
# Main command dispatcher
|
|
72
|
+
case "$1" in
|
|
73
|
+
dev)
|
|
74
|
+
cmd_dev
|
|
75
|
+
;;
|
|
76
|
+
test)
|
|
77
|
+
cmd_test
|
|
78
|
+
;;
|
|
79
|
+
lint)
|
|
80
|
+
cmd_lint
|
|
81
|
+
;;
|
|
82
|
+
format)
|
|
83
|
+
cmd_format
|
|
84
|
+
;;
|
|
85
|
+
clean)
|
|
86
|
+
cmd_clean
|
|
87
|
+
;;
|
|
88
|
+
help|--help|-h|"")
|
|
89
|
+
print_usage
|
|
90
|
+
;;
|
|
91
|
+
*)
|
|
92
|
+
print_message "$RED" "Error: Unknown command '$1'"
|
|
93
|
+
echo ""
|
|
94
|
+
print_usage
|
|
95
|
+
exit 1
|
|
96
|
+
;;
|
|
97
|
+
esac
|