VanithaSivaraj commited on
Commit
1df2bc7
·
1 Parent(s): c082141

added docker file and README file

Browse files
Files changed (2) hide show
  1. Dockerfile +27 -0
  2. README.md +71 -229
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a lightweight and stable Python 3.11 base image (Bullseye)
2
+ FROM python:3.11-slim-bullseye AS base
3
+
4
+ ENV PYTHONUNBUFFERED=1 \
5
+ PYTHONDONTWRITEBYTECODE=1 \
6
+ PATH="/home/user/.local/bin:$PATH"
7
+
8
+ RUN apt-get update && apt-get install -y \
9
+ openssl \
10
+ ca-certificates \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ RUN useradd -m -u 1000 user
14
+ USER user
15
+ WORKDIR /app
16
+
17
+ COPY --chown=user ./requirements.txt requirements.txt
18
+ COPY --chown=user ./app/insightfy_utils-0.1.0-py3-none-any.whl insightfy_utils-0.1.0-py3-none-any.whl
19
+ RUN pip install --no-cache-dir --upgrade pip && \
20
+ pip install --no-cache-dir insightfy_utils-0.1.0-py3-none-any.whl && \
21
+ pip install --no-cache-dir --upgrade -r requirements.txt
22
+
23
+ COPY --chown=user . /app
24
+
25
+ EXPOSE 7860
26
+
27
+ CMD ["uvicorn", "app.app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "4", "--log-level", "info"]
README.md CHANGED
@@ -1,256 +1,98 @@
1
- # SCM Microservice - Supply Chain Management System
2
-
3
- [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
4
- [![FastAPI](https://img.shields.io/badge/FastAPI-0.104-green.svg)](https://fastapi.tiangolo.com/)
5
- [![MongoDB](https://img.shields.io/badge/MongoDB-Latest-green.svg)](https://www.mongodb.com/)
6
-
7
- Enterprise-grade Supply Chain Management microservice with comprehensive merchant management, hierarchical organization structure, and advanced validation.
8
-
9
- ## 🚀 Quick Start
10
-
11
- ```bash
12
- # Install dependencies
13
- pip install -r requirements.txt
14
-
15
- # Configure environment
16
- cp .env.example .env # Edit with your MongoDB URI
17
-
18
- # Start the server
19
- python main.py
20
-
21
- # Run example
22
- python examples/quick_start.py
23
- ```
24
-
25
- **API Documentation**: http://localhost:8000/docs
26
-
27
- ## 📋 Features
28
-
29
- ### ✨ Enhanced Merchant Module
30
-
31
- - **Hierarchical Merchant Management**: National CNF → CNF → Distributor → Salon
32
- - **Comprehensive Validation**: E.164 phone, Indian pincode, GST/PAN/IFSC patterns
33
- - **Business Rule Enforcement**: Parent-child relationships, KYC requirements, credit limits
34
- - **RESTful API**: Complete CRUD operations with filtering and pagination
35
- - **Geographic Support**: Lat/lng validation for location-based services
36
- - **Status Lifecycle**: Draft → Submitted → Approved → Active
37
- - **Soft Delete**: Preserve data integrity with status-based deletion
38
-
39
- ### 🔒 Validation & Security
40
-
41
- - **Contact Information**: Phone (E.164), email normalization, address validation
42
- - **KYC Documents**: GST (15-char), PAN (10-char), IFSC (11-char) pattern validation
43
- - **Geographic Data**: Latitude (-90 to 90), Longitude (-180 to 180)
44
- - **Business Settings**: Payment modes, credit limits, inheritance flags
45
- - **Document URLs**: HTTPS-only enforcement
46
-
47
- ### 📊 Merchant Types
48
-
49
- | Type | Parent | KYC Requirements | Special |
50
- |------|--------|------------------|---------|
51
- | **National CNF** | None (Root) | GST, PAN, Bank, IFSC | Top-level distributor |
52
- | **CNF** | National CNF | GST, PAN, Bank, IFSC | Regional distributor |
53
- | **Distributor** | CNF | GST, PAN, Bank, IFSC | Local distributor |
54
- | **Salon** | Distributor | PAN (GST optional) | Geo-location required |
55
-
56
- ## 📚 Documentation
57
-
58
- - **[Getting Started Guide](GETTING_STARTED.md)** - Installation and setup
59
- - **[Merchant Module Documentation](MERCHANT_MODULE.md)** - Complete API reference
60
- - **[Architecture Overview](ARCHITECTURE.md)** - System design and diagrams
61
- - **[Enhancement Summary](ENHANCEMENT_SUMMARY.md)** - What's new
62
-
63
- ## 🏗️ Architecture
64
-
65
- ```
66
- FastAPI Application
67
- ├── Routers (API Endpoints)
68
- │ └── Merchant Router
69
- ├── Services (Business Logic)
70
- │ └── Merchant Service
71
- ├── Schemas (Validation)
72
- │ └── Pydantic Models
73
- ├── Models (Database)
74
- │ └── MongoDB Documents
75
- └── MongoDB (Data Store)
76
- ```
77
-
78
- ## 📦 Project Structure
79
-
80
- ```
81
- app/
82
- ├── constants/ # Enums, validation patterns
83
- ├── core/ # Configuration, logging
84
- ├── models/ # Database models
85
- ├── schemas/ # Pydantic validation schemas
86
- ├── services/ # Business logic layer
87
- └── routers/ # API endpoints
88
-
89
- tests/ # Comprehensive test suite
90
- examples/ # Usage examples
91
- main.py # Application entry point
92
- ```
93
-
94
- ## 🔧 API Endpoints
95
 
96
- ### Merchant Management
97
 
98
- ```http
99
- POST /merchants # Create merchant
100
- GET /merchants/{id} # Get merchant details
101
- PUT /merchants/{id} # Update merchant
102
- DELETE /merchants/{id} # Delete merchant (soft)
103
- GET /merchants # List with filters
104
- GET /merchants/{id}/children # Get child merchants
105
- GET /merchants/{id}/hierarchy # Get full hierarchy path
106
- ```
107
 
108
- ### Query Parameters
109
 
110
- - `merchant_type`: Filter by type (national_cnf, cnf, distributor, salon)
111
- - `parent_id`: Filter by parent merchant
112
- - `status`: Filter by status (draft, submitted, approved, active, suspended, rejected)
113
- - `skip`: Pagination offset
114
- - `limit`: Results per page (max 500)
115
 
116
- ## 💡 Usage Examples
117
 
118
- ### Create National CNF
 
 
 
 
119
 
120
- ```python
121
- POST /merchants
122
- {
123
- "merchant_type": "national_cnf",
124
- "merchant_code": "NCNF-001",
125
- "merchant_name": "National Distribution",
126
- "contact": {
127
- "phone": "+919876543210",
128
- "email": "contact@national.com",
129
- "address_line1": "123 Industrial Area",
130
- "city": "Mumbai",
131
- "state": "Maharashtra",
132
- "pincode": "400001",
133
- "country": "India"
134
- },
135
- "kyc": {
136
- "gst_number": "27AAPFU0939F1ZV",
137
- "pan_number": "AAPFU0939F",
138
- "bank_account_number": "1234567890123",
139
- "bank_ifsc": "HDFC0001234"
140
- },
141
- "created_by": "admin"
142
- }
143
- ```
144
 
145
- ### Create Salon
 
 
 
 
146
 
147
- ```python
148
- POST /merchants
149
- {
150
- "merchant_type": "salon",
151
- "parent_merchant_id": "DIST_001",
152
- "merchant_code": "SALON-001",
153
- "merchant_name": "Glamour Salon",
154
- "contact": {...},
155
- "geo_location": {"lat": 19.0760, "lng": 72.8777},
156
- "kyc": {"pan_number": "AAPFU0939F"},
157
- "created_by": "admin"
158
- }
159
- ```
160
 
161
- ## 🧪 Testing
 
 
162
 
163
- ```bash
164
- # Run all tests
165
- pytest -v
166
 
167
- # Run specific test file
168
- pytest tests/test_merchant_schemas.py -v
 
 
169
 
170
- # Run with coverage
171
- pytest --cov=app tests/
172
- ```
173
 
174
- **Test Coverage**: Comprehensive validation, business rules, hierarchy enforcement
175
 
176
- ## 🚀 Deployment
177
-
178
- ### Development
179
 
180
  ```bash
181
- python main.py
182
- # or
183
- uvicorn main:app --reload
184
- ```
185
-
186
- ### Production
 
 
 
 
 
 
 
 
 
187
 
188
- ```bash
189
- uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
 
190
  ```
191
 
192
- ### Docker (Coming Soon)
193
 
194
  ```bash
195
- docker build -t scm-microservice .
196
- docker run -p 8000:8000 scm-microservice
197
- ```
198
-
199
- ## 🗄️ Database
200
-
201
- **MongoDB Collections**:
202
- - `scm_merchants` - Merchant data with hierarchical structure
203
- - `scm_employees` - Employee management
204
- - `scm_roles` - Role definitions
205
- - `scm_auth_logs` - Authentication logs
206
-
207
- **Recommended Indexes**:
208
- ```javascript
209
- db.scm_merchants.createIndex({"merchant_id": 1}, {unique: true})
210
- db.scm_merchants.createIndex({"merchant_code": 1, "parent_merchant_id": 1}, {unique: true})
211
- db.scm_merchants.createIndex({"parent_merchant_id": 1})
212
- db.scm_merchants.createIndex({"merchant_type": 1})
213
- db.scm_merchants.createIndex({"status": 1})
214
- ```
215
-
216
- ## 🔐 Environment Variables
217
 
218
- ```env
219
- MONGODB_URI=mongodb://localhost:27017
220
- MONGODB_DB_NAME=scm_db
221
- APP_ENV=development
222
- LOG_LEVEL=INFO
223
  ```
224
 
225
- ## 📊 Tech Stack
226
-
227
- - **Framework**: FastAPI 0.104+
228
- - **Database**: MongoDB (Motor async driver)
229
- - **Validation**: Pydantic 2.5+
230
- - **Server**: Uvicorn
231
- - **Testing**: Pytest
232
- - **Logging**: insightfy-utils
233
 
234
- ## 🤝 Contributing
235
-
236
- 1. Follow existing code structure
237
- 2. Add tests for new features
238
- 3. Update documentation
239
- 4. Use type hints
240
- 5. Follow PEP 8 style guide
241
-
242
- ## 📝 License
243
-
244
- Proprietary - Cuatro Labs
245
-
246
- ## 📞 Support
247
-
248
- - **API Documentation**: http://localhost:8000/docs
249
- - **Interactive Docs**: http://localhost:8000/redoc
250
- - **Health Check**: http://localhost:8000/health
251
-
252
- ---
253
 
254
- **Version**: 1.0.0
255
- **Last Updated**: November 24, 2025
256
- **Maintained by**: Cuatro Labs Team
 
 
 
 
 
 
1
+ ---
2
+ title: Insightify ANS
3
+ emoji: 👀
4
+ colorFrom: yellow
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ short_description: Analytics Notification Services
9
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12
 
 
 
 
 
 
 
 
 
 
13
 
14
+ # Analytics and Notification Service (ANS)
15
 
16
+ The Analytics and Notification Service (ANS) is a microservice that provides business intelligence, analytics, and notification capabilities for the Insightfy Bloom platform.
 
 
 
 
17
 
18
+ ## Features
19
 
20
+ - **Analytics Dashboard**: Real-time business metrics and KPIs
21
+ - **Reporting**: Generate various business reports
22
+ - **Data Aggregation**: Collect and process data from other microservices
23
+ - **Notifications**: Send alerts and notifications based on business rules
24
+ - **Performance Monitoring**: Track business performance indicators
25
 
26
+ ## Architecture
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ ANS integrates with other microservices:
29
+ - **MPMS**: Product and merchant data
30
+ - **RMS**: Resource and employee data
31
+ - **TMS**: Transaction and sales data
32
+ - **CRM**: Customer relationship data
33
 
34
+ ## Database Connections
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ - **PostgreSQL**: Primary database for analytics data
37
+ - **MongoDB**: Document storage for flexible analytics
38
+ - **Redis**: Caching and session management
39
 
40
+ ## API Endpoints
 
 
41
 
42
+ ### Health Checks
43
+ - `GET /health` - Service health status
44
+ - `GET /ready` - Readiness check
45
+ - `GET /live` - Liveness check
46
 
47
+ ### Analytics
48
+ - `GET /api/v1/analytics/dashboard` - Dashboard data
49
+ - `GET /api/v1/analytics/reports` - Generate reports
50
 
51
+ ## Environment Variables
52
 
53
+ Copy `.env.example` to `.env` and configure:
 
 
54
 
55
  ```bash
56
+ # Database Configuration
57
+ DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/ans_db
58
+ REDIS_URL=redis://localhost:6379/0
59
+ MONGODB_URL=mongodb://localhost:27017/ans_db
60
+
61
+ # Service URLs
62
+ MPMS_BASE_URL=http://localhost:8001
63
+ RMS_BASE_URL=http://localhost:8002
64
+ TMS_BASE_URL=http://localhost:8003
65
+ CRM_BASE_URL=http://localhost:8004
66
+
67
+ # Service Configuration
68
+ SERVICE_NAME=ans
69
+ SERVICE_PORT=8005
70
+ LOG_LEVEL=INFO
71
 
72
+ # JWT Configuration
73
+ JWT_SECRET_KEY=your-secret-key
74
+ JWT_ALGORITHM=HS256
75
  ```
76
 
77
+ ## Running the Service
78
 
79
  ```bash
80
+ # Install dependencies
81
+ pip install -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
+ # Run the service
84
+ uvicorn app.main:app --host 0.0.0.0 --port 8005 --reload
 
 
 
85
  ```
86
 
87
+ ## Development
 
 
 
 
 
 
 
88
 
89
+ The service follows the standard microservice architecture:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
+ - `app/routers/` - API route handlers
92
+ - `app/services/` - Business logic
93
+ - `app/repositories/` - Data access layer
94
+ - `app/models/` - Database models
95
+ - `app/schemas/` - Pydantic schemas
96
+ - `app/clients/` - Inter-service communication
97
+ - `app/dependencies/` - FastAPI dependencies (auth, etc.)
98
+ - `app/utils/` - Utility functions